Skip to main content

MetaGen: A framework for metaheuristic development and hyperparameter optimization in machine and deep learning.

Project description

MetaGen: A Framework for Metaheuristic Development and Hyperparameter Optimization

Python Latest Release Documentation

🚀 Why MetaGen?

MetaGen simplifies the development of metaheuristics and the optimization of hyperparameters in machine learning and deep learning. Whether you're a researcher, developer, or practitioner, MetaGen provides a structured, flexible, and scalable framework.

🔹 Key Features

Metaheuristic Development Framework – Simplifies the creation of custom metaheuristics.
Hyperparameter Optimization Tools – Supports both layer and architecture-level tuning in deep learning.
Standardized Interface – Ensures compatibility between metaheuristic developers and end users.
Dynamic Architecture Optimization – Adapts model structures dynamically during execution.
Seamless Integration – Compatible with scikit-learn, tensorflow, pytorch, and other ML libraries.
Built-in Metaheuristics – Pre-implemented algorithms ready to use.
Performance Analysis Tools – Integrated visualization tools for analyzing metaheuristic performance.
Scalable and Distributed Execution – Metaheuristics can run efficiently across multiple nodes.

📌 Built-in Metaheuristics

MetaGen includes a collection of powerful metaheuristics:

  • Random Search
  • Tabu Search
  • Simulated Annealing
  • Tree-Parzen Estimator
  • Memetic Algorithm
  • Genetic Algorithm
  • Steady-State Genetic Algorithm
  • Coronavirus Optimization Algorithm (CVOA)

📦 Installation

MetaGen requires Python 3.10+ and can be installed with:

pip install pymetagen-datalabupo

📖 Documentation

The official API reference and usage guides are available at: MetaGen Documentation

🛠 Example: Developing a Metaheuristic

Creating a simple Random Search metaheuristic:

from copy import deepcopy
from typing import Callable, List
from metagen.framework import Domain, Solution

class RandomSearch:

    def __init__(self, domain: Domain, fitness: Callable[[Solution], float], search_space_size: int = 30,
                iterations: int = 20) -> None:

        self.domain = domain
        self.fitness = fitness
        self.search_space_size = search_space_size
        self.iterations = iterations

    def run(self) -> Solution:

        potential_solutions: List[Solution] = list()

        for _ in range(0, self.search_space_size):
            potential_solutions.append(Solution(self.domain, connector=self.domain.get_connector()))

        solution: Solution = deepcopy(min(potential_solutions))

        for _ in range(0, self.iterations):
            for ps in potential_solutions:
                ps.mutate()

                ps.evaluate(self.fitness)
                if ps < solution:
                    solution = deepcopy(ps)

        return solution

🤖 Example: Hyperparameter Optimization

Optimizing hyperparameters for a regression model:

from metagen.framework import Domain, Solution
from metagen.metaheuristics.rs import RandomSearch
from sklearn.datasets import make_regression
from sklearn.linear_model import SGDRegressor
from sklearn.model_selection import cross_val_score

# Generate synthetic dataset
X, y = make_regression(n_samples=1000, n_features=4)

# Define the search space
regression_domain = Domain()
regression_domain.define_real("alpha", 0.0001, 0.001)
regression_domain.define_integer("iterations", 5, 200)
regression_domain.define_categorical("loss", ["squared_error", "huber", "epsilon_insensitive"])

# Fitness function
def regression_fitness(solution: Solution):
    model = SGDRegressor(
        loss=solution["loss"],
        alpha=solution["alpha"],
        max_iter=solution["iterations"]
    )
    mape = cross_val_score(model, X, y, scoring="neg_mean_absolute_percentage_error").mean() * -1
    return mape

# Run optimization
best_solution = RandomSearch(regression_domain, regression_fitness).run()
print(best_solution)

🤝 Contributing

We welcome contributions from developers of all experience levels! To contribute:

  • Open an issue or submit a pull request.

  • Run tests using:

    pytest test
    

📌 Resources


MetaGen is an open-source project developed and maintained by:

  • David Gutiérrez-Avilés
  • Manuel Jesús Jiménez-Navarro
  • Francisco José Torres-Maldonado
  • Francisco Martínez-Álvarez

All authors are members of DataLabUPO, the Data Science & Big Data Research Lab at Pablo de Olavide University.

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

pymetagen_datalabupo-0.2.0.tar.gz (65.1 kB view details)

Uploaded Source

Built Distribution

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

pymetagen_datalabupo-0.2.0-py3-none-any.whl (103.5 kB view details)

Uploaded Python 3

File details

Details for the file pymetagen_datalabupo-0.2.0.tar.gz.

File metadata

  • Download URL: pymetagen_datalabupo-0.2.0.tar.gz
  • Upload date:
  • Size: 65.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for pymetagen_datalabupo-0.2.0.tar.gz
Algorithm Hash digest
SHA256 42468472037df224510fa8f1ddd96478189eee7e36881459ce538ed13711909b
MD5 721eafb99940e502ba69825c2612a18d
BLAKE2b-256 b356f2604b2b297e277ded8afe07ae7bddc5ce05bd510219fd9d87a8f369a87a

See more details on using hashes here.

File details

Details for the file pymetagen_datalabupo-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pymetagen_datalabupo-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7037f1425d31c95342f2ae8a41c0be7bb43a28ed3bed013c19620d5dde88e360
MD5 baab7872fe7e45a78bc407a90330af73
BLAKE2b-256 9388e30876a47e1b0dc521eb9d53b2c9cf903b9a894f7aa3247d1c2f433bc8db

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