Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ohjeah committed Aug 27, 2018
1 parent 386f53c commit 27c3490
Show file tree
Hide file tree
Showing 15 changed files with 237 additions and 223 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: python
cache:
directories:
- $HOME/.cache/pip
- .hypothesis
- tests/.hypothesis
python:
- "3.6"
install:
Expand Down
1 change: 1 addition & 0 deletions cartesian/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
pass

from .sklearn_api import Symbolic
from .cgp import Primitive, Symbol, Structural, Constant, Ephemeral
28 changes: 6 additions & 22 deletions cartesian/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np
from sklearn.utils.validation import check_random_state
from scipy.optimize import OptimizeResult, minimize

# from joblib import Parallel, delayed

from .cgp import point_mutation, compile, to_polish, Constant
Expand All @@ -26,15 +27,7 @@ def return_opt_result(f, individual):


def oneplus(
fun,
random_state=None,
cls=None,
lambda_=4,
max_iter=100,
max_nfev=None,
f_tol=0,
n_jobs=1,
seed=None,
fun, random_state=None, cls=None, lambda_=4, max_iter=100, max_nfev=None, f_tol=0, n_jobs=1, seed=None
):
"""1 + lambda algorithm.
Expand All @@ -61,28 +54,19 @@ def oneplus(
best = seed or cls.create(random_state=random_state)
best_res = return_opt_result(fun, best)
nfev = best_res.nfev
res = OptimizeResult(
expr=best, x=best_res.x, fun=best_res.fun, nit=0, nfev=nfev, success=False
)
res = OptimizeResult(expr=best, x=best_res.x, fun=best_res.fun, nit=0, nfev=nfev, success=False)
if best_res.fun <= f_tol:
res["success"] = True
return res

for i in range(1, max_iter):
offspring = [
point_mutation(best, random_state=random_state) for _ in range(lambda_)
]
offspring = [point_mutation(best, random_state=random_state) for _ in range(lambda_)]
# with Parallel(n_jobs=n_jobs) as parallel:
# offspring_fitness = parallel(delayed(return_opt_result)(fun, o) for o in offspring)
offspring_fitness = [return_opt_result(fun, o) for o in offspring]
best, best_res = min(
zip(offspring + [best], offspring_fitness + [best_res]),
key=lambda x: x[1].fun,
)
best, best_res = min(zip(offspring + [best], offspring_fitness + [best_res]), key=lambda x: x[1].fun)
nfev += sum(of.nfev for of in offspring_fitness)
res = OptimizeResult(
expr=best, x=best_res.x, fun=best_res.fun, nit=i, nfev=nfev, success=False
)
res = OptimizeResult(expr=best, x=best_res.x, fun=best_res.fun, nit=i, nfev=nfev, success=False)
if res.fun <= f_tol:
res["success"] = True
return res
Expand Down
Loading

0 comments on commit 27c3490

Please sign in to comment.