MHSA - Metaheuristics Similarity Analyzer
This repository contains the source code of the experiments in the paper Measuring the similarity of metaheuristic search strategies with machine learning models. MHSA provides an alternative way to compare and analyze metaheuristic-search strategies with the help of machine learning.
Usage
To use MHSA for similarity analysis we first have to define the gene spaces which will be used by the genetic algorithm. First key of the gene space dictionary must correspond with the class name of the the algorithm which must be implemented in the NiaPy micro-framework. In this case we chose BatAlgorithm and ParticleSwarmAlgorithm.
PSA_gene_spaces = {
"ParticleSwarmAlgorithm": {
"c1": {"low": 0.01, "high": 2.5, "step": 0.01},
"c2": {"low": 0.01, "high": 2.5, "step": 0.01},
"w": {"low": 0.0, "high": 1.0, "step": 0.01},
}
}
BA_gene_spaces = {
"BatAlgorithm": {
"loudness": {"low": 0.01, "high": 1.0, "step": 0.01},
"pulse_rate": {"low": 0.01, "high": 1.0, "step": 0.01},
"alpha": {"low": 0.9, "high": 1.0, "step": 0.001},
"gamma": {"low": 0.0, "high": 1.0, "step": 0.01},
}
}
We also have to chose diversity metrics which will be used as the basis of the analysis and the optimization problem the metaheuristics are going to solve.
from mhsa.diversity_metrics.population_diversity.dpc import DPC
from mhsa.diversity_metrics.population_diversity.fdc import FDC
from mhsa.diversity_metrics.population_diversity.pfsd import PFSD
from mhsa.diversity_metrics.population_diversity.pfm import PFM
from mhsa.diversity_metrics.individual_diversity.idt import IDT
from mhsa.diversity_metrics.individual_diversity.isi import ISI
from mhsa.diversity_metrics.individual_diversity.ifm import IFM
from mhsa.diversity_metrics.individual_diversity.ifiqr import IFIQR
from mhsa.problems.schwefel import Schwefel
OPTIMIZATION_PROBLEM = Schwefel(dimension=20)
POP_DIVERSITY_METRICS = [
DPC(OPTIMIZATION_PROBLEM),
FDC(OPTIMIZATION_PROBLEM, [420.968746], True),
PFSD(),
PFM(),
]
INDIV_DIVERSITY_METRICS = [
IDT(),
ISI(),
IFM(),
IFIQR(),
]
In the next step we have to instantiate the MetaGA class which uses the GA class from the PyGAD library. At this point we decide which of the algorithms will be analyzed and which will be the "reference" or "target" algorithm. The gene space of the analyzed algorithm gets assigned to the gene_spaces argument of the MetaGA.
from mhsa.tools.meta_ga import MetaGA, MetaGAFitnessFunction
meta_ga = MetaGA(
fitness_function_type=MetaGAFitnessFunction.TARGET_PERFORMANCE_SIMILARITY,
ga_generations=20,
ga_solutions_per_pop=15,
ga_percent_parents_mating=60,
ga_parent_selection_type="tournament",
ga_k_tournament=2,
ga_crossover_type="uniform",
ga_mutation_type="random",
ga_crossover_probability=0.9,
ga_mutation_num_genes=1,
ga_keep_elitism=1,
gene_spaces=BA_gene_spaces,
pop_size=30,
max_evals=10000,
num_runs=30,
problem=OPTIMIZATION_PROBLEM,
pop_diversity_metrics=POP_DIVERSITY_METRICS,
indiv_diversity_metrics=INDIV_DIVERSITY_METRICS,
)
In the last step we have to instantiate the MetaheuristicSimilarityAnalyzer class and pass it the configured MetaGA instance and the gene space of the target algorithm. Then we simply call the run_similarity_analysis method to start the analysis.
from mhsa.tools.metaheuristics_similarity_analyzer import MetaheuristicsSimilarityAnalyzer
mhsa = MetaheuristicsSimilarityAnalyzer(meta_ga=meta_ga, target_gene_space=PSA_gene_spaces)
mhsa.run_similarity_analysis(
num_comparisons=10
get_info=True,
generate_dataset=True,
calculate_similarity_metrics=True,
export=True,
)
After the analysis we can choose to export results of the analysis as a .pdf and/or .tex file with export_results_to_latex method or access them trough the MetaheuristicsSimilarityAnalyzer class instance.
mhsa.export_results_to_latex(generate_pdf=True)
For more information check out examples.
This project depends on
NiaPy Python microframework
PyGAD Python library
Metadata
Release files for mhsa 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mhsa-1.1.0.tar.gz | 40.9 kB | Without provenance | Details for mhsa-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mhsa-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for mhsa-1.1.0-py3-none-any.whl |
Total release size: 91.8 kB
Release files / mhsa-1.1.0.tar.gz
| Download URL | mhsa-1.1.0.tar.gz |
|---|---|
| Size | 40.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d411b8c0a43dd5b001b17697be3c4b6f0a182616a07e51d6fb7df1834663df50
|
|
BLAKE2b-256 checksum How to use checksums |
979d1a56bc9eeb8de5501ea46b0c2e9887eb0a293c8118db5c7ae07aa2198016
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.0.dev0 CPython/3.10.18 Linux/6.6.87.2-microsoft-standard-WSL2
|
Release files / mhsa-1.1.0-py3-none-any.whl
| Download URL | mhsa-1.1.0-py3-none-any.whl |
|---|---|
| Size | 50.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9d96d359bc22d38341bcb9e434981493d7ed3d5ef4e06e5c4f71ef4e1943a060
|
|
BLAKE2b-256 checksum How to use checksums |
ddf3f14203559c2a0d1b00bfc5bffead24d7f0649c0963da0ecebd1318acd345
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.0.dev0 CPython/3.10.18 Linux/6.6.87.2-microsoft-standard-WSL2
|
Security for mhsa 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.