Class: Rumale::NeuralNetwork::RVFLRegressor

Inherits:
BaseRVFL show all
Includes:
Base::Regressor
Defined in:
rumale-neural_network/lib/rumale/neural_network/rvfl_regressor.rb

Overview

RVFLRegressor is a class that implements regressor 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.

Examples:

require 'numo/tiny_linalg'
Numo::Linalg = Numo::TinyLinalg

require 'rumale/neural_network/rvfl_regressor'

estimator = Rumale::NeuralNetwork::RVFLRegressor.new(hidden_units: 128, reg_param: 100.0)
estimator.fit(training_samples, traininig_values)
results = estimator.predict(testing_samples)

Instance Attribute Summary collapse

Attributes inherited from Base::Estimator

#params

Instance Method Summary collapse

Methods included from Base::Regressor

#score

Constructor Details

#initialize(hidden_units: 128, reg_param: 100.0, scale: 1.0, random_seed: nil) ⇒ RVFLRegressor

Create a new regressor with RVFL network.

Parameters:

  • hidden_units (Array) (defaults to: 128)

    The number of units in the hidden layer.

  • reg_param (Float) (defaults to: 100.0)

    The regularization parameter.

  • scale (Float) (defaults to: 1.0)

    The scale parameter for random weight and bias.

  • random_seed (Integer) (defaults to: nil)

    The seed value using to initialize the random generator.



50
51
52
# File 'rumale-neural_network/lib/rumale/neural_network/rvfl_regressor.rb', line 50

def initialize(hidden_units: 128, reg_param: 100.0, scale: 1.0, random_seed: nil)
  super
end

Instance Attribute Details

#random_biasNumo::DFloat (readonly)

Return the bias vector in the hidden layer of RVFL network.

Returns:

  • (Numo::DFloat)

    (shape: [n_hidden_units])



34
35
36
# File 'rumale-neural_network/lib/rumale/neural_network/rvfl_regressor.rb', line 34

def random_bias
  @random_bias
end

#random_weight_vecNumo::DFloat (readonly)

Return the weight vector in the hidden layer of RVFL network.

Returns:

  • (Numo::DFloat)

    (shape: [n_hidden_units, n_features])



30
31
32
# File 'rumale-neural_network/lib/rumale/neural_network/rvfl_regressor.rb', line 30

def random_weight_vec
  @random_weight_vec
end

#rngRandom (readonly)

Return the random generator.

Returns:

  • (Random)


42
43
44
# File 'rumale-neural_network/lib/rumale/neural_network/rvfl_regressor.rb', line 42

def rng
  @rng
end

#weight_vecNumo::DFloat (readonly)

Return the weight vector.

Returns:

  • (Numo::DFloat)

    (shape: [n_features + n_hidden_units, n_outputs])



38
39
40
# File 'rumale-neural_network/lib/rumale/neural_network/rvfl_regressor.rb', line 38

def weight_vec
  @weight_vec
end

Instance Method Details

#fit(x, y) ⇒ RVFLRegressor

Fit the model with given training data.

Parameters:

  • x (Numo::DFloat)

    (shape: [n_samples, n_features]) The training data to be used for fitting the model.

  • y (Numo::DFloat)

    (shape: [n_samples, n_outputs]) The taget values to be used for fitting the model.

Returns:



59
60
61
62
63
64
65
66
67
68
69
70
# File 'rumale-neural_network/lib/rumale/neural_network/rvfl_regressor.rb', line 59

def fit(x, y)
  x = ::Rumale::Validation.check_convert_sample_array(x)
  y = ::Rumale::Validation.check_convert_target_value_array(y)
  ::Rumale::Validation.check_sample_size(x, y)
  raise 'RVFLRegressor#fit requires Numo::Linalg but that is not loaded.' unless enable_linalg?(warning: false)

  y = y.expand_dims(1) if y.ndim == 1

  partial_fit(x, y)

  self
end

#predict(x) ⇒ Numo::DFloat

Predict values for samples.

Parameters:

  • x (Numo::DFloat)

    (shape: [n_samples, n_features]) The samples to predict the values.

Returns:

  • (Numo::DFloat)

    (shape: [n_samples, n_outputs]) The predicted values per sample.



76
77
78
79
80
81
82
83
# File 'rumale-neural_network/lib/rumale/neural_network/rvfl_regressor.rb', line 76

def predict(x)
  x = ::Rumale::Validation.check_convert_sample_array(x)

  h = hidden_output(x)
  out = h.dot(@weight_vec)
  out = out[true, 0] if out.shape[1] == 1
  out
end