lib/rumale/decomposition/factor_analysis.rb in rumale-0.13.8 vs lib/rumale/decomposition/factor_analysis.rb in rumale-0.14.0
- old
+ new
@@ -44,12 +44,12 @@
# @param n_components [Integer] The number of components (dimensionality of latent space).
# @param max_iter [Integer] The maximum number of iterations.
# @param tol [Float/Nil] The tolerance of termination criterion for EM algorithm.
# If nil is given, iterate EM steps up to the maximum number of iterations.
def initialize(n_components: 2, max_iter: 100, tol: 1e-8)
- check_params_integer(n_components: n_components, max_iter: max_iter)
- check_params_type_or_nil(Float, tol: tol)
+ check_params_numeric(n_components: n_components, max_iter: max_iter)
+ check_params_numeric_or_nil(tol: tol)
check_params_positive(n_components: n_components, max_iter: max_iter)
@params = {}
@params[:n_components] = n_components
@params[:max_iter] = max_iter
@params[:tol] = tol
@@ -105,21 +105,21 @@
#
# @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)
raise 'FactorAnalysis#fit_transform requires Numo::Linalg but that is not loaded.' unless enable_linalg?
fit(x).transform(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)
raise 'FactorAnalysis#transform requires Numo::Linalg but that is not loaded.' unless enable_linalg?
factors = @params[:n_components] == 1 ? @components.expand_dims(0) : @components
centered_x = x - @mean
beta = Numo::Linalg.inv(Numo::DFloat.eye(factors.shape[0]) + (factors / @noise_variance).dot(factors.transpose))