Class: Rumale::Decomposition::NMF
- Inherits:
-
Base::Estimator
- Object
- Base::Estimator
- Rumale::Decomposition::NMF
- Includes:
- Base::Transformer
- Defined in:
- rumale-decomposition/lib/rumale/decomposition/nmf.rb
Overview
NMF is a class that implements Non-negative Matrix Factorization.
Reference
-
Xu, W., Liu, X., and Gong, Y., “Document Clustering Based On Non-negative Matrix Factorization,” Proc. SIGIR’ 03 , pp. 267–273, 2003.
Instance Attribute Summary collapse
-
#components ⇒ Numo::DFloat
readonly
Returns the factorization matrix.
-
#rng ⇒ Random
readonly
Return the random generator.
Attributes inherited from Base::Estimator
Instance Method Summary collapse
-
#fit(x) ⇒ NMF
Fit the model with given training data.
-
#fit_transform(x) ⇒ Numo::DFloat
Fit the model with training data, and then transform them with the learned model.
-
#initialize(n_components: 2, max_iter: 500, tol: 1.0e-4, eps: 1.0e-16, random_seed: nil) ⇒ NMF
constructor
Create a new transformer with NMF.
-
#inverse_transform(z) ⇒ Numo::DFloat
Inverse transform the given transformed data with the learned model.
-
#transform(x) ⇒ Numo::DFloat
Transform the given data with the learned model.
Constructor Details
#initialize(n_components: 2, max_iter: 500, tol: 1.0e-4, eps: 1.0e-16, random_seed: nil) ⇒ NMF
Create a new transformer with NMF.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'rumale-decomposition/lib/rumale/decomposition/nmf.rb', line 38 def initialize(n_components: 2, max_iter: 500, tol: 1.0e-4, eps: 1.0e-16, random_seed: nil) super() @params = { n_components: n_components, max_iter: max_iter, tol: tol, eps: eps, random_seed: random_seed || srand } @rng = Random.new(@params[:random_seed]) end |
Instance Attribute Details
#components ⇒ Numo::DFloat (readonly)
Returns the factorization matrix.
25 26 27 |
# File 'rumale-decomposition/lib/rumale/decomposition/nmf.rb', line 25 def components @components end |
#rng ⇒ Random (readonly)
Return the random generator.
29 30 31 |
# File 'rumale-decomposition/lib/rumale/decomposition/nmf.rb', line 29 def rng @rng end |
Instance Method Details
#fit(x) ⇒ NMF
Fit the model with given training data.
55 56 57 58 59 60 |
# File 'rumale-decomposition/lib/rumale/decomposition/nmf.rb', line 55 def fit(x, _y = nil) x = ::Rumale::Validation.check_convert_sample_array(x) partial_fit(x) self end |
#fit_transform(x) ⇒ Numo::DFloat
Fit the model with training data, and then transform them with the learned model.
67 68 69 70 71 |
# File 'rumale-decomposition/lib/rumale/decomposition/nmf.rb', line 67 def fit_transform(x, _y = nil) x = ::Rumale::Validation.check_convert_sample_array(x) partial_fit(x) end |
#inverse_transform(z) ⇒ Numo::DFloat
Inverse transform the given transformed data with the learned model.
87 88 89 90 91 |
# File 'rumale-decomposition/lib/rumale/decomposition/nmf.rb', line 87 def inverse_transform(z) z = ::Rumale::Validation.check_convert_sample_array(z) z.dot(@components) end |
#transform(x) ⇒ Numo::DFloat
Transform the given data with the learned model.
77 78 79 80 81 |
# File 'rumale-decomposition/lib/rumale/decomposition/nmf.rb', line 77 def transform(x) x = ::Rumale::Validation.check_convert_sample_array(x) partial_fit(x, update_comps: false) end |