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

Add sigma, sigma0 to gaussian_emitter and iso_line_emitter #199

Merged
merged 10 commits into from
Jun 2, 2022

Conversation

itsdawei
Copy link
Collaborator

@itsdawei itsdawei commented Jun 2, 2022

Description

Allow user to configure different standard deviations (sigma, sigma0) for initialization and sampling steps of gaussian_emitter and iso_line_emitter.

TODO / DONE

  • Change sigma0 to optional parameter (defaults to sigma). sigma0 is used to generate new solutions when the archive is empty, and added parametersigma, which used to sample solutions from a non-empty archive.
  • Add optional parametersigma0 to Iso_Line_Emitter.
  • Change iso_line_emitter_test::test_properties_are_correct to test for sigma0.
  • Change factory_test to reflect constructor change
  • Add additional test iso_line_emitter_test::test_sigma0_is_correct and gaussian_emitter_test::test_sigma0_is_correct

Status

  • I have read the guidelines in CONTRIBUTING.md.
  • I have formatted my code using yapf
  • I have tested my code by running pytest
  • I have linted my code with pylint
  • I have added a one-line description of my change to the changelog in HISTORY.md.
  • This PR is ready to go

@itsdawei itsdawei requested a review from btjanaka June 2, 2022 04:40
@itsdawei itsdawei self-assigned this Jun 2, 2022
ribs/emitters/_gaussian_emitter.py Outdated Show resolved Hide resolved
ribs/emitters/_gaussian_emitter.py Outdated Show resolved Hide resolved
ribs/emitters/_gaussian_emitter.py Outdated Show resolved Hide resolved
ribs/emitters/_gaussian_emitter.py Outdated Show resolved Hide resolved
ribs/emitters/_gaussian_emitter.py Outdated Show resolved Hide resolved
ribs/emitters/_gaussian_emitter.py Outdated Show resolved Hide resolved
ribs/emitters/_iso_line_emitter.py Outdated Show resolved Hide resolved
tests/emitters/iso_line_emitter_test.py Outdated Show resolved Hide resolved
Copy link
Member

@btjanaka btjanaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small changes. Have some comments I will talk to you about offline.

ribs/emitters/_gaussian_emitter.py Outdated Show resolved Hide resolved
ribs/emitters/_gaussian_emitter.py Outdated Show resolved Hide resolved
ribs/emitters/_gaussian_emitter.py Outdated Show resolved Hide resolved
ribs/emitters/_iso_line_emitter.py Outdated Show resolved Hide resolved
tests/emitters/gaussian_emitter_test.py Outdated Show resolved Hide resolved
@itsdawei
Copy link
Collaborator Author

itsdawei commented Jun 2, 2022

Visualizing using the new sigma0 parameter.

from ribs.archives import GridArchive
from ribs.emitters import GaussianEmitter, IsoLineEmitter
from ribs.optimizers import Optimizer
import numpy as np
import matplotlib.pyplot as plt
from ribs.visualize import grid_archive_heatmap

archive = GridArchive(
    dims=[20, 20],
    ranges=[(-1, 1), (-1, 1)],
)

# emitters = [
#     GaussianEmitter(
#         archive,
#         x0=[0.0] * 10,
#         sigma=1,
#         sigma0=0.1,  # should generate a small circle of solutions around (0,0)
#     )
# ]

emitters = [
    IsoLineEmitter(
        archive,
        x0=[0.0] * 10,
        iso_sigma=1,
        sigma0=0.1,  # should generate a small circle of solutions around (0,0)
    )
]

optimizer = Optimizer(archive, emitters)

for itr in range(1000):
    solutions = optimizer.ask()

    # Optimize the 10D negative Sphere function.
    objectives = -np.sum(np.square(solutions), axis=1)

    # BCs: first 2 coordinates of each 10D solution.
    bcs = solutions[:, :2]
    optimizer.tell(objectives, bcs)

    # plot every 100 iteration
    if itr % 100 == 0:
        plt.figure()
        grid_archive_heatmap(archive)
        plt.savefig(f"img/plot{itr}.png", dpi=300)
        plt.close()

GaussianEmitter (sigma0=0)

plot0

GaussianEmitter (sigma0=0.1)

plot0

IsoLineEmitter (sigma0=0)

plot0

IsoLineEmitter (sigma0=0.1)

plot0

ribs/emitters/_gaussian_emitter.py Outdated Show resolved Hide resolved
@itsdawei itsdawei marked this pull request as ready for review June 2, 2022 20:47
@itsdawei itsdawei merged commit 4e8a8c7 into master Jun 2, 2022
@itsdawei itsdawei deleted the add-sigma-gaussian-and-iso-line-emitter branch June 2, 2022 20:48
@btjanaka btjanaka added the API label Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants