Skip to content

Commit

Permalink
Merge pull request #17 from gugarosa/dev
Browse files Browse the repository at this point in the history
Merging up dev to master for newest stable release.
  • Loading branch information
gugarosa authored May 12, 2021
2 parents e9593fb + fd1ba07 commit 3b770e6
Show file tree
Hide file tree
Showing 365 changed files with 8,526 additions and 11,272 deletions.
7 changes: 5 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ disable=print-statement,
no-self-use,
duplicate-code,
abstract-method,
super-with-arguments
super-with-arguments,
import-error,
unnecessary-pass,
redefined-builtin

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down Expand Up @@ -571,7 +574,7 @@ valid-metaclass-classmethod-first-arg=cls
max-args=10

# Maximum number of attributes for a class (see R0902).
max-attributes=20
max-attributes=25

# Maximum number of boolean expressions in an if statement (see R0916).
max-bool-expr=5
Expand Down
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Opytimizer: A Nature-Inspired Python Optimizer

[![Latest release](https://img.shields.io/github/release/gugarosa/opytimizer.svg)](https://github.com/gugarosa/opytimizer/releases)
[![DOI](https://zenodo.org/badge/109152650.svg)](https://zenodo.org/badge/latestdoi/109152650)
[![DOI](http://img.shields.io/badge/DOI-10.5281/zenodo.4594294-006DB9.svg)](https://doi.org/10.5281/zenodo.4594294)
[![Build status](https://img.shields.io/travis/com/gugarosa/opytimizer/master.svg)](https://github.com/gugarosa/opytimizer/releases)
[![Open issues](https://img.shields.io/github/issues/gugarosa/opytimizer.svg)](https://github.com/gugarosa/opytimizer/issues)
[![License](https://img.shields.io/github/license/gugarosa/opytimizer.svg)](https://github.com/gugarosa/opytimizer/blob/master/LICENSE)
Expand Down Expand Up @@ -65,6 +65,7 @@ Opytimizer is based on the following structure, and you should pay attention to
- optimizer
- space
- functions
- constrained
- weighted
- math
- distribution
Expand All @@ -86,8 +87,8 @@ Opytimizer is based on the following structure, and you should pay attention to
- search
- tree
- utils
- constants
- decorator
- callback
- constant
- exception
- history
- logging
Expand All @@ -106,19 +107,19 @@ Instead of using raw and straightforward functions, why not try this module? Com
### Math
Just because we are computing stuff, it does not means that we do not need math. Math is the mathematical package, containing low-level math implementations. From random numbers to distributions generation, you can find your needs on this module.
Just because we are computing stuff does not means that we do not need math. Math is the mathematical package containing low-level math implementations. From random numbers to distribution generation, you can find your needs on this module.
### Optimizers
This is why we are called Opytimizer. This is the heart of the heuristics, where you can find a large number of meta-heuristics, optimization techniques, anything that can be called as an optimizer. Please take a look on the [available optimizers](https://github.com/gugarosa/opytimizer/wiki/Types-of-Optimizers).
This is why we are called Opytimizer. This is the heart of heuristics, where you can find a large number of meta-heuristics, optimization techniques, anything that can be called an optimizer. Please take a look at the [available optimizers](https://github.com/gugarosa/opytimizer/wiki/Types-of-Optimizers).
### Spaces
One can see the space as the place that agents will update their positions and evaluate a fitness function. However, the newest approaches may consider a different type of space. Thinking about that, we are glad to support diverse space implementations.
### Utils
This is a utility package. Common things shared across the application should be implemented here. It is better to implement once and use as you wish than re-implementing the same thing over and over again.
This is a utility package. Common things shared across the application should be implemented here. It is better to implement once and use as you wish than re-implementing the same thing repeatedly.
### Visualization
Expand All @@ -128,7 +129,7 @@ Everyone needs images and plots to help visualize what is happening, correct? Th
## Installation
We believe that everything has to be easy. Not tricky or daunting, Opytimizer will be the one-to-go package that you will need, from the very first installation to the daily-tasks implementing needs. If you may just run the following under your most preferred Python environment (raw, conda, virtualenv, whatever):
We believe that everything has to be easy. Not tricky or daunting, Opytimizer will be the one-to-go package that you will need, from the first installation to the daily tasks implementing needs. If you may just run the following under your most preferred Python environment (raw, conda, virtualenv, whatever):
```bash
pip install opytimizer
Expand All @@ -148,15 +149,15 @@ Note that sometimes, there is a need for additional implementation. If needed, f

### Ubuntu

No specific additional commands needed.
No specific additional commands are needed.

### Windows

No specific additional commands needed.
No specific additional commands are needed.

### MacOS

No specific additional commands needed.
No specific additional commands are needed.

---

Expand All @@ -168,25 +169,24 @@ Take a look at a quick working example of Opytimizer. Note that we are not passi
import numpy as np

from opytimizer import Opytimizer
from opytimizer.core.function import Function
from opytimizer.optimizers.swarm.pso import PSO
from opytimizer.spaces.search import SearchSpace
from opytimizer.core import Function
from opytimizer.optimizers.swarm import PSO
from opytimizer.spaces import SearchSpace

def sphere(x):
return np.sum(x ** 2)

n_agents = 20
n_variables = 2
n_iterations = 1000
lower_bound = (-10, -10)
upper_bound = (10, 10)
lower_bound = [-10, -10]
upper_bound = [10, 10]

s = SearchSpace(n_agents, n_iterations, n_variables, lower_bound, upper_bound)
p = PSO()
f = Function(sphere)
space = SearchSpace(n_agents, n_variables, lower_bound, upper_bound)
optimizer = PSO()
function = Function(sphere)

o = Opytimizer(s, p, f)
o.start()
opt = Opytimizer(space, optimizer, function)
opt.start(n_iterations=1000)
```

---
Expand Down
2 changes: 1 addition & 1 deletion docs/api/opytimizer.core.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
opytimizer.core
=========================

Core is the core. Essentially, it is the parent of everything. You should find parent classes defining the basic of our structure. They should provide variables and methods that will help to construct other modules.
Core is the core. Essentially, it is the parent of everything. You should find parent classes defining the basis of our structure. They should provide variables and methods that will help to construct other modules.

.. toctree::
opytimizer.core.agent
Expand Down
7 changes: 7 additions & 0 deletions docs/api/opytimizer.functions.constrained.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
opytimizer.functions.constrained
=================================

.. automodule:: opytimizer.functions.constrained
:members:
:private-members:
:special-members:
4 changes: 2 additions & 2 deletions docs/api/opytimizer.functions.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
opytimizer.functions
=========================

Instead of using raw and simple functions, why not try this module? Compose high-level abstract functions or even new function-based ideas in order to solve your problems. Note that for now, we will only support multi-objective function strategies.
Instead of using raw and straightforward functions, why not try this module? Compose high-level abstract functions or even new function-based ideas in order to solve your problems. Note that for now, we will only support multi-objective function strategies.

.. toctree::
opytimizer.functions.constrained
opytimizer.functions.weighted


.. automodule:: opytimizer.functions
:members:
:show-inheritance:
2 changes: 1 addition & 1 deletion docs/api/opytimizer.math.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
opytimizer.math
=========================

Just because we are computing stuff, it does not means that we do not need math. Math is the mathematical package, containing low level math implementations. From random numbers to distributions generation, you can find your needs on this module.
Just because we are computing stuff does not means that we do not need math. Math is the mathematical package containing low-level math implementations. From random numbers to distribution generation, you can find your needs on this module.

.. toctree::
opytimizer.math.distribution
Expand Down
2 changes: 1 addition & 1 deletion docs/api/opytimizer.optimizers.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
opytimizer.optimizers
======================

This is why we are called Opytimizer. This is the heart of the heuristics, where you can find a broad number of meta-heuristics, optimization techniques, anything that can be called as an optimizer. Investigate over any module for more information.
This is why we are called Opytimizer. This is the heart of heuristics, where you can find a large number of meta-heuristics, optimization techniques, anything that can be called an optimizer. Please take a look at the [available optimizers](https://github.com/gugarosa/opytimizer/wiki/Types-of-Optimizers).

.. toctree::
opytimizer.optimizers.boolean
Expand Down
2 changes: 1 addition & 1 deletion docs/api/opytimizer.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
opytimizer
=========================
===========

.. autoclass:: opytimizer.Opytimizer
:members:
Expand Down
2 changes: 1 addition & 1 deletion docs/api/opytimizer.spaces.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
opytimizer.spaces
=========================

One can see the space as the place that agents will update their positions and evaluate a fitness function. However, newest approaches may consider a different type of space. Thinking on that, we are glad to support diverse space implementations.
One can see the space as the place that agents will update their positions and evaluate a fitness function. However, the newest approaches may consider a different type of space. Thinking about that, we are glad to support diverse space implementations.

.. toctree::
opytimizer.spaces.boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
opytimizer.utils.decorator
opytimizer.utils.callback
===========================

.. automodule:: opytimizer.utils.decorator
.. automodule:: opytimizer.utils.callback
:members:
:private-members:
:special-members:
7 changes: 7 additions & 0 deletions docs/api/opytimizer.utils.constant.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
opytimizer.utils.constant
==========================

.. automodule:: opytimizer.utils.constant
:members:
:private-members:
:special-members:
7 changes: 0 additions & 7 deletions docs/api/opytimizer.utils.constants.rst

This file was deleted.

6 changes: 3 additions & 3 deletions docs/api/opytimizer.utils.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
opytimizer.utils
=========================

This is an utilities package. Common things shared across the application should be implemented here. It is better to implement once and use as you wish than re-implementing the same thing over and over again.
This is a utility package. Common things shared across the application should be implemented here. It is better to implement once and use as you wish than re-implementing the same thing repeatedly.

.. toctree::
opytimizer.utils.constants
opytimizer.utils.decorator
opytimizer.utils.callback
opytimizer.utils.constant
opytimizer.utils.exception
opytimizer.utils.history
opytimizer.utils.logging
Expand Down
2 changes: 1 addition & 1 deletion docs/api/opytimizer.visualization.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
opytimizer.visualization
=========================

Everyone needs images and plots to help visualize what is happening, correct? This package will provide every visual-related method for you. Check a specific variable convergence, your fitness function convergence, plot benchmark function surfaces and much more!
Everyone needs images and plots to help visualize what is happening, correct? This package will provide every visual-related method for you. Check a specific variable convergence, your fitness function convergence, plot benchmark function surfaces, and much more!

.. toctree::
opytimizer.visualization.convergence
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import numpy as np
from opytimark.markers.n_dimensional import Sphere

from opytimizer import Opytimizer
from opytimizer.core import Function
from opytimizer.optimizers.swarm import PSO
from opytimizer.spaces import SearchSpace
from opytimizer.utils.callback import CheckpointCallback

# Random seed for experimental consistency
np.random.seed(0)

# Number of agents and decision variables
n_agents = 20
n_variables = 2

# Lower and upper bounds (has to be the same size as `n_variables`)
lower_bound = [-10, -10]
upper_bound = [10, 10]

# Creates the space, optimizer and function
space = SearchSpace(n_agents, n_variables, lower_bound, upper_bound)
optimizer = PSO()
function = Function(Sphere())

# Bundles every piece into Opytimizer class
opt = Opytimizer(space, optimizer, function, save_agents=False)

# Runs the optimization task
# CheckpointCallback will snapshot the optimization every `frequency` iterations
opt.start(n_iterations=10, callbacks=[CheckpointCallback(frequency=1)])
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import numpy as np
from opytimark.markers.n_dimensional import Sphere

from opytimizer import Opytimizer
from opytimizer.core import Function
from opytimizer.optimizers.swarm import PSO
from opytimizer.spaces import SearchSpace

# Random seed for experimental consistency
np.random.seed(0)

# Number of agents and decision variables
n_agents = 20
n_variables = 2

# Lower and upper bounds (has to be the same size as `n_variables`)
lower_bound = [-10, -10]
upper_bound = [10, 10]

# Creates the space, optimizer and function
space = SearchSpace(n_agents, n_variables, lower_bound, upper_bound)
optimizer = PSO()
function = Function(Sphere())

# Bundles every piece into Opytimizer class
opt = Opytimizer(space, optimizer, function, save_agents=False)

# Runs the optimization task
# Every call on `start` will the continue the optimization for `n_iterations`
# Note that the following lines achieves the same results as a 100-iteration running
opt.start(n_iterations=50)
opt.start(n_iterations=25)
opt.start(n_iterations=25)
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import numpy as np
from opytimark.markers.n_dimensional import Sphere

from opytimizer import Opytimizer
from opytimizer.core import Function
from opytimizer.optimizers.swarm import PSO
from opytimizer.spaces import SearchSpace
from opytimizer.utils.callback import CheckpointCallback

# Random seed for experimental consistency
np.random.seed(0)

# Number of agents and decision variables
n_agents = 20
n_variables = 2

# Lower and upper bounds (has to be the same size as `n_variables`)
lower_bound = [-10, -10]
upper_bound = [10, 10]

# Creates the space, optimizer and function
space = SearchSpace(n_agents, n_variables, lower_bound, upper_bound)
optimizer = PSO()
function = Function(Sphere())

# Bundles every piece into Opytimizer class
opt = Opytimizer(space, optimizer, function, save_agents=False)

# Runs the optimization task
opt.start(n_iterations=10, callbacks=[CheckpointCallback(frequency=10)])

# Deletes the optimization objecs
del opt

# Loads the task from file and resumes it
# Note that the following lines achieves the same results as a 35-iteration running
opt = Opytimizer.load('iter_10_checkpoint.pkl')
opt.start(n_iterations=25)
37 changes: 0 additions & 37 deletions examples/applications/boolean_optimization.py

This file was deleted.

Loading

0 comments on commit 3b770e6

Please sign in to comment.