Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jbytecode/mccga.py
Machine-coded compact genetic algorithm in Python
https://github.com/jbytecode/mccga.py
Last synced: 22 days ago
JSON representation
Machine-coded compact genetic algorithm in Python
- Host: GitHub
- URL: https://github.com/jbytecode/mccga.py
- Owner: jbytecode
- License: mit
- Created: 2023-09-26T09:44:34.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-01T17:57:59.000Z (about 1 year ago)
- Last Synced: 2024-10-15T16:56:54.129Z (2 months ago)
- Language: Python
- Size: 13.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mccga.py
Machine-coded compact genetic algorithm in Python## In-short
The package implements the Machine-coded compact genetic algorithm defined in
Satman, M. H. & Akadal, E. (2020). Machine Coded Compact Genetic Algorithms for Real Parameter Optimization Problems . Alphanumeric Journal , 8 (1) , 43-58 . DOI: 10.17093/alphanumeric.576919 [Link](https://dergipark.org.tr/en/pub/alphanumeric/issue/55603/576919)
## Usage
Suppose the optimization problem is
$$
\min f(x, y) = \text{abs}(x - 3.14159265) + \text{abs}(y - \exp{1})
$$then the MCCGA searches for the minimum using
```python
def f(xs: list[float]) -> float:
return abs(xs[0] - 3.14159265) + abs(xs[1] - 2.71828)rangemin = [-100.0, -100.0]
rangemax = [100.0, 100.0]
mutrate = 0.001
maxiter = 100000
result = optimizer.mccga(f, rangemin, rangemax, mutrate, maxiter)
```## Other implementations
- Julia (https://github.com/jmejia8/Metaheuristics.jl)
- Rust (https://crates.io/crates/mccga)
- Java (https://github.com/jbytecode/mccga.java)## Calling mccga() from R
Thanks to the `reticulate` package, the Python function `mccga()` can be called into R.
Here is the example:```R
# The package for R & Python integration
library(reticulate)# Loading the mccga library
source_python("optimizer.py")# Defining the objective function
f <- function(xs){
val <- (xs[1] - 3.14159265)^2 + (xs[2] - 2.71828)^2
return(val)
}result <- mccga(f, c(-100, -100), c(100, 100), 0.0001, 100000)
> result
[1] 3.141595 2.718276
```