Class: Rumale::NeuralNetwork::RVFLClassifier
- Inherits:
-
BaseRVFL
- Object
- Base::Estimator
- BaseRVFL
- Rumale::NeuralNetwork::RVFLClassifier
- Includes:
- Base::Classifier
- Defined in:
- rumale-neural_network/lib/rumale/neural_network/rvfl_classifier.rb
Overview
RVFLClassifier is a class that implements classifier based on random vector functional link (RVFL) network. The current implementation uses sigmoid function as activation function.
Reference
-
Malik, A. K., Gao, R., Ganaie, M. A., Tanveer, M., and Suganthan, P. N., “Random vector functional link network: recent developments, applications, and future directions,” Applied Soft Computing, vol. 143, 2023.
-
Zhang, L., and Suganthan, P. N., “A comprehensive evaluation of random vector functional link networks,” Information Sciences, vol. 367–368, pp. 1094–1105, 2016.
Instance Attribute Summary collapse
-
#classes ⇒ Numo::Int32
readonly
Return the class labels.
-
#random_bias ⇒ Numo::DFloat
readonly
Return the bias vector in the hidden layer of RVFL network.
-
#random_weight_vec ⇒ Numo::DFloat
readonly
Return the weight vector in the hidden layer of RVFL network.
-
#rng ⇒ Random
readonly
Return the random generator.
-
#weight_vec ⇒ Numo::DFloat
readonly
Return the weight vector.
Attributes inherited from Base::Estimator
Instance Method Summary collapse
-
#decision_function(x) ⇒ Numo::DFloat
Calculate confidence scores for samples.
-
#fit(x, y) ⇒ RVFLClassifier
Fit the model with given training data.
-
#initialize(hidden_units: 128, reg_param: 100.0, scale: 1.0, random_seed: nil) ⇒ RVFLClassifier
constructor
Create a new classifier with RVFL network.
-
#predict(x) ⇒ Numo::Int32
Predict class labels for samples.
Methods included from Base::Classifier
Constructor Details
#initialize(hidden_units: 128, reg_param: 100.0, scale: 1.0, random_seed: nil) ⇒ RVFLClassifier
Create a new classifier with RVFL network.
55 56 57 |
# File 'rumale-neural_network/lib/rumale/neural_network/rvfl_classifier.rb', line 55 def initialize(hidden_units: 128, reg_param: 100.0, scale: 1.0, random_seed: nil) super end |
Instance Attribute Details
#classes ⇒ Numo::Int32 (readonly)
Return the class labels.
31 32 33 |
# File 'rumale-neural_network/lib/rumale/neural_network/rvfl_classifier.rb', line 31 def classes @classes end |
#random_bias ⇒ Numo::DFloat (readonly)
Return the bias vector in the hidden layer of RVFL network.
39 40 41 |
# File 'rumale-neural_network/lib/rumale/neural_network/rvfl_classifier.rb', line 39 def random_bias @random_bias end |
#random_weight_vec ⇒ Numo::DFloat (readonly)
Return the weight vector in the hidden layer of RVFL network.
35 36 37 |
# File 'rumale-neural_network/lib/rumale/neural_network/rvfl_classifier.rb', line 35 def random_weight_vec @random_weight_vec end |
#rng ⇒ Random (readonly)
Return the random generator.
47 48 49 |
# File 'rumale-neural_network/lib/rumale/neural_network/rvfl_classifier.rb', line 47 def rng @rng end |
#weight_vec ⇒ Numo::DFloat (readonly)
Return the weight vector.
43 44 45 |
# File 'rumale-neural_network/lib/rumale/neural_network/rvfl_classifier.rb', line 43 def weight_vec @weight_vec end |
Instance Method Details
#decision_function(x) ⇒ Numo::DFloat
Calculate confidence scores for samples.
81 82 83 84 85 86 |
# File 'rumale-neural_network/lib/rumale/neural_network/rvfl_classifier.rb', line 81 def decision_function(x) x = ::Rumale::Validation.check_convert_sample_array(x) h = hidden_output(x) h.dot(@weight_vec) end |
#fit(x, y) ⇒ RVFLClassifier
Fit the model with given training data.
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'rumale-neural_network/lib/rumale/neural_network/rvfl_classifier.rb', line 64 def fit(x, y) x = ::Rumale::Validation.check_convert_sample_array(x) y = ::Rumale::Validation.check_convert_label_array(y) ::Rumale::Validation.check_sample_size(x, y) raise 'RVFLClassifier#fit requires Numo::Linalg but that is not loaded.' unless enable_linalg?(warning: false) @classes = Numo::NArray[*y.to_a.uniq.sort] partial_fit(x, one_hot_encode(y)) self end |
#predict(x) ⇒ Numo::Int32
Predict class labels for samples.
92 93 94 95 96 97 98 99 |
# File 'rumale-neural_network/lib/rumale/neural_network/rvfl_classifier.rb', line 92 def predict(x) x = ::Rumale::Validation.check_convert_sample_array(x) scores = decision_function(x) n_samples, n_classes = scores.shape label_ids = scores.max_index(axis: 1) - Numo::Int32.new(n_samples).seq * n_classes @classes[label_ids].dup end |