evograd-diff 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- evograd/__init__.py +67 -0
- evograd/algorithms/__init__.py +138 -0
- evograd/algorithms/cmaes.py +1365 -0
- evograd/algorithms/de.py +895 -0
- evograd/algorithms/ga.py +532 -0
- evograd/algorithms/pso.py +648 -0
- evograd/algorithms/shade.py +1165 -0
- evograd/benchmarks/functions/__init__.py +229 -0
- evograd/benchmarks/functions/base.py +217 -0
- evograd/benchmarks/functions/cec2017/__init__.py +250 -0
- evograd/benchmarks/functions/cec2017/basic.py +413 -0
- evograd/benchmarks/functions/cec2017/composition.py +580 -0
- evograd/benchmarks/functions/cec2017/data.pkl +0 -0
- evograd/benchmarks/functions/cec2017/data.py +350 -0
- evograd/benchmarks/functions/cec2017/hybrid.py +406 -0
- evograd/benchmarks/functions/cec2017/simple.py +326 -0
- evograd/benchmarks/functions/classical.py +649 -0
- evograd/benchmarks/functions/smoothed_funnel.py +476 -0
- evograd/benchmarks/functions/transforms.py +463 -0
- evograd/benchmarks/run_benchmark_functions.py +1208 -0
- evograd/core/__init__.py +73 -0
- evograd/core/algorithm.py +778 -0
- evograd/core/maximize.py +269 -0
- evograd/core/minimize.py +740 -0
- evograd/core/problem.py +444 -0
- evograd/core/result.py +571 -0
- evograd/core/termination.py +602 -0
- evograd/operators/__init__.py +178 -0
- evograd/operators/crossover.py +1117 -0
- evograd/operators/mutation.py +1098 -0
- evograd/operators/relaxations.py +175 -0
- evograd/operators/repair.py +601 -0
- evograd/operators/sampling.py +577 -0
- evograd/operators/selection.py +981 -0
- evograd/operators/survival.py +1000 -0
- evograd/tests/__init__.py +11 -0
- evograd/tests/run_all.py +78 -0
- evograd/tests/test_core.py +528 -0
- evograd/tests/test_ga.py +572 -0
- evograd/tests/test_operators.py +662 -0
- evograd/tests/test_per_individual.py +326 -0
- evograd/tests/test_utils.py +328 -0
- evograd/utils/__init__.py +97 -0
- evograd/utils/callbacks.py +926 -0
- evograd/utils/device.py +502 -0
- evograd/utils/duplicates.py +421 -0
- evograd_diff-0.1.0.dist-info/METADATA +439 -0
- evograd_diff-0.1.0.dist-info/RECORD +50 -0
- evograd_diff-0.1.0.dist-info/WHEEL +4 -0
- evograd_diff-0.1.0.dist-info/licenses/LICENSE +201 -0
evograd/__init__.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""
|
|
2
|
+
EvoGrad: Metaheuristics in a Differentiable Wonderland.
|
|
3
|
+
|
|
4
|
+
EvoGrad is a PyTorch-based framework for differentiable evolutionary
|
|
5
|
+
computation and swarm intelligence. It provides:
|
|
6
|
+
|
|
7
|
+
- **Differentiable Algorithms**: GA, DE, PSO, CMA-ES with gradient flow
|
|
8
|
+
- **Classical Algorithms**: GPU-accelerated versions without backpropagation
|
|
9
|
+
- **Modular Operators**: Pluggable selection, crossover, mutation operators
|
|
10
|
+
- **Flexible API**: pymoo-inspired interface with dependency injection
|
|
11
|
+
|
|
12
|
+
Quick Start
|
|
13
|
+
-----------
|
|
14
|
+
>>> from evograd.core.problem import Problem
|
|
15
|
+
>>> from evograd.core.minimize import minimize
|
|
16
|
+
>>> from evograd.core.termination import MaxEvaluations
|
|
17
|
+
>>> from evograd.algorithms import GA
|
|
18
|
+
>>> from evograd.operators import TournamentSelection, SBX, PolynomialMutation
|
|
19
|
+
>>>
|
|
20
|
+
>>> # Define a problem
|
|
21
|
+
>>> problem = Problem(
|
|
22
|
+
... objective=lambda x: (x ** 2).sum(dim=-1), # Sphere function
|
|
23
|
+
... n_var=10,
|
|
24
|
+
... xl=-5.0,
|
|
25
|
+
... xu=5.0,
|
|
26
|
+
... )
|
|
27
|
+
>>>
|
|
28
|
+
>>> # Create algorithm with custom operators
|
|
29
|
+
>>> algorithm = GA(
|
|
30
|
+
... pop_size=100,
|
|
31
|
+
... selection=TournamentSelection(tournament_size=3),
|
|
32
|
+
... crossover=SBX(eta=15, prob=0.9),
|
|
33
|
+
... mutation=PolynomialMutation(eta=20),
|
|
34
|
+
... adaptive=True, # Enable gradient-based hyperparameter learning
|
|
35
|
+
... differentiable=True, # Enable gradient-based population learning
|
|
36
|
+
... )
|
|
37
|
+
>>>
|
|
38
|
+
>>> # Run optimization
|
|
39
|
+
>>> result = minimize(problem, algorithm, termination=MaxEvaluations(10000), seed=42)
|
|
40
|
+
>>> print(f"Best fitness: {result.best_fitness:.6f}")
|
|
41
|
+
|
|
42
|
+
Architecture
|
|
43
|
+
------------
|
|
44
|
+
evograd/
|
|
45
|
+
├── core/ # Problem, Algorithm base, Result, Termination, minimize/maximize
|
|
46
|
+
├── algorithms/ # GA, DE, PSO, CMA-ES implementations
|
|
47
|
+
├── operators/ # Selection, Crossover, Mutation, Repair
|
|
48
|
+
├── benchmarks/ # Classic functions, CEC2017
|
|
49
|
+
└── utils/ # Device, Callbacks, Duplicates
|
|
50
|
+
|
|
51
|
+
License
|
|
52
|
+
-------
|
|
53
|
+
MIT License - See LICENSE file for details.
|
|
54
|
+
|
|
55
|
+
Authors
|
|
56
|
+
-------
|
|
57
|
+
Andrea Tangherloni <andrea.tangherloni@unibocconi.it>
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
__version__ = "0.1.0"
|
|
61
|
+
__author__ = "Andrea Tangherloni"
|
|
62
|
+
|
|
63
|
+
__all__ = [
|
|
64
|
+
# Version info
|
|
65
|
+
"__version__",
|
|
66
|
+
"__author__",
|
|
67
|
+
]
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""
|
|
2
|
+
EvoGrad Algorithms Module.
|
|
3
|
+
|
|
4
|
+
This module provides implementations of population-based optimisation
|
|
5
|
+
algorithms that leverage the EvoGrad framework for both classical and
|
|
6
|
+
differentiable operation.
|
|
7
|
+
|
|
8
|
+
Available Algorithms:
|
|
9
|
+
- GA: Genetic Algorithm with SBX crossover and polynomial mutation
|
|
10
|
+
- DE: Differential Evolution with multiple mutation strategies
|
|
11
|
+
- SHADE: Success-History based Adaptive DE
|
|
12
|
+
- LSHADE: SHADE with Linear Population Size Reduction
|
|
13
|
+
- PSO: Particle Swarm Optimisation
|
|
14
|
+
- CMAES: Covariance Matrix Adaptation Evolution Strategy
|
|
15
|
+
|
|
16
|
+
All algorithms inherit from the base Algorithm class and follow
|
|
17
|
+
the dependency injection pattern for operators.
|
|
18
|
+
|
|
19
|
+
Example:
|
|
20
|
+
>>> from evograd.algorithms import GA, DE, SHADE, PSO, CMAES
|
|
21
|
+
>>> from evograd.core import Problem, minimize
|
|
22
|
+
>>>
|
|
23
|
+
>>> problem = Problem(
|
|
24
|
+
... objective=lambda x: (x**2).sum(dim=-1),
|
|
25
|
+
... n_var=30,
|
|
26
|
+
... xl=-100.0,
|
|
27
|
+
... xu=100.0,
|
|
28
|
+
... )
|
|
29
|
+
>>>
|
|
30
|
+
>>> # Genetic Algorithm
|
|
31
|
+
>>> ga = GA(pop_size=100, differentiable=True)
|
|
32
|
+
>>> result = minimize(problem, ga, max_evals=10000)
|
|
33
|
+
>>>
|
|
34
|
+
>>> # Differential Evolution
|
|
35
|
+
>>> de = DE(pop_size=100, variant="DE/rand/1/bin", adaptive=True)
|
|
36
|
+
>>> result = minimize(problem, de, max_evals=10000)
|
|
37
|
+
>>>
|
|
38
|
+
>>> # SHADE (Self-Adaptive DE)
|
|
39
|
+
>>> shade = SHADE(pop_size=100, memory_size=100)
|
|
40
|
+
>>> result = minimize(problem, shade, max_evals=10000)
|
|
41
|
+
>>>
|
|
42
|
+
>>> # L-SHADE (SHADE with population reduction)
|
|
43
|
+
>>> lshade = LSHADE(pop_size_init=18*30, pop_size_min=4)
|
|
44
|
+
>>> result = minimize(problem, lshade, max_evals=10000)
|
|
45
|
+
>>>
|
|
46
|
+
>>> # Particle Swarm Optimisation
|
|
47
|
+
>>> pso = PSO(pop_size=100, adaptive=True)
|
|
48
|
+
>>> result = minimize(problem, pso, max_evals=10000)
|
|
49
|
+
>>>
|
|
50
|
+
>>> # CMA-ES
|
|
51
|
+
>>> cmaes = CMAES(pop_size=50, adaptive=True)
|
|
52
|
+
>>> result = minimize(problem, cmaes, max_evals=10000)
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
# Genetic Algorithm
|
|
56
|
+
from evograd.algorithms.ga import (
|
|
57
|
+
GA,
|
|
58
|
+
ga_default,
|
|
59
|
+
ga_steady_state,
|
|
60
|
+
ga_comma)
|
|
61
|
+
|
|
62
|
+
# Differential Evolution
|
|
63
|
+
from .de import (
|
|
64
|
+
DE,
|
|
65
|
+
DEVariant,
|
|
66
|
+
de_default,
|
|
67
|
+
de_rand_1_bin,
|
|
68
|
+
de_best_1_bin,
|
|
69
|
+
de_current_to_best_1_bin,
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
# SHADE and L-SHADE
|
|
73
|
+
from .shade import (
|
|
74
|
+
SHADE,
|
|
75
|
+
LSHADE,
|
|
76
|
+
SHADEMemory,
|
|
77
|
+
shade_default,
|
|
78
|
+
shade_adaptive,
|
|
79
|
+
lshade_default,
|
|
80
|
+
lshade_adaptive,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
# Particle Swarm Optimisation
|
|
84
|
+
from .pso import (
|
|
85
|
+
PSO,
|
|
86
|
+
pso_default,
|
|
87
|
+
pso_constriction)
|
|
88
|
+
|
|
89
|
+
# CMA-ES
|
|
90
|
+
from .cmaes import (
|
|
91
|
+
CMAES,
|
|
92
|
+
cmaes_default,
|
|
93
|
+
cmaes_small,
|
|
94
|
+
cmaes_large,
|
|
95
|
+
cmaes_adaptive,
|
|
96
|
+
cmaes_ipop,
|
|
97
|
+
cmaes_bipop,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
__all__ = [
|
|
102
|
+
# GAs
|
|
103
|
+
"GA",
|
|
104
|
+
"ga_default",
|
|
105
|
+
"ga_steady_state",
|
|
106
|
+
"ga_comma",
|
|
107
|
+
|
|
108
|
+
# DE
|
|
109
|
+
"DE",
|
|
110
|
+
"DEVariant",
|
|
111
|
+
"de_default",
|
|
112
|
+
"de_rand_1_bin",
|
|
113
|
+
"de_best_1_bin",
|
|
114
|
+
"de_current_to_best_1_bin",
|
|
115
|
+
|
|
116
|
+
# SHADE family
|
|
117
|
+
"SHADE",
|
|
118
|
+
"LSHADE",
|
|
119
|
+
"SHADEMemory",
|
|
120
|
+
"shade_default",
|
|
121
|
+
"shade_adaptive",
|
|
122
|
+
"lshade_default",
|
|
123
|
+
"lshade_adaptive",
|
|
124
|
+
|
|
125
|
+
# PSO
|
|
126
|
+
"PSO",
|
|
127
|
+
"pso_default",
|
|
128
|
+
"pso_constriction",
|
|
129
|
+
|
|
130
|
+
# CMA-ES
|
|
131
|
+
"CMAES",
|
|
132
|
+
"cmaes_default",
|
|
133
|
+
"cmaes_small",
|
|
134
|
+
"cmaes_large",
|
|
135
|
+
"cmaes_adaptive",
|
|
136
|
+
"cmaes_ipop",
|
|
137
|
+
"cmaes_bipop",
|
|
138
|
+
]
|