No project description provided
Project description
Optirustic Py
This is a Python package that mainly let users import serialised data from JSON files
exported with the optirustic crate.
It lets you:
- import data into Python classes for easy manipulation;
- calculate the population hyper-volume;
- plot 2D, 3D or parallel coordinate charts of the Pareto front.
- initialise the configurations of genetic operators and algorithms from Python in case someone wants to create a Python library that wraps this library along with a specific optimisation problem.
NOTE: this pacage will not let you optimise a problem from Python, but a dedicated Python wrapper can be create in Rust from a pre-defined problem.
Installation
The package can be installed from PyPi:
pip install optirustic
Usage
These are two example scripts to fetch data and plot the Pareto fronts of the optirustic example
files
Python API
All Python API are available in your editor via type hints:
from optirustic import NSGA3
# Load the NSGA3 data first
data = NSGA3(r"../examples/results/DTLZ1_3obj_NSGA3_gen400.json")
# Fetch the problem data
p = data.problem
print(p.number_of_variables)
print(p.variables)
# Fetch the lower bound of X!
print(p.variables["x1"].min_value)
# Get the objective stored into the problem
print(p.objectives)
# Fetch the direction of objective f1
print(p.objectives["f1"].direction)
# Fetch the problem constraints
print(p.constraints)
# Fetch other data such as the algorithm name or generation
print(f"Algorithm name: {data.algorithm}")
print(f"Population reached generation: {data.generation}")
print(f"Algorithm took: {data.took}")
print(f"JSOn file exported on: {data.exported_on}")
# Fetch data for the first individual
print(data.individuals[0])
print(data.individuals[0].constraint_violation)
print(f"Objective values: {data.individuals[0].objectives}")
print(f"Objective f2 value is: {data.individuals[0].get_objective_value("f2")}")
print(f"Variable values: {data.individuals[0].variables}")
print(f"Additional stored data: {data.individuals[0].data}")
# Calculate the hyper-volume
print(f"Hyper-volume is: {data.hyper_volume(reference_point=[100, 100, 100])}")
Generate Pareto front chart
import matplotlib.pyplot as plt
from optirustic import NSGA2, NSGA3
# Plot a 2D charts for a 2-objective problem
NSGA2(r"../examples/results/SCH_2obj_NSGA2_gen250.json").plot()
plt.show()
# Plot a 3D charts for a 3-objective problem
NSGA3(r"../examples/results/DTLZ1_3obj_NSGA3_gen400.json").plot()
plt.show()
# Plot a parallel coordinate chart for an 8-objective problem
NSGA3(r"../examples/results/DTLZ1_8obj_NSGA3_gen750.json").plot()
plt.show()
Generate convergence chart
This template script plots the algorithm convergence by calculating the hyper-volumes at different generations:
import matplotlib.pyplot as plt
from optirustic import NSGA2
# provide the folder where optimistic exported the JSON files
# and a reference point to use in the hyper-volume calculation
NSGA2.plot_convergence(
folder=r"../examples/results/convergence",
reference_point=[10000, 10000]
)
plt.show()
Generate reference points
To generate, plot and inspect the reference points for the NSGA3 algorithm you can us:
One layer
import matplotlib.pyplot as plt
from optirustic import DasDarren1998
ds = DasDarren1998(number_of_objectives=3, number_of_partitions=5)
points = ds.calculate()
ds.plot(points)
plt.show()
Two layers
import matplotlib.pyplot as plt
from optirustic import DasDarren1998
two_layers = dict(
boundary_layer=3,
inner_layer=4,
scaling=None,
)
ds = DasDarren1998(number_of_objectives=3, number_of_partitions=two_layers)
points = ds.calculate()
ds.plot(points)
plt.show()
Initialise an algorithm properties
from optirustic import (
StoppingConditionValue,
StoppingCondition,
Algorithm,
NSGA2Arg,
)
# set the stopping condition at 300 seconds
cond = StoppingConditionValue.max_duration(300)
print(cond)
# define the NSGA2 arguments
args = NSGA2Arg(
number_of_individuals=10,
stopping_condition=StoppingCondition(condition=cond),
)
print(args)
# define the algorithm to use in a Python wrapper
algo = Algorithm.nsga2(args)
print(algo)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file optirustic-0.4.1.tar.gz.
File metadata
- Download URL: optirustic-0.4.1.tar.gz
- Upload date:
- Size: 92.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14d4dcec025871fd062ae2eefd3d892d576d87b544796684c80283a96617bfc5
|
|
| MD5 |
d92e22e27c25c25c2152a43f182bec3b
|
|
| BLAKE2b-256 |
afd3b27beda13b669e81fcbd83ca2f05b2c8a7cb8d71e18569ce378d76717722
|
File details
Details for the file optirustic-0.4.1-cp39-cp39-macosx_11_0_arm64.whl.
File metadata
- Download URL: optirustic-0.4.1-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 690.4 kB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f0b1591ef8dd6165a49075df7458ae33b9310fce7c398a9588ce4483f97c7c8
|
|
| MD5 |
19f68f75c2997233160d37b6676436de
|
|
| BLAKE2b-256 |
c8ec340f921211a50ef7cf6aea076aac01cc2e67d74c2aed5575122411d709b4
|