lib/rumale/kernel_approximation/nystroem.rb
# Fit the model with given training data.
#
# @overload fit(x) -> Nystroem
#   @param x [Numo::NArray] (shape: [n_samples, n_features]) The training data to be used for fitting the model.
# @return [Nystroem] The learned transformer itself.
Fit the model with given training data.
Fit the model with given training data .
def fit(x, _y = nil)
        x = check_convert_sample_array(x)
        raise 'Nystroem#fit requires Numo::Linalg but that is not loaded.' unless enable_linalg?
        sub_rng = @rng.dup
        n_samples = x.shape[0]
        n_components = [1, [@params[:n_components], n_samples].min].max
        @component_indices = Numo::Int32.cast(Array(0...n_samples).shuffle(random: sub_rng)[0...n_components])
        @components = x[@component_indices, true].dup
        kernel_mat = kernel_mat(@components)
        eig_vals, eig_vecs = Numo::Linalg.eigh(kernel_mat)
        la = eig_vals.class.maximum(eig_vals.reverse, 1e-12)
        u = eig_vecs.reverse(1)
        @normalizer = u.dot((1.0 / Numo::NMath.sqrt(la)).diag)
        self
      end
def fit ( x , _y = nil ) x = check_convert_sample_array ( x ) raise 'Nystroem#fit requires Numo::Linalg but that is not loaded.' unless enable_linalg? sub_rng = @rng . dup n_samples = x . shape [ 0 ] n_components = [ 1 , [ @params [ :n_components ] , n_samples ] . min ] . max @component_indices = Numo :: Int32 . cast ( Array ( 0 ... n_samples ) . shuffle ( random : sub_rng ) [ 0 ... n_components ] ) @components = x [ @component_indices , true ] . dup kernel_mat = kernel_mat ( @components ) eig_vals , eig_vecs = Numo :: Linalg . eigh ( kernel_mat ) la = eig_vals . class . maximum ( eig_vals . reverse , 1e-12 ) u = eig_vecs . reverse ( 1 ) @normalizer = u . dot ( ( 1.0 / Numo :: NMath . sqrt ( la ) ) . diag ) self end
Fit the model with given training data.
Fit the model with given training data .
# initialize some variables. # random sampling. # calculate normalizing factor.
The learned transformer itself.
The learned transformer itself .
Nystroem
x
<not_specific>
_y
<not_specific>
overload
> Nystroem @param x [Numo::NArray] (shape: [n_samples, n_features]) The training data to be used for fitting the model.
> Nystroem @param x [ Numo :: NArray ] ( shape : [ n_samples n_features ] ) The training data to be used for fitting the model .