Skip to content

Commit

Permalink
harmonize type hints for Individual and Particle in docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
mcw92 committed Mar 13, 2024
1 parent b51964a commit dc06d53
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 63 deletions.
6 changes: 3 additions & 3 deletions propulate/islands.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,11 @@ def _run(
logging_interval : int
The logging interval.
debug : int
The verbosity/debug level.
The debug level.
Returns
-------
List[List[Individual] | Individual]
List[List[propulate.Individual] | propulate.Individual]
The top-n best individuals on each island.
"""
self.propulator.propulate(logging_interval, debug)
Expand All @@ -333,7 +333,7 @@ def evolve(
Returns
-------
List[List[Individual] | Individual]
List[List[propulate.Individual] | propulate.Individual]
The top-n best individuals on each island.
"""
return self._run(top_n, logging_interval, debug)
32 changes: 16 additions & 16 deletions propulate/propagators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ def __call__(self, inds: List[Individual]) -> Union[List[Individual], Individual
Parameters
----------
inds : List[propulate.individual.Individual]
inds : List[propulate.Individual]
The input individuals the propagator is applied to.
Returns
-------
List[Individual] | Individual
List[propulate.Individual] | propulate.Individual
The individual(s) bred by applying the propagator.
While this abstract base class method actually returns ``None``, each concrete child class of ``Propagator``
should return an ``Individual`` instance or a list of them.
Expand Down Expand Up @@ -182,7 +182,7 @@ def __init__(
offspring: int = -1,
) -> None:
"""
Initialize the conditional propagator.
Initialize a conditional propagator.
Parameters
----------
Expand All @@ -208,12 +208,12 @@ def __call__(self, inds: List[Individual]) -> List[Individual]:
Parameters
----------
inds : List[propulate.individual.Individual]
inds : List[propulate.Individual]
The input individuals the propagator is applied to.
Returns
-------
List[propulate.individual.Individual]
List[propulate.Individual]
The output individuals returned by the conditional propagator.
"""
if (
Expand Down Expand Up @@ -283,12 +283,12 @@ def __call__(self, inds: List[Individual]) -> List[Individual]:
Parameters
----------
inds : List[propulate.individual.Individual]
inds : List[propulate.Individual]
The input individuals the propagator is applied to.
Returns
-------
List[propulate.individual.Individual]
List[propulate.Individual]
The output individuals after application of the propagator.
"""
for p in self.propagators:
Expand Down Expand Up @@ -329,12 +329,12 @@ def __call__(self, inds: List[Individual]) -> List[Individual]:
Parameters
----------
inds : List[propulate.individual.Individual]
inds : List[propulate.Individual]
The input individuals the propagator is applied to.
Returns
-------
List[propulate.individual.Individual]
List[propulate.Individual]
The selected output individuals after application of the propagator.
Raises
Expand Down Expand Up @@ -385,12 +385,12 @@ def __call__(self, inds: List[Individual]) -> List[Individual]:
Parameters
----------
inds : List[propulate.individual.Individual]
inds : List[propulate.Individual]
The individuals the propagator is applied to.
Returns
-------
List[propulate.individual.Individual]
List[propulate.Individual]
The selected individuals after application of the propagator.
Raises
Expand Down Expand Up @@ -423,7 +423,7 @@ class SelectUniform(Propagator):

def __init__(self, offspring: int, rng: Optional[random.Random] = None) -> None:
"""
Initialize random-selection propagator.
Initialize a random-selection propagator.
Parameters
----------
Expand All @@ -440,12 +440,12 @@ def __call__(self, inds: List[Individual]) -> List[Individual]:
Parameters
----------
inds : List[propulate.individual.Individual]
inds : List[propulate.Individual]
The individuals the propagator is applied to.
Returns
-------
List[propulate.individual.Individual]
List[propulate.Individual]
The selected individuals after application of the propagator.
Raises
Expand Down Expand Up @@ -515,12 +515,12 @@ def __call__(self, *inds: Individual) -> Individual:
Parameters
----------
inds : propulate.individual.Individual
inds : propulate.Individual
The individuals the propagator is applied to.
Returns
-------
propulate.individual.Individual
propulate.Individual
The output individual after application of the propagator.
Raises
Expand Down
16 changes: 8 additions & 8 deletions propulate/propagators/cmaes.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,16 @@ def update_mean(self, new_mean: np.ndarray) -> None:
self.old_mean = self.mean
self.mean = new_mean

def update_covariance_matrix(self, new_co_matrix: np.ndarray) -> None:
def update_covariance_matrix(self, new_covariance_matrix: np.ndarray) -> None:
"""
Setter for the covariance matrix.
Update the covariance matrix.
Computes new values for ``b_matrix``, ``d_matrix``, and ``covariance_inv_sqrt``. Decomposition of
``covariance_matrix`` is O(n^3), hence the possibility of lazy updating ``b_matrix`` and ``d_matrix``.
Parameters
----------
new_co_matrix : numpy.ndarray
new_covariance_matrix : numpy.ndarray
The new covariance matrix.
"""
# Update b and d matrix and covariance_inv_sqrt only after certain number of evaluations to ensure 0(n^2).
Expand All @@ -219,7 +219,7 @@ def update_covariance_matrix(self, new_co_matrix: np.ndarray) -> None:
> self.lambd / (self.c_1 + self.c_mu) / self.problem_dimension / 10
):
self.eigen_eval = self.count_eval
self._decompose_co_matrix(new_co_matrix)
self._decompose_co_matrix(new_covariance_matrix)
self.covariance_inv_sqrt = (
self.b_matrix @ np.diag(self.d_matrix ** (-1)) @ self.b_matrix.T
)
Expand Down Expand Up @@ -802,12 +802,12 @@ def __call__(self, inds: List[Individual]) -> Individual:
Parameters
----------
inds: List[Individual]
inds: List[propulate.Individual]
Available individuals.
Returns
-------
new_ind : Individual
new_ind : propulate.Individual
The newly sampled individual.
"""
num_inds = len(inds)
Expand Down Expand Up @@ -845,7 +845,7 @@ def _transform_individuals_to_matrix(self, inds: List[Individual]) -> np.ndarray
Parameters
----------
inds : list[Individual]
inds : list[propulate.Individual]
The list of individuals.
Returns
Expand All @@ -865,7 +865,7 @@ def _sample_cma(self) -> Individual:
Returns
-------
new_ind : Individual
new_ind : propulate.Individual
The newly sampled individual.
"""
# Generate new offspring
Expand Down
24 changes: 12 additions & 12 deletions propulate/propagators/ga.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ def __call__(self, ind: Individual) -> Individual:
Parameters
----------
ind : propulate.individual.Individual
ind : propulate.Individual
The individual the propagator is applied to.
Returns
-------
propulate.individual.Individual
propulate.Individual
The possibly point-mutated individual after application of the propagator.
"""
if (
Expand Down Expand Up @@ -184,12 +184,12 @@ def __call__(self, ind: Individual) -> Individual:
Parameters
----------
ind : propulate.population.Individual
ind : propulate.Individual
The individual the propagator is applied to.
Returns
-------
propulate.population.Individual
propulate.Individual
The possibly point-mutated individual after application of the propagator.
"""
if (
Expand Down Expand Up @@ -288,12 +288,12 @@ def __call__(self, ind: Individual) -> Individual:
Parameters
----------
ind : propulate.individual.Individual
ind : propulate.Individual
The input individual the propagator is applied to.
Returns
-------
propulate.individual.Individual
propulate.Individual
The possibly interval-mutated output individual after application of the propagator.
"""
if (
Expand Down Expand Up @@ -377,12 +377,12 @@ def __call__(self, inds: List[Individual]) -> Individual:
Parameters
----------
inds : List[propulate.individual.Individual]
inds : List[propulate.Individual]
The individuals the propagator is applied to.
Returns
-------
propulate.individual.Individual
propulate.Individual
The possibly cross-bred individual after application of the propagator.
"""
ind = copy.deepcopy(inds[0]) # Consider 1st parent.
Expand Down Expand Up @@ -438,12 +438,12 @@ def __call__(self, inds: List[Individual]) -> Individual:
Parameters
----------
inds : list[propulate.individual.Individual]
inds : list[propulate.Individual]
The individuals the propagator is applied to.
Returns
-------
propulate.individual.Individual
propulate.Individual
The possibly cross-bred individual after application of propagator
"""
ind = copy.deepcopy(inds[0]) # Consider 1st parent.
Expand Down Expand Up @@ -507,12 +507,12 @@ def __call__(self, inds: List[Individual]) -> Individual:
Parameters
----------
inds : List[propulate.individual.Individual]
inds : List[propulate.Individual]
The individuals the propagator is applied to.
Returns
-------
propulate.individual.Individual
propulate.Individual
The possibly cross-bred individual after application of the propagator.
"""
ind = copy.deepcopy(inds[0]) # Consider 1st parent.
Expand Down
Loading

0 comments on commit dc06d53

Please sign in to comment.