Class: Rumale::Preprocessing::MaxNormalizer
- Inherits:
-
Base::Estimator
- Object
- Base::Estimator
- Rumale::Preprocessing::MaxNormalizer
- Includes:
- Base::Transformer
- Defined in:
- rumale-preprocessing/lib/rumale/preprocessing/max_normalizer.rb
Overview
Normalize samples with the maximum of the absolute values.
Instance Attribute Summary collapse
-
#norm_vec ⇒ Numo::DFloat
readonly
Return the vector consists of the maximum norm for each sample.
Attributes inherited from Base::Estimator
Instance Method Summary collapse
-
#fit(x) ⇒ MaxNormalizer
Calculate the maximum norms of each sample.
-
#fit_transform(x) ⇒ Numo::DFloat
Calculate the maximums norm of each sample, and then normalize samples with the norms.
-
#initialize ⇒ MaxNormalizer
constructor
Create a new normalizer for normaliing to max-norm.
-
#transform(x) ⇒ Numo::DFloat
Calculate the maximum norms of each sample, and then normalize samples with the norms.
Constructor Details
#initialize ⇒ MaxNormalizer
Create a new normalizer for normaliing to max-norm.
24 25 26 |
# File 'rumale-preprocessing/lib/rumale/preprocessing/max_normalizer.rb', line 24 def initialize # rubocop:disable Lint/UselessMethodDefinition super() end |
Instance Attribute Details
#norm_vec ⇒ Numo::DFloat (readonly)
Return the vector consists of the maximum norm for each sample.
21 22 23 |
# File 'rumale-preprocessing/lib/rumale/preprocessing/max_normalizer.rb', line 21 def norm_vec @norm_vec end |
Instance Method Details
#fit(x) ⇒ MaxNormalizer
Calculate the maximum norms of each sample.
34 35 36 37 38 39 40 |
# File 'rumale-preprocessing/lib/rumale/preprocessing/max_normalizer.rb', line 34 def fit(x, _y = nil) x = ::Rumale::Validation.check_convert_sample_array(x) @norm_vec = x.abs.max(1) @norm_vec[@norm_vec.eq(0)] = 1 self end |
#fit_transform(x) ⇒ Numo::DFloat
Calculate the maximums norm of each sample, and then normalize samples with the norms.
48 49 50 51 52 53 |
# File 'rumale-preprocessing/lib/rumale/preprocessing/max_normalizer.rb', line 48 def fit_transform(x, _y = nil) x = ::Rumale::Validation.check_convert_sample_array(x) fit(x) x / @norm_vec.(1) end |
#transform(x) ⇒ Numo::DFloat
Calculate the maximum norms of each sample, and then normalize samples with the norms. This method calls the fit_transform method. This method exists for the Pipeline class.
60 61 62 63 64 |
# File 'rumale-preprocessing/lib/rumale/preprocessing/max_normalizer.rb', line 60 def transform(x) x = ::Rumale::Validation.check_convert_sample_array(x) fit_transform(x) end |