Class: SNES

Inherits:
NES
  • Object
show all
Defined in:
lib/neuroevo/nes.rb

Instance Attribute Summary collapse

Attributes inherited from NES

#id, #mu, #ndims, #obj_fn, #opt_type, #rand, #sigma

Instance Method Summary collapse

Methods inherited from NES

#hansen_lrate, #hansen_popsize, #hansen_utilities, #initialize, #lrate, #move_inds, #popsize, #run, #sorted_inds, #standard_normal_samples, #unit_normal_sample, #utils

Constructor Details

This class inherits a constructor from NES

Instance Attribute Details

#variancesObject (readonly)

Separable NES


151
152
153
# File 'lib/neuroevo/nes.rb', line 151

def variances
  @variances
end

Instance Method Details

#convergenceObject


168
169
170
171
# File 'lib/neuroevo/nes.rb', line 168

def convergence
  # Estimate algorithm convergence as total variance
  variances.reduce :+
end

#initialize_distributionObject


153
154
155
156
157
# File 'lib/neuroevo/nes.rb', line 153

def initialize_distribution
  @mu = NMatrix.zeros([1, ndims], dtype: :float64)
  @variances = NMatrix.ones([1,ndims], dtype: :float64)
  @sigma = NMatrix.diagonal variances
end

#trainObject


159
160
161
162
163
164
165
166
# File 'lib/neuroevo/nes.rb', line 159

def train
  picks = sorted_inds
  g_mu = utils.dot(picks)
  g_sigma = utils.dot(picks**2 - 1)
  @mu += sigma.dot(g_mu.transpose).transpose * lrate
  @variances *= (g_sigma * lrate / 2).exponential
  @sigma = NMatrix.diagonal variances
end