Skip to main content

Multi-Strategy Parrot Optimizer for hyperparameter tuning

Project description

mspo

Multi-Strategy Parrot Optimizer — a population-based metaheuristic for hyperparameter tuning and continuous black-box optimization.

This is a reference implementation of the algorithm described in:

Govindarajan, V. (2025). MSPO: A machine learning hyperparameter optimization method for enhanced breast cancer image classification. Digital Health.

Install

git clone https://github.com/vijaygovindaraja/mspo.git
cd mspo
pip install -e .

Requires Python 3.10+, NumPy, SciPy.

Quick start

import numpy as np
from mspo import MSPO

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

opt = MSPO(
    objective=sphere,
    bounds=[(-100, 100)] * 10,
    n_parrots=30,
    max_iter=1000,
    seed=42,
)
result = opt.run()

print(result.best_value)        # ~1.6e-12
print(result.best_params)       # ~zeros
print(result.history[-1])       # final best-so-far
print(result.n_evaluations)     # 30030

How it works

MSPO maintains a swarm of agents ("parrots") that explore the search space. Each iteration, every agent independently picks one of four behavioral updates uniformly at random:

Behavior Role Mechanism
Foraging Exploration Levy flight from the global best, with a decaying mean-pull term
Staying Exploitation Drift toward the global best with shrinking uniform noise
Communicating Social Either flock toward the population mean (50%) or fly off solitary with exponential decay (50%)
Fear of strangers Chaotic Cosine-modulated mix of attraction-to-best and repulsion-from-current, driven by a Tent map

Three components distinguish MSPO from the base Parrot Optimizer:

  1. Sobol initialization — low-discrepancy quasi-random sequence for uniform starting coverage of the search space
  2. Nonlinear decreasing inertia weight — exponential decay from w_max = 2.0 toward w_min = 0.2, driving the algorithm from broad exploration to fine exploitation over the course of the run
  3. Parametric Tent map — chaotic coefficient (β = 0.4, C₀ = 0.255) for the fear-of-strangers behavior, helping the swarm escape local optima in the late stages of optimization

Module layout

mspo/
├── initialization.py   # Sobol low-discrepancy starting population
├── inertia.py          # Nonlinear decreasing inertia weight schedule
├── chaos.py            # Parametric Tent map (state-carrying iterator)
├── utils.py            # Levy flight via Mantegna's algorithm
├── behaviors.py        # The four position update rules
└── optimizer.py        # MSPO class and main loop

Each module is small (under 200 lines) and accompanied by unit tests in tests/. The four behaviors share a uniform signature so the main loop dispatches to them by index.

Validation

Unit tests

73 tests across 7 modules, under 3 seconds:

pytest                     # full suite
pytest -m "not slow"       # skip the long sphere test

CEC 2022 benchmark (official shifted/rotated functions)

Full benchmark using the official CEC 2022 SO-BO competition suite (12 shifted/rotated functions with the published shift vectors and rotation matrices from Suganthan et al., NTU Singapore). Evaluation protocol: N=30 agents, T=1000 iterations, dim=10, 30 independent runs per function, bounds [-100, 100].

Results — median error (f(x) - f*) on each function:

Func Name MSPO PSO Random Winner
F1 Zakharov 45.06 0.00 5436.40 PSO
F2 Rosenbrock 10.05 62.98 256.16 MSPO
F3 Schaffer F7 1.71e-04 0.03 0.20 MSPO
F4 Rastrigin 38.00 51.00 87.90 MSPO
F5 Levy 0.55 0.67 2.47 MSPO
F6 Hybrid 1 39637 58895 10425125 MSPO
F7 Hybrid 2 60.02 29.50 214.49 PSO
F8 Hybrid 3 472.03 298.72 1061.58 PSO
F9 Composition 1 398.04 426.70 516.36 MSPO
F10 Composition 2 -1254.97 29.57 -366.14 MSPO
F11 Composition 3 2.32 79.14 117.85 MSPO
F12 Composition 4 165.34 170.97 242.15 MSPO

MSPO ranks 1st on 9 of 12 functions with average rank 1.25, consistent with the paper's reported results (1st on 9/12, avg rank 1.42).

To reproduce:

pip install -e ".[benchmark]"
python benchmarks/run_cec2022.py          # full run (~2.5 hours)
python benchmarks/run_cec2022.py --quick  # 5 runs, T=200 (~2 min)

Convergence on 10D Sphere

End-to-end demo on the paper's exact CEC configuration (N=30, T=1000):

Iteration Best so far
0 3.65 × 10³
100 8.56 × 10⁻²
500 1.10 × 10⁻⁴
1000 1.63 × 10⁻¹²

Configuration

The defaults match the paper. The full constructor:

MSPO(
    objective,            # f(x) -> float, position vector in -> scalar out
    bounds,               # iterable of (low, high) per dimension
    n_parrots=30,         # population size
    max_iter=1000,        # number of outer iterations
    w_max=2.0,            # initial inertia weight
    w_min=0.2,            # asymptotic floor
    lambda_=0.005,        # inertia exponential decay rate
    tent_c0=0.255,        # tent map initial value
    tent_beta=0.4,        # tent map breakpoint
    seed=None,            # for reproducibility
)

Set seed to make the run fully reproducible — the same seed reproduces the Sobol initialization, the per-iteration behavior choices, the Levy draws, and every internal uniform draw.

Citation

If you use this code, please cite:

@article{govindarajan2025mspo,
    title   = {MSPO: A machine learning hyperparameter optimization method for enhanced breast cancer image classification},
    author  = {Govindarajan, Vijay},
    journal = {Digital Health},
    year    = {2025},
}

License

MIT — see LICENSE.

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

mspo-0.1.0.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mspo-0.1.0-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file mspo-0.1.0.tar.gz.

File metadata

  • Download URL: mspo-0.1.0.tar.gz
  • Upload date:
  • Size: 25.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mspo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d942a6f7fbed2205bd51dee3da7308219c18d18ca4d094f27b8298d96a3886ac
MD5 af8c7b55cbe461bbd6dfe8c9295f0eb4
BLAKE2b-256 f66033ff77888c49f198a21baf5e34f298a3fcceb032bc7c98f4e08d773023a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for mspo-0.1.0.tar.gz:

Publisher: publish.yml on vijaygovindaraja/mspo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mspo-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mspo-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mspo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ca86b557c853890e640f9d44452da1c49c877e5f92137b47fd0bd7185a13a502
MD5 37ff9bfbd3ed0ddb83a7be867c7da4a2
BLAKE2b-256 c13996c9d9a09b7d205f38c819f282f47b64dc82748ecce46f331b3fa2f47a71

See more details on using hashes here.

Provenance

The following attestation bundles were made for mspo-0.1.0-py3-none-any.whl:

Publisher: publish.yml on vijaygovindaraja/mspo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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