Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ dependencies:
- typeguard
- yaml
- pygraphviz
- petsc
- petsc4py
- pip
- pip:
- git+https://github.com/cpml-au/dctkit
Expand Down
24 changes: 15 additions & 9 deletions src/flex/gp/regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class GPSymbolicRegressor(RegressorMixin, BaseEstimator):
- Elitism and overlapping or non-overlapping generations
- Parallel fitness evaluation using Ray
- Validation-set monitoring
- Conversion of the best individual to a SymPy expression
- Conversion of the best individuals to a SymPy expression

Args:
pset_config: set of primitives and terminals (loosely or strongly typed).
Expand Down Expand Up @@ -942,25 +942,31 @@ def __save_train_fit_history(self, output_path: str):
join(output_path, "val_score_history.npy"), self.__val_score_history
)

def get_best_individual_sympy(
def get_best_individuals_sympy(
self,
sympy_conversion_rules: Dict = conversion_rules,
special_term_name: str = "c",
n_ind: int = 1,
):
"""Returns the SymPy expression of the best individual.
"""Returns the SymPy expression of the best individuals.

Args:
sympy_conversion_rules: mapping from GP primitives (DEAP) to SymPy
primitives.
special_term_name: name used for constants during SymPy conversion.
n_ind: number of best individuals to convert to SymPy.

Returns:
sympy representation of the best individual if conversion is enabled.
"""

best_sympy = parse_expr(
stringify_for_sympy(self._best, sympy_conversion_rules, special_term_name)
)
sympy representation of the best individuals.
"""
best_inds = self.get_best_individuals(n_ind=n_ind)
best_sympy = [None] * n_ind
for i in range(n_ind):
best_sympy[i] = parse_expr(
stringify_for_sympy(
best_inds[i], sympy_conversion_rules, special_term_name
)
)
return best_sympy

def get_train_fit_history(self):
Expand Down