Class: CrossEntropy::BetaProblem

Inherits:
AbstractProblem show all
Includes:
NMath
Defined in:
lib/cross_entropy/beta_problem.rb

Overview

Solve a continuous optimisation problem in which the variables are bounded to the unit interval, [0, 1]. The sampling distribution of each parameter is assumed to be a Beta distribution with parameters alpha and beta.

Instance Attribute Summary

Attributes inherited from AbstractProblem

#elite_score, #max_iters, #min_score, #num_elite, #num_iters, #num_samples, #overall_min_score, #overall_min_score_sample, #params, #track_overall_min

Instance Method Summary collapse

Methods inherited from AbstractProblem

#for_stop_decision, #solve, #to_estimate, #to_generate_samples, #to_score_sample, #to_update

Constructor Details

#initialize(alpha, beta) {|_self| ... } ⇒ BetaProblem

Returns a new instance of BetaProblem.

Yields:

  • (_self)

Yield Parameters:



13
14
15
16
17
18
19
20
# File 'lib/cross_entropy/beta_problem.rb', line 13

def initialize(alpha, beta)
  super [alpha, beta]

  to_generate_samples { generate_beta_samples }
  to_estimate { |elite| estimate_mom(elite) }

  yield(self) if block_given?
end

Instance Method Details

#estimate_mom(elite) ⇒ Array

Method of moments estimate using only the given ‘elite’ solutions.

Maximum likelihood estimates for the parameters of the beta distribution are difficult to compute, so we use the method of moments instead; see www.itl.nist.gov/div898/handbook/eda/section3/eda366h.htm for more information.

Parameters:

  • elite (NArray)

    elite samples; dimension 0 is the sample index; the remaining dimensions contain the samples

Returns:

  • (Array)

    the estimated parameter arrays



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cross_entropy/beta_problem.rb', line 52

def estimate_mom(elite)
  mean = elite.mean(0)
  variance = elite.stddev(0)**2

  q = mean * (1.0 - mean)
  valid = 0 < variance && variance < q
  r = q[valid] / variance[valid] - 1

  alpha = NArray[*param_alpha.map(&:to_f)]
  alpha[valid] = mean[valid] * r

  beta = NArray[*param_beta.map(&:to_f)]
  beta[valid] = (1.0 - mean[valid]) * r

  [alpha, beta]
end

#generate_beta_samplesObject

Generate samples.



33
34
35
36
37
# File 'lib/cross_entropy/beta_problem.rb', line 33

def generate_beta_samples
  NArray[*param_alpha.to_a.zip(param_beta.to_a).map do |alpha, beta|
    generate_beta_sample(alpha, beta)
  end]
end

#param_alphaObject



22
23
24
# File 'lib/cross_entropy/beta_problem.rb', line 22

def param_alpha
  params[0]
end

#param_betaObject



26
27
28
# File 'lib/cross_entropy/beta_problem.rb', line 26

def param_beta
  params[1]
end