-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1f8d69
commit 063d1c7
Showing
23 changed files
with
2,831 additions
and
1,099 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
% ----------------------------------------------------------------- | ||
% One-dimensional optimization with the Cross-entropy method | ||
% | ||
% Example from: | ||
% Reuven Y. Rubinstein, Dirk P. Kroese | ||
% The Cross-Entropy Method: A Unified Approach to | ||
% Combinatorial Optimization, Monte-Carlo Simulation, | ||
% and Machine Learning | ||
% Springer-Verlag, 2004. | ||
% ----------------------------------------------------------------- | ||
|
||
clc | ||
clear | ||
close all | ||
|
||
S = inline('exp(-(x-2).^2) + 0.8*exp(-(x+2).^2)'); | ||
|
||
mu = -6; | ||
sigma = 10; | ||
Nel = 10; | ||
N = 100; | ||
eps = 1E-8; | ||
tic | ||
t=0; | ||
|
||
while sigma > eps | ||
t = t+1; | ||
x = mu + sigma*randn(N,1); | ||
SX = S(x); | ||
sortSX = sortrows([x SX],2); | ||
Xel = sortSX((N - Nel + 1):N,1); | ||
mu = mean(Xel); | ||
sigma = std(Xel); | ||
fprintf('%g %6.9f %6.9f %6.9f \n', t, S(mu),mu, sigma) | ||
end | ||
|
||
mu | ||
toc |
Oops, something went wrong.