lib/rumale/decomposition/nmf.rb in rumale-0.13.8 vs lib/rumale/decomposition/nmf.rb in rumale-0.14.0
- old
+ new
@@ -32,13 +32,12 @@
# @param max_iter [Integer] The maximum number of iterations.
# @param tol [Float] The tolerance of termination criterion.
# @param eps [Float] A small value close to zero to avoid zero division error.
# @param random_seed [Integer] The seed value using to initialize the random generator.
def initialize(n_components: 2, max_iter: 500, tol: 1.0e-4, eps: 1.0e-16, random_seed: nil)
- check_params_integer(n_components: n_components, max_iter: max_iter)
- check_params_float(tol: tol, eps: eps)
- check_params_type_or_nil(Integer, random_seed: random_seed)
+ check_params_numeric(n_components: n_components, max_iter: max_iter, tol: tol, eps: eps)
+ check_params_numeric_or_nil(random_seed: random_seed)
check_params_positive(n_components: n_components, max_iter: max_iter, tol: tol, eps: eps)
@params = {}
@params[:n_components] = n_components
@params[:max_iter] = max_iter
@params[:tol] = tol
@@ -54,11 +53,11 @@
# @overload fit(x) -> NMF
#
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The training data to be used for fitting the model.
# @return [NMF] The learned transformer itself.
def fit(x, _y = nil)
- check_sample_array(x)
+ x = check_convert_sample_array(x)
partial_fit(x)
self
end
# Fit the model with training data, and then transform them with the learned model.
@@ -66,28 +65,28 @@
# @overload fit_transform(x) -> Numo::DFloat
#
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The training data to be used for fitting the model.
# @return [Numo::DFloat] (shape: [n_samples, n_components]) The transformed data
def fit_transform(x, _y = nil)
- check_sample_array(x)
+ x = check_convert_sample_array(x)
partial_fit(x)
end
# Transform the given data with the learned model.
#
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The data to be transformed with the learned model.
# @return [Numo::DFloat] (shape: [n_samples, n_components]) The transformed data.
def transform(x)
- check_sample_array(x)
+ x = check_convert_sample_array(x)
partial_fit(x, false)
end
# Inverse transform the given transformed data with the learned model.
#
# @param z [Numo::DFloat] (shape: [n_samples, n_components]) The data to be restored into original space with the learned model.
# @return [Numo::DFloat] (shape: [n_samples, n_featuress]) The restored data.
def inverse_transform(z)
- check_sample_array(z)
+ z = check_convert_sample_array(z)
z.dot(@components)
end
# Dump marshal data.
# @return [Hash] The marshal data.