Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a new algorithm #122

Closed
umfundii opened this issue Mar 19, 2024 · 2 comments
Closed

Adding a new algorithm #122

umfundii opened this issue Mar 19, 2024 · 2 comments

Comments

@umfundii
Copy link

Hi,

Thank you for providing this fantastic library. I'm interested in adding a new algorithm, specifically the 'cross-entropy method.'
Could you please provide an example or guidance on how to do this?

Thank you.

@BillHuang2001
Copy link
Collaborator

Yes, we currently have a simple guide on how to add a new algorithm. https://evox.readthedocs.io/en/latest/guide/advanced/3-custom-alg-pro.html#example
This guide will introduce the Algorithm class, which is used to implement new algorithms.

For your case, to implement a typical "cross-entropy method" (from wikipedia)

// Initialize parameters
μ := −6
σ2 := 100
t := 0
maxits := 100
N := 100
Ne := 10
// While maxits not exceeded and not converged
while t < maxits and σ2 > ε do
    // Obtain N samples from current sampling distribution
    X := SampleGaussian(μ, σ2, N)
    // Evaluate objective function at sampled points
    S := exp(−(X − 2) ^ 2) + 0.8 exp(−(X + 2) ^ 2)
    // Sort X by objective function values in descending order
    X := sort(X, S)
    // Update parameters of sampling distribution via elite samples                  
    μ := mean(X(1:Ne))
    σ2 := var(X(1:Ne))
    t := t + 1
// Return mean of final sampling distribution as solution
return μ

You will need to implement the following methods of the Algorithm class

  • __init__
  • setup initialize μ, σ2 here as the state of this algorithm, because these two are changing throughout the iterations.
  • ask do SampleGaussian
  • tell do sort, and update μ, σ2 in the state

I hope this helps.

@umfundii
Copy link
Author

@BillHuang2001 Thanks, I will close this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants