Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
nmichlo committed Sep 25, 2021
2 parents 1025b3c + 7361bee commit 88405a4
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 28 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ name: test

on:
push:
branches: [ main, dev ]
branches: [ 'main', 'dev', 'dev-*' ]
tags: [ '*' ]
pull_request:
branches: [ main, dev ]
branches: [ 'main', 'dev', 'dev-*' ]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest] # [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.8]
python-version: ['3.6', '3.7', '3.8', '3.9']

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ be made to members, instead new members should be created with the modified valu
easily implement efficient multi-threading, see below!

The trainer automatically constructs `HallOfFame` and `LogBook` objects which keep track of your
population and offspring. `EaModule` provides defaults for `get_stats_groups` that can be overridden
if you wish to customize the tracked statistics.
population and offspring. `EaModule` provides defaults for `get_stats_groups` and `get_progress_stats`
that can be overridden if you wish to customize the tracked statistics and statistics displayed by tqdm.


### Minimal OneMax Example
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pip>=21.0
numpy>=1.21.0
tqdm>=4.60.0
numpy>=1.19
tqdm>=4
# ray should be an optional requirement
ray>=1.6.0
4 changes: 4 additions & 0 deletions ruck/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@
from ruck._train import Trainer
from ruck._train import yield_population_steps

from ruck._history import HallOfFame
from ruck._history import Logbook
from ruck._history import StatsGroup

# functional utils
from ruck import functional as R
1 change: 0 additions & 1 deletion ruck/_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ def __iter__(self):
yield self[i]



# ========================================================================= #
# END #
# ========================================================================= #
15 changes: 10 additions & 5 deletions ruck/_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from typing import Sequence
from typing import TypeVar

import numpy as np

from ruck._history import StatsGroup
from ruck._member import Population
from ruck.util._args import HParamsMixin
Expand All @@ -47,12 +49,15 @@ class EaModule(Generic[T], HParamsMixin):
# OVERRIDABLE DEFAULTS

def get_stats_groups(self) -> Dict[str, StatsGroup[T, Any]]:
# additional stats to be recorded
return {}
# default stats groups
return {
'fit': StatsGroup(lambda pop: [m.fitness for m in pop], min=np.min, max=np.max, mean=np.mean)
}

def get_progress_stats(self) -> Sequence[str]:
# which stats are included in the progress bar
return ('evals', 'fit:max',)
# - values added by trainer
return ('evals', 'fit:max')

# REQUIRED

Expand All @@ -62,10 +67,10 @@ def gen_starting_values(self) -> List[T]:
def generate_offspring(self, population: Population[T]) -> Population[T]:
raise NotImplementedError

def select_population(self, population: Population[T], offspring: Population[T]) -> Population[T]:
def evaluate_values(self, values: List[T]) -> List[float]:
raise NotImplementedError

def evaluate_values(self, values: List[T]) -> List[float]:
def select_population(self, population: Population[T], offspring: Population[T]) -> Population[T]:
raise NotImplementedError


Expand Down
15 changes: 2 additions & 13 deletions ruck/_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ def __init__(
def fit(self, module: EaModule[T]) -> Tuple[Population[T], Logbook[T], HallOfFame[T]]:
assert isinstance(module, EaModule)
# history trackers
logbook, halloffame = self._create_default_trackers(module)
logbook = Logbook('gen', 'evals', **module.get_stats_groups())
halloffame = HallOfFame(n_best=self._history_n_best, maximize=True)
# progress bar and training loop
with tqdm(total=self._generations, desc='generation', disable=not self._progress, ncols=120) as p:
for gen, population, offspring, evals in itertools.islice(self._offspring_generator(module), self._generations):
Expand All @@ -143,18 +144,6 @@ def fit(self, module: EaModule[T]) -> Tuple[Population[T], Logbook[T], HallOfFam
# done
return population, logbook, halloffame.freeze()

def _create_default_trackers(self, module: EaModule[T]) -> Tuple[Logbook[T], HallOfFame[T]]:
halloffame = HallOfFame(
n_best=self._history_n_best,
maximize=True,
)
logbook = Logbook(
'gen', 'evals',
fit=StatsGroup(lambda pop: [m.fitness for m in pop], min=np.min, max=np.max, mean=np.mean),
**module.get_stats_groups()
)
return logbook, halloffame


# ========================================================================= #
# END #
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
author="Nathan Juraj Michlo",
author_email="[email protected]",

version="0.0.1.dev1",
python_requires=">=3.8",
version="0.1.0",
python_requires=">=3.6",
packages=setuptools.find_packages(),

install_requires=install_requires,
Expand All @@ -62,7 +62,10 @@
classifiers=[
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Intended Audience :: Science/Research",
],
)
Expand Down
File renamed without changes.

0 comments on commit 88405a4

Please sign in to comment.