Skip to main content

Another optimization package

Project description

fortoptim

Fortoptim is an optimization library based on python and fortran routines.

Installation

Prerequisite:

  • python 3.12
  • gfortran

from the gitlab repository

After cloning the repository, run in the project folder:

python -m pip install -e .

and compile the fortran source files with:

fortoptim-compile

pip

python -m pip install fortoptim
fortoptim-compile

Demonstration with MultiSwarmCooperativePSO on Ackley problem

import numpy as np

from fortoptim.optimizers.pso import MultiSwarmCooperativePSO
from fortoptim.problems import Ackley

dim = 2
lower = -32
upper = 32
constraints = [np.array([lower, upper])] * dim
problem = Ackley(dim=dim, constraints=constraints)

# initial population and velocity
n = 6
sub_swarm = [np.random.uniform(size=(n, dim), low=lower, high=upper) for i in range(4)]
# sub_swarm_velocity = [np.random.uniform(size=(n, dim), high=0.8) for i in range(4)]
sub_swarm_velocity = [np.zeros(shape=(n, dim)) for i in range(4)]

# initialize optimizer with default parameters
opti = MultiSwarmCooperativePSO(eps=0.0)

history = opti.minimize(problem, sub_swarm, sub_swarm_velocity, max_iter=10000)

x_plot = np.random.uniform(size=(200000, dim), low=lower, high=upper)

x_best, f_best = history.get_best_solution()
print(f"The best solution is {x_best} obtained at {f_best}.")

history.plot_loss_history(log=True, show=True)

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

fortoptim-0.0.10.tar.gz (22.8 kB view hashes)

Uploaded Source

Built Distribution

fortoptim-0.0.10-py3-none-any.whl (25.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page