Skip to content

Commit

Permalink
docs test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sherstpasha committed Apr 11, 2024
1 parent a8c8440 commit f63a1eb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 40 deletions.
14 changes: 7 additions & 7 deletions src/thefittest/utils/crossovers.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def empty_crossoverGP(
>>>
>>> # Example
>>> X = np.array([[0.3, 0.7], [0.3, 1.1], [3.5, 11.0]], dtype=np.float64)
>>> functional_set_names = ("add", "mul", "neg", "inv")
>>> functional_set_names = ("add", "mul")
>>> max_tree_level = 5
>>>
>>> # Initialize Universal Set for Symbolic Regression
Expand Down Expand Up @@ -605,7 +605,7 @@ def standard_crossover(
>>> # Example
>>>
>>> X = np.array([[0.3, 0.7], [0.3, 1.1], [3.5, 11.0]], dtype=np.float64)
>>> functional_set_names = ("add", "mul", "neg", "inv")
>>> functional_set_names = ("add", "mul")
>>> max_tree_level = 5
>>>
>>> # Initialize Universal Set for Symbolic Regression
Expand Down Expand Up @@ -685,7 +685,7 @@ def one_point_crossoverGP(
>>> # Example
>>>
>>> X = np.array([[0.3, 0.7], [0.3, 1.1], [3.5, 11.0]], dtype=np.float64)
>>> functional_set_names = ("add", "mul", "neg", "inv")
>>> functional_set_names = ("add", "mul")
>>> max_tree_level = 5
>>>
>>> # Initialize Universal Set for Symbolic Regression
Expand Down Expand Up @@ -763,7 +763,7 @@ def uniform_crossoverGP(
>>> # Example
>>>
>>> X = np.array([[0.3, 0.7], [0.3, 1.1], [3.5, 11.0]], dtype=np.float64)
>>> functional_set_names = ("add", "mul", "neg", "inv")
>>> functional_set_names = ("add", "mul")
>>> max_tree_level = 5
>>>
>>> # Initialize Universal Set for Symbolic Regression
Expand Down Expand Up @@ -849,7 +849,7 @@ def uniform_proportional_crossover_GP(
>>> # Example
>>>
>>> X = np.array([[0.3, 0.7], [0.3, 1.1], [3.5, 11.0]], dtype=np.float64)
>>> functional_set_names = ("add", "mul", "neg", "inv")
>>> functional_set_names = ("add", "mul")
>>> max_tree_level = 5
>>>
>>> # Initialize Universal Set for Symbolic Regression
Expand Down Expand Up @@ -936,7 +936,7 @@ def uniform_rank_crossover_GP(
>>> # Example
>>>
>>> X = np.array([[0.3, 0.7], [0.3, 1.1], [3.5, 11.0]], dtype=np.float64)
>>> functional_set_names = ("add", "mul", "neg", "inv")
>>> functional_set_names = ("add", "mul")
>>> max_tree_level = 5
>>>
>>> # Initialize Universal Set for Symbolic Regression
Expand Down Expand Up @@ -1024,7 +1024,7 @@ def uniform_tournament_crossover_GP(
>>> # Example
>>>
>>> X = np.array([[0.3, 0.7], [0.3, 1.1], [3.5, 11.0]], dtype=np.float64)
>>> functional_set_names = ("add", "mul", "neg", "inv")
>>> functional_set_names = ("add", "mul")
>>> max_tree_level = 5
>>>
>>> # Initialize Universal Set for Symbolic Regression
Expand Down
27 changes: 4 additions & 23 deletions src/thefittest/utils/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,6 @@ def current_to_rand_1(
--------
>>> from thefittest.utils.mutations import current_to_rand_1
>>> import numpy as np
>>>
>>> # Example
>>> current_individual = np.array([0.5, 0.3, 0.8], dtype=np.float64)
>>> best_individual = np.array([0.6, 0.4, 0.7], dtype=np.float64)
Expand Down Expand Up @@ -494,7 +493,6 @@ def current_to_pbest_1_archive(
--------
>>> from thefittest.utils.mutations import current_to_pbest_1_archive
>>> import numpy as np
>>>
>>> # Example
>>> current_individual = np.array([0.5, 0.3, 0.8], dtype=np.float64)
>>> population = np.array([[0.2, 0.1, 0.5], [0.8, 0.6, 0.9], [0.3, 0.7, 0.4], [0.9, 0.5, 0.2]], dtype=np.float64)
Expand Down Expand Up @@ -556,7 +554,6 @@ def current_to_pbest_1_archive_p_min(
--------
>>> from thefittest.utils.mutations import current_to_pbest_1_archive_p_min
>>> import numpy as np
>>>
>>> # Example
>>> current_individual = np.array([0.5, 0.3, 0.8], dtype=np.float64)
>>> population = np.array([[0.2, 0.1, 0.5], [0.8, 0.6, 0.9], [0.3, 0.7, 0.4], [0.9, 0.5, 0.2]], dtype=np.float64)
Expand Down Expand Up @@ -615,19 +612,15 @@ def point_mutation(tree: Tree, uniset: UniversalSet, proba: float, max_level: in
>>> from thefittest.base import Tree
>>> from thefittest.base import init_symbolic_regression_uniset
>>> from thefittest.utils.mutations import point_mutation
>>>
>>> # Example Parameters
>>> X = np.array([[0.3, 0.7], [0.3, 1.1], [3.5, 11.0]], dtype=np.float64)
>>> functional_set_names = ("add", "mul", "neg", "inv")
>>> functional_set_names = ("add", "mul")
>>> max_tree_level = 4
>>> mutation_probability = 0.5
>>>
>>> # Initialize Universal Set for Symbolic Regression
>>> universal_set = init_symbolic_regression_uniset(X, functional_set_names)
>>>
>>> # Generate a Random Tree
>>> tree = Tree.random_tree(universal_set, max_tree_level)
>>>
>>> # Perform Point Mutation
>>> mutated_tree = point_mutation(tree, universal_set, mutation_probability, max_tree_level)
>>> print("Original Tree:", tree)
Expand Down Expand Up @@ -680,19 +673,15 @@ def growing_mutation(tree: Tree, uniset: UniversalSet, proba: float, max_level:
>>> from thefittest.base import Tree
>>> from thefittest.base import init_symbolic_regression_uniset
>>> from thefittest.utils.mutations import growing_mutation
>>>
>>> # Example Parameters
>>> X = np.array([[0.3, 0.7], [0.3, 1.1], [3.5, 11.0]], dtype=np.float64)
>>> functional_set_names = ("add", "mul", "neg", "inv")
>>> functional_set_names = ("add", "mul")
>>> max_tree_level = 4
>>> mutation_probability = 0.5
>>>
>>> # Initialize Universal Set for Symbolic Regression
>>> universal_set = init_symbolic_regression_uniset(X, functional_set_names)
>>>
>>> # Generate a Random Tree
>>> tree = Tree.random_tree(universal_set, max_tree_level)
>>>
>>> # Perform Growing Mutation
>>> mutated_tree = growing_mutation(tree, universal_set, mutation_probability, max_tree_level)
>>> print("Original Tree:", tree)
Expand Down Expand Up @@ -739,19 +728,15 @@ def swap_mutation(tree: Tree, uniset: UniversalSet, proba: float, max_leve: int)
>>> from thefittest.base import Tree
>>> from thefittest.base import init_symbolic_regression_uniset
>>> from thefittest.utils.mutations import swap_mutation
>>>
>>> # Example Parameters
>>> X = np.array([[0.3, 0.7], [0.3, 1.1], [3.5, 11.0]], dtype=np.float64)
>>> functional_set_names = ("add", "mul", "neg", "inv")
>>> functional_set_names = ("add", "mul")
>>> max_tree_level = 4
>>> mutation_probability = 0.5
>>>
>>> # Initialize Universal Set for Symbolic Regression
>>> universal_set = init_symbolic_regression_uniset(X, functional_set_names)
>>>
>>> # Generate a Random Tree
>>> tree = Tree.random_tree(universal_set, max_tree_level)
>>>
>>> # Perform Swap Mutation
>>> mutated_tree = swap_mutation(tree, universal_set, mutation_probability, max_tree_level)
>>> print("Original Tree:", tree)
Expand Down Expand Up @@ -806,19 +791,15 @@ def shrink_mutation(tree: Tree, uniset: UniversalSet, proba: float, max_level: i
>>> from thefittest.base import Tree
>>> from thefittest.base import init_symbolic_regression_uniset
>>> from thefittest.utils.mutations import shrink_mutation
>>>
>>> # Example Parameters
>>> X = np.array([[0.3, 0.7], [0.3, 1.1], [3.5, 11.0]], dtype=np.float64)
>>> functional_set_names = ("add", "mul", "neg", "inv")
>>> functional_set_names = ("add", "mul")
>>> max_tree_level = 4
>>> mutation_probability = 0.5
>>>
>>> # Initialize Universal Set for Symbolic Regression
>>> universal_set = init_symbolic_regression_uniset(X, functional_set_names)
>>>
>>> # Generate a Random Tree
>>> tree = Tree.random_tree(universal_set, max_tree_level)
>>>
>>> # Perform Shrink Mutation
>>> mutated_tree = shrink_mutation(tree, universal_set, mutation_probability, max_tree_level)
>>> print("Original Tree:", tree)
Expand Down
16 changes: 7 additions & 9 deletions src/thefittest/utils/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ def sattolo_shuffle(arr):
--------
>>> from numba import jit
>>> import numpy as np
>>>
>>> from thefittest.utils.random import sattolo_shuffle
>>> # Example of using Sattolo's shuffle
>>> arr = np.array([1, 2, 3, 4, 5])
>>> shuffled_arr = sattolo_shuffle(arr)
>>> print("Shuffled Array:", shuffled_arr)
>>> arr = np.array([1, 2, 3, 4, 5], dtype = np.int64)
>>> print("Shuffled Array:", sattolo_shuffle(arr))
Shuffled Array: ...
Notes
Expand Down Expand Up @@ -76,11 +75,10 @@ def sattolo_shuffle_2d(arr):
--------
>>> from numba import jit
>>> import numpy as np
>>>
>>> from thefittest.utils.random import sattolo_shuffle_2d
>>> # Example of using Sattolo's shuffle for a 2D array
>>> arr_2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> shuffled_arr_2d = sattolo_shuffle_2d(arr_2d)
>>> print("Shuffled 2D Array:", shuffled_arr_2d)
>>> print("Shuffled 2D Array:", sattolo_shuffle_2d(arr_2d))
Shuffled 2D Array: ...
Notes
Expand Down Expand Up @@ -349,9 +347,9 @@ def randint(low, high, size):
--------
>>> from numba import jit
>>> import numpy as np
>>>
>>> from thefittest.utils.random import randint
>>> # Example of generating random integers
>>> result = numba_randint(low=1, high=10, size=5)
>>> result = randint(low=1, high=10, size=5)
>>> print("Random Integers:", result)
Random Integers: ...
Expand Down
2 changes: 1 addition & 1 deletion src/thefittest/utils/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def minmax_scale(data: NDArray[Union[np.int64, np.float64]]) -> NDArray[np.float
>>> print("Original Data:", example_data)
Original Data: [ 2 5 10 8 3]
>>> print("Scaled Data:", scaled_data)
Scaled Data: [0. 0.375 1. 0.75 0.125]
Scaled Data: [0. 0.375 1. 0.75 0.125]
"""
data_copy = data.copy()
max_value = data_copy.max()
Expand Down

0 comments on commit f63a1eb

Please sign in to comment.