Skip to main content

Mixed Adaptive Random Search for Optimization

Project description

marsopt logo

marsopt

Mixed Adaptive Random Search for Optimization

PyPI version License Python Versions

marsopt is a Python library designed to simplify and accelerate hyperparameter and black-box optimization. It supports continuous, integer, and categorical variables. Based on Mixed Adaptive Random Search (MARS) algorithm, marsopt dynamically balances exploration and exploitation through:

  • adaptive noise for sampling,
  • elite selection to guide the search toward promising regions,
  • flexible handling of log-scale and categorical parameters,
  • minimization or maximization of any user-defined objective.

MARS iteratively refines a population of “elite” solutions and generates new candidates by perturbing those elites with gradually decreasing noise. For a more detailed explanation of MARS, see our algorithm overview in the documentation.

Features

  • Mixed Variable Support: Optimize integer, float (with optional log-scale), and categorical variables in the same study.
  • Adaptive Sampling: Early iterations explore widely, while later iterations exploit the best regions found, thanks to a built-in cosine annealing scheme for noise.
  • Easy Setup: Simply define an objective function, specify a variable search space, and run study.optimize().
  • Resume & Extend: Continue a Study with more trials at any time without losing past information.
  • Rich Tracking: Inspect all trial details (objective values, parameters, times, and so on) for deeper analysis.

Installation

Install marsopt from PyPI:

pip install marsopt

Getting Started

Below is a simplified example of how to use marsopt to tune a few common hyperparameters:

from marsopt import Study, Trial
import numpy as np

def objective(trial: Trial) -> float:
    lr = trial.suggest_float("learning_rate", 1e-4, 1e-1, log=True)
    layers = trial.suggest_int("num_layers", 1, 5)
    optimizer = trial.suggest_categorical("optimizer", ["adam", "sgd", "rmsprop"])

    score = -5 * (np.log10(lr) + 3) ** 2  
    score += np.log1p(layers) * 10  
    score += {"adam": 15, "sgd": 5, "rmsprop": 20}[optimizer]

    return score 

# Run optimization
study = Study(direction="minimize", random_state=42) # Minimize the  score
study.optimize(objective, n_trials=50)

Documentation

For more detailed information about the API and advanced usage, please refer to the full documentation.

Contributing

Contributions are welcome! If you'd like to improve marsopt or suggest new features, feel free to fork the repository and submit a pull request.

License

This project is licensed under the MIT 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

marsopt-0.1.1.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

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

marsopt-0.1.1-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file marsopt-0.1.1.tar.gz.

File metadata

  • Download URL: marsopt-0.1.1.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for marsopt-0.1.1.tar.gz
Algorithm Hash digest
SHA256 19a15b17eeb71a140e8ea5e0ed4500a6b1104294edcc251368907671f524122c
MD5 e5fc341beb892b5d09ca708180d75356
BLAKE2b-256 598654edce643ece9da81f384c8ac09b33bb852c30903e78c5e01f4b1aa04a2f

See more details on using hashes here.

File details

Details for the file marsopt-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: marsopt-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for marsopt-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 771fbf9ce89faa0ee7c7d17d407116c63fcd33a19ab32efa4fd7db7b94c2a6e7
MD5 dc4e5cfa7a1421cc6857e8a92766d5bd
BLAKE2b-256 61cb3853b0ced964184f4e65972cddbc35ef7e5b7e68cf80b6afba28b253cc4c

See more details on using hashes here.

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