Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonBlanke committed Aug 29, 2021
2 parents 2ef4e61 + 26044b0 commit e1d5f53
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 40 deletions.
128 changes: 128 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.

Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
simon.blanke@yahoo.com.
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series
of actions.

**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
the community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.

Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
34 changes: 25 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Hyperactive features a collection of optimization algorithms that can be used fo
</ul>
<a><b>Data Collection:</b></a>
<ul>
<li><a href="./examples/optimization_applications/meta_data_collection.py">Meta-data Collection</a></li>
<li><a href="./examples/optimization_applications/meta_data_collection.py">Search Data Collection</a></li>
<li><a href="./examples/optimization_applications/meta_optimization.py">Meta Optimization</a></li>
<li><a href="./examples/optimization_applications/meta_learning.py">Meta Learning</a></li>
</ul>
Expand Down Expand Up @@ -959,17 +959,33 @@ A combination between simulated annealing and random search.
<summary><b> Read this before opening a bug-issue </b></summary>

<br>

- <b>Are you sure the bug is located in Hyperactive? </b>

Are you sure the bug is located in Hyperactive?

Look at the error message from the command line. <b>If</b> one of the last messages look like this:
- File "/.../gradient_free_optimizers/...", line ...

<b>Then</b> you should post the bug report in:
- https://github.com/SimonBlanke/Gradient-Free-Optimizers
The error might be located in the optimization-backend.
Look at the error message from the command line. <b>If</b> one of the last messages look like this:
- File "/.../gradient_free_optimizers/...", line ...

<b>Otherwise</b> you can post the bug report in Hyperactive
<b>Then</b> you should post the bug report in:
- https://github.com/SimonBlanke/Gradient-Free-Optimizers

<br>Otherwise</b> you can post the bug report in Hyperactive

- <b>Do you have the correct Hyperactive version? </b>

Every major version update (e.g. v2.2 -> v3.0) the API of Hyperactive changes.
Check which version of Hyperactive you have. If your major version is older you have two options:

<b>Recommended:</b> You could just update your Hyperactive version with:
```bash
pip install hyperactive --upgrade
```
This way you can use all the new documentation and examples from the current repository.

Or you could continue using the old version and use an old repository branch as documentation.
You can do that by selecting the corresponding branch. (top right of the repository. The default is "master" or "main")
So if your major version is older (e.g. v2.1.0) you can select the 2.x.x branch to get the old repository for that version.

</details>


Expand Down
52 changes: 27 additions & 25 deletions examples/optimization_applications/meta_optimization.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import numpy as np
from sklearn.datasets import load_breast_cancer
from hyperactive import Hyperactive

from gradient_free_optimizers import EvolutionStrategyOptimizer

data = load_breast_cancer()
X, y = data.data, data.target
from hyperactive import Hyperactive, BayesianOptimizer

from gradient_free_optimizers import RandomRestartHillClimbingOptimizer

def meta_opt(opt_para):
scores = []

for i in range(25):
for i in range(33):

def sphere_function(para):
loss = []
for key in para.keys():
loss.append(para[key] * para[key])
def ackley_function(para):
x = para["x"]
y = para["y"]
loss1 = - 20 * np.exp(-0.2 * np.sqrt(0.5 * (x * x + y * y)))
loss2 = -np.exp(0.5 * (np.cos(2 * np.pi * x) + np.cos(2 * np.pi * y)))
loss3 = np.exp(1)
loss4 = 20

return -np.array(loss).sum()
loss = loss1 + loss2 + loss3 + loss4

dim_size = np.arange(-10, 10, 0.01)
return -loss

dim_size = np.arange(-6, 6, 0.01)

search_space = {
"x1": dim_size,
"x2": dim_size,
"x": dim_size,
"y": dim_size,
}

opt = EvolutionStrategyOptimizer(
opt = RandomRestartHillClimbingOptimizer(
search_space,
mutation_rate=opt_para["mutation_rate"],
crossover_rate=opt_para["crossover_rate"],
initialize={"random": opt_para["individuals"]},
epsilon=opt_para["epsilon"],
n_neighbours=opt_para["n_neighbours"],
n_iter_restart=opt_para["n_iter_restart"],
)
opt.search(
sphere_function,
ackley_function,
n_iter=100,
random_state=i,
verbosity=False,
Expand All @@ -46,12 +46,14 @@ def sphere_function(para):


search_space = {
"individuals": list(range(2, 11)),
"mutation_rate": list(np.arange(0, 1, 0.1)),
"crossover_rate": list(np.arange(0, 1, 0.1)),
"epsilon": list(np.arange(0.01, 0.1, 0.01)),
"n_neighbours": list(range(1, 10)),
"n_iter_restart": list(range(2, 12)),
}


optimizer = BayesianOptimizer()

hyper = Hyperactive()
hyper.add_search(meta_opt, search_space, n_iter=50)
hyper.add_search(meta_opt, search_space, n_iter=120, optimizer=optimizer)
hyper.run()
12 changes: 9 additions & 3 deletions examples/optimization_applications/progress_visualization.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""
Optimization runs are often like a black box. The information provided in the command line is often sparse.
The Hyperactive ProgressBoard enables the visualization of the optimization progress during the run. I tried
to make its usage as convenient as possible. You only have to initialize the ProgressBoard class and pass it to
.add_search(...). Hyperactive will do the rest!
"""
from sklearn.model_selection import cross_val_score
from sklearn.ensemble import GradientBoostingRegressor, RandomForestRegressor
from sklearn.datasets import load_boston
Expand Down Expand Up @@ -58,7 +64,7 @@ def model_rfr(opt):
# progress_board2 = ProgressBoard()
"""
uncomment the line above and pass progress_board2
to one .add_search(...) to open two browser tabs at the same time
to one .add_search(...) to open an additional browser tabs at the same time
"""


Expand All @@ -76,7 +82,7 @@ def model_rfr(opt):
search_space_rfr,
n_iter=200,
n_jobs=4,
progress_board=progress_board1,
progress_board=progress_board1, # optionally put progress_board2 here
)
# a terminal will open, which opens a dashboard in your browser
# an additional terminal will open, which opens a dashboard in your browser
hyper.run()
6 changes: 3 additions & 3 deletions examples/optimization_applications/search_space_example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
Hyperactive is very versatile, because of it can handle not just numerical or
Hyperactive is very versatile, because it can handle not just numerical or
string variables in the search space, but also functions. This enables many
possibilities for more complex optimization applications. Neural architecture search,
feature engineering, ensemble optimization and many other applications are
only possible or much easier, if you can put functions in the search space.
only possible or much easier if you can put functions in the search space.
"""

from hyperactive import Hyperactive
Expand Down Expand Up @@ -44,7 +44,7 @@ def list3():


def objective_function(para):
# score must be a single number
# score must be a number
score = 1
return score

Expand Down

0 comments on commit e1d5f53

Please sign in to comment.