Class: Rumale::Decomposition::NMF
- Inherits:
-
Object
- Object
- Rumale::Decomposition::NMF
- Includes:
- Base::BaseEstimator, Base::Transformer
- Defined in:
- lib/rumale/decomposition/nmf.rb
Overview
NMF is a class that implements Non-negative Matrix Factorization.
Reference
-
Xu, X. Liu, and Y.Gong, “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 included from Base::BaseEstimator
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.
-
#marshal_dump ⇒ Hash
Dump marshal data.
-
#marshal_load(obj) ⇒ nil
Load marshal data.
-
#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.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rumale/decomposition/nmf.rb', line 36 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_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 @params[:eps] = eps @params[:random_seed] = random_seed @params[:random_seed] ||= srand @components = nil @rng = Random.new(@params[:random_seed]) end |
Instance Attribute Details
#components ⇒ Numo::DFloat (readonly)
Returns the factorization matrix.
23 24 25 |
# File 'lib/rumale/decomposition/nmf.rb', line 23 def components @components end |
#rng ⇒ Random (readonly)
Return the random generator.
27 28 29 |
# File 'lib/rumale/decomposition/nmf.rb', line 27 def rng @rng end |
Instance Method Details
#fit(x) ⇒ NMF
Fit the model with given training data.
58 59 60 61 62 |
# File 'lib/rumale/decomposition/nmf.rb', line 58 def fit(x, _y = nil) check_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.
70 71 72 73 |
# File 'lib/rumale/decomposition/nmf.rb', line 70 def fit_transform(x, _y = nil) check_sample_array(x) partial_fit(x) end |
#inverse_transform(z) ⇒ Numo::DFloat
Inverse transform the given transformed data with the learned model.
88 89 90 91 |
# File 'lib/rumale/decomposition/nmf.rb', line 88 def inverse_transform(z) check_sample_array(z) z.dot(@components) end |
#marshal_dump ⇒ Hash
Dump marshal data.
95 96 97 98 99 |
# File 'lib/rumale/decomposition/nmf.rb', line 95 def marshal_dump { params: @params, components: @components, rng: @rng } end |
#marshal_load(obj) ⇒ nil
Load marshal data.
103 104 105 106 107 108 |
# File 'lib/rumale/decomposition/nmf.rb', line 103 def marshal_load(obj) @params = obj[:params] @components = obj[:components] @rng = obj[:rng] nil end |
#transform(x) ⇒ Numo::DFloat
Transform the given data with the learned model.
79 80 81 82 |
# File 'lib/rumale/decomposition/nmf.rb', line 79 def transform(x) check_sample_array(x) partial_fit(x, false) end |