Spaces:
Running
Running
Commit
·
0a9f0c4
1
Parent(s):
1858959
Update API calls for SymbolicRegression.jl 0.13
Browse files- pysr/sr.py +48 -36
pysr/sr.py
CHANGED
|
@@ -1518,25 +1518,22 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
| 1518 |
str(self.early_stop_condition) if self.early_stop_condition else None
|
| 1519 |
)
|
| 1520 |
|
| 1521 |
-
mutation_weights =
|
| 1522 |
-
|
| 1523 |
-
|
| 1524 |
-
|
| 1525 |
-
|
| 1526 |
-
|
| 1527 |
-
|
| 1528 |
-
|
| 1529 |
-
|
| 1530 |
-
self.weight_do_nothing,
|
| 1531 |
-
],
|
| 1532 |
-
dtype=float,
|
| 1533 |
)
|
| 1534 |
|
| 1535 |
# Call to Julia backend.
|
| 1536 |
# See https://github.com/MilesCranmer/SymbolicRegression.jl/blob/master/src/OptionsStruct.jl
|
| 1537 |
options = SymbolicRegression.Options(
|
| 1538 |
-
binary_operators=Main.eval(str(
|
| 1539 |
-
unary_operators=Main.eval(str(
|
| 1540 |
bin_constraints=bin_constraints,
|
| 1541 |
una_constraints=una_constraints,
|
| 1542 |
complexity_of_operators=complexity_of_operators,
|
|
@@ -1545,43 +1542,43 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
| 1545 |
nested_constraints=nested_constraints,
|
| 1546 |
loss=custom_loss,
|
| 1547 |
maxsize=int(self.maxsize),
|
| 1548 |
-
|
| 1549 |
npopulations=int(self.populations),
|
| 1550 |
batching=self.batching,
|
| 1551 |
-
|
| 1552 |
-
|
| 1553 |
-
|
| 1554 |
-
|
| 1555 |
# These have the same name:
|
| 1556 |
parsimony=self.parsimony,
|
| 1557 |
alpha=self.alpha,
|
| 1558 |
maxdepth=maxdepth,
|
| 1559 |
fast_cycle=self.fast_cycle,
|
| 1560 |
migration=self.migration,
|
| 1561 |
-
|
| 1562 |
-
|
| 1563 |
-
|
| 1564 |
-
|
| 1565 |
-
|
| 1566 |
-
|
| 1567 |
npop=self.population_size,
|
| 1568 |
-
|
| 1569 |
-
|
| 1570 |
topn=self.topn,
|
| 1571 |
verbosity=self.verbosity,
|
| 1572 |
optimizer_algorithm=self.optimizer_algorithm,
|
| 1573 |
optimizer_nrestarts=self.optimizer_nrestarts,
|
| 1574 |
-
|
| 1575 |
optimizer_iterations=self.optimizer_iterations,
|
| 1576 |
-
|
| 1577 |
annealing=self.annealing,
|
| 1578 |
-
|
| 1579 |
progress=progress,
|
| 1580 |
timeout_in_seconds=self.timeout_in_seconds,
|
| 1581 |
-
|
| 1582 |
skip_mutation_failures=self.skip_mutation_failures,
|
| 1583 |
max_evals=self.max_evals,
|
| 1584 |
-
|
| 1585 |
seed=seed,
|
| 1586 |
deterministic=self.deterministic,
|
| 1587 |
)
|
|
@@ -1603,19 +1600,34 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
| 1603 |
else:
|
| 1604 |
Main.weights = None
|
| 1605 |
|
| 1606 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1607 |
|
| 1608 |
# Call to Julia backend.
|
| 1609 |
# See https://github.com/MilesCranmer/SymbolicRegression.jl/blob/master/src/SymbolicRegression.jl
|
| 1610 |
-
self.raw_julia_state_ =
|
| 1611 |
Main.X,
|
| 1612 |
Main.y,
|
| 1613 |
weights=Main.weights,
|
| 1614 |
niterations=int(self.niterations),
|
| 1615 |
varMap=self.feature_names_in_.tolist(),
|
| 1616 |
options=options,
|
| 1617 |
-
numprocs=
|
| 1618 |
-
multithreading=bool(multithreading),
|
| 1619 |
saved_state=self.raw_julia_state_,
|
| 1620 |
addprocs_function=cluster_manager,
|
| 1621 |
)
|
|
|
|
| 1518 |
str(self.early_stop_condition) if self.early_stop_condition else None
|
| 1519 |
)
|
| 1520 |
|
| 1521 |
+
mutation_weights = SymbolicRegression.MutationWeights(
|
| 1522 |
+
mutate_constant=self.weight_mutate_constant,
|
| 1523 |
+
mutate_operator=self.weight_mutate_operator,
|
| 1524 |
+
add_node=self.weight_add_node,
|
| 1525 |
+
insert_node=self.weight_insert_node,
|
| 1526 |
+
delete_node=self.weight_delete_node,
|
| 1527 |
+
simplify=self.weight_simplify,
|
| 1528 |
+
randomize=self.weight_randomize,
|
| 1529 |
+
do_nothing=self.weight_do_nothing,
|
|
|
|
|
|
|
|
|
|
| 1530 |
)
|
| 1531 |
|
| 1532 |
# Call to Julia backend.
|
| 1533 |
# See https://github.com/MilesCranmer/SymbolicRegression.jl/blob/master/src/OptionsStruct.jl
|
| 1534 |
options = SymbolicRegression.Options(
|
| 1535 |
+
binary_operators=Main.eval(str(binary_operators).replace("'", "")),
|
| 1536 |
+
unary_operators=Main.eval(str(unary_operators).replace("'", "")),
|
| 1537 |
bin_constraints=bin_constraints,
|
| 1538 |
una_constraints=una_constraints,
|
| 1539 |
complexity_of_operators=complexity_of_operators,
|
|
|
|
| 1542 |
nested_constraints=nested_constraints,
|
| 1543 |
loss=custom_loss,
|
| 1544 |
maxsize=int(self.maxsize),
|
| 1545 |
+
output_file=_escape_filename(self.equation_file_),
|
| 1546 |
npopulations=int(self.populations),
|
| 1547 |
batching=self.batching,
|
| 1548 |
+
batch_size=int(min([batch_size, len(X)]) if self.batching else len(X)),
|
| 1549 |
+
mutation_weights=mutation_weights,
|
| 1550 |
+
tournament_selection_p=self.tournament_selection_p,
|
| 1551 |
+
tournament_selection_n=self.tournament_selection_n,
|
| 1552 |
# These have the same name:
|
| 1553 |
parsimony=self.parsimony,
|
| 1554 |
alpha=self.alpha,
|
| 1555 |
maxdepth=maxdepth,
|
| 1556 |
fast_cycle=self.fast_cycle,
|
| 1557 |
migration=self.migration,
|
| 1558 |
+
hof_migration=self.hof_migration,
|
| 1559 |
+
fraction_replaced_hof=self.fraction_replaced_hof,
|
| 1560 |
+
should_optimize_constants=self.should_optimize_constants,
|
| 1561 |
+
warmup_maxsize_by=self.warmup_maxsize_by,
|
| 1562 |
+
use_frequency=self.use_frequency,
|
| 1563 |
+
use_frequency_in_tournament=self.use_frequency_in_tournament,
|
| 1564 |
npop=self.population_size,
|
| 1565 |
+
ncycles_per_iteration=self.ncyclesperiteration,
|
| 1566 |
+
fraction_replaced=self.fraction_replaced,
|
| 1567 |
topn=self.topn,
|
| 1568 |
verbosity=self.verbosity,
|
| 1569 |
optimizer_algorithm=self.optimizer_algorithm,
|
| 1570 |
optimizer_nrestarts=self.optimizer_nrestarts,
|
| 1571 |
+
optimizer_probability=self.optimize_probability,
|
| 1572 |
optimizer_iterations=self.optimizer_iterations,
|
| 1573 |
+
perturbation_factor=self.perturbation_factor,
|
| 1574 |
annealing=self.annealing,
|
| 1575 |
+
return_state=True, # Required for state saving.
|
| 1576 |
progress=progress,
|
| 1577 |
timeout_in_seconds=self.timeout_in_seconds,
|
| 1578 |
+
crossover_probability=self.crossover_probability,
|
| 1579 |
skip_mutation_failures=self.skip_mutation_failures,
|
| 1580 |
max_evals=self.max_evals,
|
| 1581 |
+
early_stop_condition=early_stop_condition,
|
| 1582 |
seed=seed,
|
| 1583 |
deterministic=self.deterministic,
|
| 1584 |
)
|
|
|
|
| 1600 |
else:
|
| 1601 |
Main.weights = None
|
| 1602 |
|
| 1603 |
+
if self.procs == 0 and not multithreading:
|
| 1604 |
+
parallelism = "serial"
|
| 1605 |
+
elif multithreading:
|
| 1606 |
+
parallelism = "multithreading"
|
| 1607 |
+
else:
|
| 1608 |
+
parallelism = "multiprocessing"
|
| 1609 |
+
|
| 1610 |
+
cprocs = (
|
| 1611 |
+
None if parallelism in ["serial", "multithreading"] else int(self.procs)
|
| 1612 |
+
)
|
| 1613 |
+
|
| 1614 |
+
# Can't pass symbol to PyJulia, so need to eval a function:
|
| 1615 |
+
Main.eval(
|
| 1616 |
+
"call_sr(@nospecialize args...; @nospecialize kws...)"
|
| 1617 |
+
" = SymbolicRegression.EquationSearch(args...;"
|
| 1618 |
+
f"parallelism=:{parallelism}, kws...)"
|
| 1619 |
+
)
|
| 1620 |
|
| 1621 |
# Call to Julia backend.
|
| 1622 |
# See https://github.com/MilesCranmer/SymbolicRegression.jl/blob/master/src/SymbolicRegression.jl
|
| 1623 |
+
self.raw_julia_state_ = Main.call_sr(
|
| 1624 |
Main.X,
|
| 1625 |
Main.y,
|
| 1626 |
weights=Main.weights,
|
| 1627 |
niterations=int(self.niterations),
|
| 1628 |
varMap=self.feature_names_in_.tolist(),
|
| 1629 |
options=options,
|
| 1630 |
+
numprocs=cprocs,
|
|
|
|
| 1631 |
saved_state=self.raw_julia_state_,
|
| 1632 |
addprocs_function=cluster_manager,
|
| 1633 |
)
|