Class: Rumale::NeuralNetwork::RBFRegressor

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

Overview

RBFRegressor is a class that implements regressor based on (k-means) radial basis function (RBF) networks.

Reference

  • Bugmann, G., “Normalized Gaussian Radial Basis Function networks,” Neural Computation, vol. 20, pp. 97–110, 1998.

  • Que, Q., and Belkin, M., “Back to the Future: Radial Basis Function Networks Revisited,” Proc. of AISTATS’16, pp. 1375–1383, 2016.

Examples:

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

require 'rumale/neural_network/rbf_regressor'

estimator = Rumale::NeuralNetwork::RBFRegressor.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, gamma: nil, reg_param: 100.0, normalize: false, max_iter: 50, tol: 1e-4, random_seed: nil) ⇒ RBFRegressor

Create a new regressor with (k-means) RBF networks.

Parameters:

  • hidden_units (Array) (defaults to: 128)

    The number of units in the hidden layer.

  • gamma (Float) (defaults to: nil)

    The parameter for the radial basis function, if nil it is 1 / n_features.

  • reg_param (Float) (defaults to: 100.0)

    The regularization parameter.

  • normalize (Boolean) (defaults to: false)

    The flag indicating whether to normalize the hidden layer output or not.

  • max_iter (Integer) (defaults to: 50)

    The maximum number of iterations for finding centers.

  • tol (Float) (defaults to: 1e-4)

    The tolerance of termination criterion for finding centers.

  • random_seed (Integer) (defaults to: nil)

    The seed value using to initialize the random generator.



48
49
50
51
# File 'rumale-neural_network/lib/rumale/neural_network/rbf_regressor.rb', line 48

def initialize(hidden_units: 128, gamma: nil, reg_param: 100.0, normalize: false,
               max_iter: 50, tol: 1e-4, random_seed: nil)
  super
end

Instance Attribute Details

#centersNumo::DFloat (readonly)

Return the centers in the hidden layer of RBF network.

Returns:

  • (Numo::DFloat)

    (shape: [n_centers, n_features])



29
30
31
# File 'rumale-neural_network/lib/rumale/neural_network/rbf_regressor.rb', line 29

def centers
  @centers
end

#rngRandom (readonly)

Return the random generator.

Returns:

  • (Random)


37
38
39
# File 'rumale-neural_network/lib/rumale/neural_network/rbf_regressor.rb', line 37

def rng
  @rng
end

#weight_vecNumo::DFloat (readonly)

Return the weight vector.

Returns:

  • (Numo::DFloat)

    (shape: [n_centers, n_outputs])



33
34
35
# File 'rumale-neural_network/lib/rumale/neural_network/rbf_regressor.rb', line 33

def weight_vec
  @weight_vec
end

Instance Method Details

#fit(x, y) ⇒ MLPRegressor

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:



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

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 'RBFRegressor#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]) Predicted values per sample.



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

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