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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file fortoptim-0.0.10.tar.gz.

File metadata

  • Download URL: fortoptim-0.0.10.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for fortoptim-0.0.10.tar.gz
Algorithm Hash digest
SHA256 b1d035b72085da2fbdef687dac7ee24d2356e26b5d2354b3ba0ac43ec2a74c3e
MD5 bdd827c2a7816567d71ffbc1f83fcaaa
BLAKE2b-256 a18c67a15f3d1a9fd8c0660bcc2eb56661b8df48a435c14882ab975f3ffc198c

See more details on using hashes here.

File details

Details for the file fortoptim-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: fortoptim-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 25.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for fortoptim-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 2c3eb24df0054e923c70bc651eb4091e0a46dfef99d9f4ffe736d4f4b502ed16
MD5 7d8477dd2dc5f93e94c7d718fe0af15b
BLAKE2b-256 bb36ee9ee5f46cca6c1bb563dc0fecf3a2ec75ab8660c086f96c0fc6eac1edc8

See more details on using hashes here.

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