code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def get_symbolic_result (pareto_df, Feynman_pb, i_pareto = -1):
"""
Produces an SRBench style dictionary characterizing the best expression found.
Parameters
----------
pareto_df : pd.DataFrame
Pareto front dataframe generated by PhySO.
Feynman_pb : physo.benchmark.FeynmanDataset.Feynman... |
Produces an SRBench style dictionary characterizing the best expression found.
Parameters
----------
pareto_df : pd.DataFrame
Pareto front dataframe generated by PhySO.
Feynman_pb : physo.benchmark.FeynmanDataset.FeynmanProblem.FeynmanProblem
Related Feynman problem.
i_pareto : ... | get_symbolic_result | python | WassimTenachi/PhySO | benchmarking/FeynmanBenchmark/feynman_results_analysis.py | https://github.com/WassimTenachi/PhySO/blob/master/benchmarking/FeynmanBenchmark/feynman_results_analysis.py | MIT |
def load_run_data (pb_folder_prefix):
"""
Safely loads pareto front .csv and curves data .csv into dataframes if possible return None otherwise.
Also returns noise level encoded into folder name.
Parameters
----------
pb_folder_prefix : str or path
Starting name of folder containing run ... |
Safely loads pareto front .csv and curves data .csv into dataframes if possible return None otherwise.
Also returns noise level encoded into folder name.
Parameters
----------
pb_folder_prefix : str or path
Starting name of folder containing run data (there should only be one folder startin... | load_run_data | python | WassimTenachi/PhySO | benchmarking/FeynmanBenchmark/feynman_results_analysis.py | https://github.com/WassimTenachi/PhySO/blob/master/benchmarking/FeynmanBenchmark/feynman_results_analysis.py | MIT |
def load_class_equations_csv (filepath_eqs ="ClassEquations.csv"):
"""
Loads ClassEquations.csv into a pd.DataFrame.
Parameters
----------
filepath_eqs : str
Path to ClassEquations.csv.
Returns
-------
eqs_class_df : pd.DataFrame
"""
eqs_class_df = pd.read_csv(filepath_e... |
Loads ClassEquations.csv into a pd.DataFrame.
Parameters
----------
filepath_eqs : str
Path to ClassEquations.csv.
Returns
-------
eqs_class_df : pd.DataFrame
| load_class_equations_csv | python | WassimTenachi/PhySO | physo/benchmark/ClassDataset/ClassProblem.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/ClassDataset/ClassProblem.py | MIT |
def get_units (i_eq, i_var = 0, output_var = False):
"""
Gets units of variable.
Parameters
----------
i_eq : int
Equation number in the set of equations.
i_var : int
Variable id in its equation line.
output_var : bool
If True, returns units of output variable, otherw... |
Gets units of variable.
Parameters
----------
i_eq : int
Equation number in the set of equations.
i_var : int
Variable id in its equation line.
output_var : bool
If True, returns units of output variable, otherwise returns units of input variable specified by i_var.
... | get_units | python | WassimTenachi/PhySO | physo/benchmark/ClassDataset/ClassProblem.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/ClassDataset/ClassProblem.py | MIT |
def __init__(self, i_eq = None, eq_name = None, original_var_names = False):
"""
Loads a Class problem based on its number in the set or its equation name.
Parameters
----------
i_eq : int
Equation number in the set of equations.
eq_name : str
Equa... |
Loads a Class problem based on its number in the set or its equation name.
Parameters
----------
i_eq : int
Equation number in the set of equations.
eq_name : str
Equation name in the set of equations (e.g. 'Harmonic Oscillator').
original_var_nam... | __init__ | python | WassimTenachi/PhySO | physo/benchmark/ClassDataset/ClassProblem.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/ClassDataset/ClassProblem.py | MIT |
def target_function(self, X, K):
"""
Evaluates X with target function, using K values.
Parameters
----------
X : numpy.array of shape (n_vars, ?,) of floats
Input variables.
K : numpy.array of shape (n_spe,) of floats
Spe free consts.
Retur... |
Evaluates X with target function, using K values.
Parameters
----------
X : numpy.array of shape (n_vars, ?,) of floats
Input variables.
K : numpy.array of shape (n_spe,) of floats
Spe free consts.
Returns
-------
y : numpy.array o... | target_function | python | WassimTenachi/PhySO | physo/benchmark/ClassDataset/ClassProblem.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/ClassDataset/ClassProblem.py | MIT |
def generate_data_points (self, n_samples = 1_000, n_realizations = 10, return_K = False):
"""
Generates data points accordingly for this Class problem.
Parameters
----------
n_samples : int
Number of samples to draw. By default, 1e3.
n_realizations : int
... |
Generates data points accordingly for this Class problem.
Parameters
----------
n_samples : int
Number of samples to draw. By default, 1e3.
n_realizations : int
Number of realizations to draw. By default, 10.
return_K : bool
If True, r... | generate_data_points | python | WassimTenachi/PhySO | physo/benchmark/ClassDataset/ClassProblem.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/ClassDataset/ClassProblem.py | MIT |
def get_sympy(self, K_vals=None):
"""
Gets sympy expression of the formula evaluated with spe free consts.
Parameters
----------
K_vals : numpy.array of shape (?, n_spe,) of floats or None
Values to evaluate spe free consts with, if None, uses random values and return... |
Gets sympy expression of the formula evaluated with spe free consts.
Parameters
----------
K_vals : numpy.array of shape (?, n_spe,) of floats or None
Values to evaluate spe free consts with, if None, uses random values and returns only one realization.
Returns
... | get_sympy | python | WassimTenachi/PhySO | physo/benchmark/ClassDataset/ClassProblem.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/ClassDataset/ClassProblem.py | MIT |
def get_units (var_name):
"""
Gets units of variable var_name. Example: get_units("kb")
Parameters
----------
var_name : str
original variable name.
Returns
-------
units : numpy.array of shape (FEYN_UNITS_VECTOR_SIZE,) of floats
Units of variable.
"""
assert not ... |
Gets units of variable var_name. Example: get_units("kb")
Parameters
----------
var_name : str
original variable name.
Returns
-------
units : numpy.array of shape (FEYN_UNITS_VECTOR_SIZE,) of floats
Units of variable.
| get_units | python | WassimTenachi/PhySO | physo/benchmark/FeynmanDataset/FeynmanProblem.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/FeynmanDataset/FeynmanProblem.py | MIT |
def __init__(self, i_eq = None, eq_name = None, original_var_names = False):
"""
Loads a Feynman problem based on its number in the set or its equation name
Parameters
----------
i_eq : int
Equation number in the whole set of equations (0 to 99 for bulk eqs and 100 to... |
Loads a Feynman problem based on its number in the set or its equation name
Parameters
----------
i_eq : int
Equation number in the whole set of equations (0 to 99 for bulk eqs and 100 to 119 for bonus eqs).
eq_name : str
Equation name in the set of equat... | __init__ | python | WassimTenachi/PhySO | physo/benchmark/FeynmanDataset/FeynmanProblem.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/FeynmanDataset/FeynmanProblem.py | MIT |
def target_function(self, X):
"""
Evaluates X with target function.
Parameters
----------
X : numpy.array of shape (n_vars, ?,) of floats
Returns
-------
y : numpy.array of shape (?,) of floats
"""
# Getting sympy function
f = sympy... |
Evaluates X with target function.
Parameters
----------
X : numpy.array of shape (n_vars, ?,) of floats
Returns
-------
y : numpy.array of shape (?,) of floats
| target_function | python | WassimTenachi/PhySO | physo/benchmark/FeynmanDataset/FeynmanProblem.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/FeynmanDataset/FeynmanProblem.py | MIT |
def compare_expression (self, trial_expr,
handle_trigo = True,
prevent_zero_frac = True,
prevent_inf_equivalence = True,
round_decimal = 2,
verbose=False... |
Checks if trial_expr is symbolically equivalent to the target expression of this Feynman problem, following a
similar methodology as SRBench (see https://github.com/cavalab/srbench).
I.e, it is deemed equivalent if:
- the symbolic difference simplifies to 0
- OR the symb... | compare_expression | python | WassimTenachi/PhySO | physo/benchmark/FeynmanDataset/FeynmanProblem.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/FeynmanDataset/FeynmanProblem.py | MIT |
def trial_function (self, trial_expr, X):
"""
Evaluates X on a trial expression mapping X to input variables names in sympy.
Parameters
----------
trial_expr : Sympy Expression
Trial sympy expression with evaluated numeric free constants and assumptions regarding vari... |
Evaluates X on a trial expression mapping X to input variables names in sympy.
Parameters
----------
trial_expr : Sympy Expression
Trial sympy expression with evaluated numeric free constants and assumptions regarding variables
(positivity etc.) encoded in expres... | trial_function | python | WassimTenachi/PhySO | physo/benchmark/FeynmanDataset/FeynmanProblem.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/FeynmanDataset/FeynmanProblem.py | MIT |
def read_pareto_csv (pareto_csv_path, sympy_X_symbols_dict = None, return_df = False):
"""
Loads a Pareto front csv generated by PhySO into sympy expressions with evaluated free constants.
Only works for expressions not using dataset spe free constants (ie. Class SR tasks), in those cases, pkl loading
i... |
Loads a Pareto front csv generated by PhySO into sympy expressions with evaluated free constants.
Only works for expressions not using dataset spe free constants (ie. Class SR tasks), in those cases, pkl loading
is recommended instead (physo.read_pareto_pkl).
Parameters
----------
pareto_csv_pa... | read_pareto_csv | python | WassimTenachi/PhySO | physo/benchmark/utils/read_logs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/utils/read_logs.py | MIT |
def get_pareto_expressions_from_df (pareto_df, sympy_X_symbols_dict = None):
"""
Loads a Pareto front dataframe generated by PhySO into sympy expressions with evaluated free constants.
Only works for expressions not using dataset spe free constants (ie. Class SR tasks).
Parameters
----------
par... |
Loads a Pareto front dataframe generated by PhySO into sympy expressions with evaluated free constants.
Only works for expressions not using dataset spe free constants (ie. Class SR tasks).
Parameters
----------
pareto_df : pd.DataFrame
Pareto front dataframe generated by PhySO.
sympy_X... | get_pareto_expressions_from_df | python | WassimTenachi/PhySO | physo/benchmark/utils/read_logs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/utils/read_logs.py | MIT |
def replace_sin_by_cos (expr):
"""
Replaces sin(...) by cos(pi/2 - ...) in a sympy expression.
Parameters
----------
expr : Sympy Expression
Returns
-------
ex1 : Sympy Expression
"""
ex1 = expr
# If sin(...) is encountered, replacing it by cos(pi/2 - ...)
for a in sympy.... |
Replaces sin(...) by cos(pi/2 - ...) in a sympy expression.
Parameters
----------
expr : Sympy Expression
Returns
-------
ex1 : Sympy Expression
| replace_sin_by_cos | python | WassimTenachi/PhySO | physo/benchmark/utils/symbolic_utils.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/utils/symbolic_utils.py | MIT |
def replace_cos_by_sin (expr):
"""
Replaces cos(...) by sin(pi/2 - ...) in a sympy expression.
Parameters
----------
expr : Sympy Expression
Returns
-------
ex1 : Sympy Expression
"""
ex1 = expr
# If cos(...) is encountered, replacing it by sin(pi/2 - ...)
for a in sympy.... |
Replaces cos(...) by sin(pi/2 - ...) in a sympy expression.
Parameters
----------
expr : Sympy Expression
Returns
-------
ex1 : Sympy Expression
| replace_cos_by_sin | python | WassimTenachi/PhySO | physo/benchmark/utils/symbolic_utils.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/utils/symbolic_utils.py | MIT |
def round_floats(expr, round_decimal = 2):
"""
Rounds the floats in a sympy expression as in SRBench (see https://github.com/cavalab/srbench).
Parameters
----------
expr : Sympy Expression
round_decimal : int
Rounding up to this decimal.
Use round_decimal = 2 for SRBench-like beh... |
Rounds the floats in a sympy expression as in SRBench (see https://github.com/cavalab/srbench).
Parameters
----------
expr : Sympy Expression
round_decimal : int
Rounding up to this decimal.
Use round_decimal = 2 for SRBench-like behavior (as they actually round up to 2 decimals).
... | round_floats | python | WassimTenachi/PhySO | physo/benchmark/utils/symbolic_utils.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/utils/symbolic_utils.py | MIT |
def clean_sympy_expr(expr, round_decimal = 2):
"""
Cleans (rounds floats, simplifies) sympy expression for symbolic comparison purposes as in SRBench
(see https://github.com/cavalab/srbench).
Parameters
----------
expr : Sympy Expression
round_decimal : int
Rounding up to this decima... |
Cleans (rounds floats, simplifies) sympy expression for symbolic comparison purposes as in SRBench
(see https://github.com/cavalab/srbench).
Parameters
----------
expr : Sympy Expression
round_decimal : int
Rounding up to this decimal.
Use round_decimal = 2 for SRBench-like beha... | clean_sympy_expr | python | WassimTenachi/PhySO | physo/benchmark/utils/symbolic_utils.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/utils/symbolic_utils.py | MIT |
def compare_expression (trial_expr,
target_expr,
handle_trigo = True,
prevent_zero_frac = True,
prevent_inf_equivalence = True,
round_decimal = 2,
verbose=Fals... |
Checks if trial_expr is symbolically equivalent to target_expr, following a similar methodology as
SRBench (see https://github.com/cavalab/srbench).
I.e, it is deemed equivalent if:
- the symbolic difference simplifies to 0
- OR the symbolic difference is a constant
- OR the symboli... | compare_expression | python | WassimTenachi/PhySO | physo/benchmark/utils/symbolic_utils.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/utils/symbolic_utils.py | MIT |
def expression_size(expr):
"""
Evaluates complexity as in SRBench
(see https://github.com/cavalab/srbench).
Parameters
----------
expr : Sympy Expression
Returns
-------
c : int
"""
c=0
for arg in sympy.preorder_traversal(expr):
c += 1
return c |
Evaluates complexity as in SRBench
(see https://github.com/cavalab/srbench).
Parameters
----------
expr : Sympy Expression
Returns
-------
c : int
| expression_size | python | WassimTenachi/PhySO | physo/benchmark/utils/symbolic_utils.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/utils/symbolic_utils.py | MIT |
def sympy_to_prefix(sympy_expr):
"""
Converts a sympy expression to prefix notation.
Parameters
----------
sympy_expr : sympy.core
Sympy expression
Returns
-------
dict :
tokens_str : numpy.array of str
List of tokens in the expression.
arities : numpy... |
Converts a sympy expression to prefix notation.
Parameters
----------
sympy_expr : sympy.core
Sympy expression
Returns
-------
dict :
tokens_str : numpy.array of str
List of tokens in the expression.
arities : numpy.array of int
List of aritie... | sympy_to_prefix | python | WassimTenachi/PhySO | physo/benchmark/utils/symbolic_utils.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/utils/symbolic_utils.py | MIT |
def sympy_symbol_with_assumptions_from_range(name, low, high):
"""
Returns a sympy symbol with assumptions from its data range.
Parameters
----------
name : str
Name of the variable.
low : float
Lowest value taken by the variable.
high : float
Highest value taken by t... |
Returns a sympy symbol with assumptions from its data range.
Parameters
----------
name : str
Name of the variable.
low : float
Lowest value taken by the variable.
high : float
Highest value taken by the variable.
Returns
-------
sympy.Symbol
| sympy_symbol_with_assumptions_from_range | python | WassimTenachi/PhySO | physo/benchmark/utils/symbolic_utils.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/utils/symbolic_utils.py | MIT |
def timeout(seconds=10, error_message=os.strerror(errno.ETIME)):
"""
# Works on UNIX only
# https://stackoverflow.com/questions/2281850/timeout-function-if-it-takes-too-long-to-finish
Demo:
@timeout(20)
def myfunc(n):
time.sleep(n)
return True
myfunc(n>20) will be killed
... |
# Works on UNIX only
# https://stackoverflow.com/questions/2281850/timeout-function-if-it-takes-too-long-to-finish
Demo:
@timeout(20)
def myfunc(n):
time.sleep(n)
return True
myfunc(n>20) will be killed
| timeout | python | WassimTenachi/PhySO | physo/benchmark/utils/timeout_unix.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/benchmark/utils/timeout_unix.py | MIT |
def loss_func(logits_train, ideal_probs_train, R_train, baseline, lengths, gamma_decay, entropy_weight, ):
"""
Loss function for reinforcing symbolic programs.
Parameters
----------
logits_train : torch.tensor of shape (max_time_step, n_train, n_choices,)
Probabilities generated by the... |
Loss function for reinforcing symbolic programs.
Parameters
----------
logits_train : torch.tensor of shape (max_time_step, n_train, n_choices,)
Probabilities generated by the rnn (for each step along program length, for each program in training sub-batch,
for each choosable token... | loss_func | python | WassimTenachi/PhySO | physo/learn/loss.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/learn/loss.py | MIT |
def save_pareto_pkl (pareto_progs, fpath):
"""
Save pareto programs to pickle file.
Parameters
----------
pareto_progs : list of Program.Program
List of pareto programs.
fpath : str
Path to pkl file.
"""
with open(fpath, 'wb') as f:
pickle.dump(pareto_progs, f)
... |
Save pareto programs to pickle file.
Parameters
----------
pareto_progs : list of Program.Program
List of pareto programs.
fpath : str
Path to pkl file.
| save_pareto_pkl | python | WassimTenachi/PhySO | physo/learn/monitoring.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/learn/monitoring.py | MIT |
def read_pareto_pkl (fpath):
"""
Load pareto programs from pickle file.
Parameters
----------
fpath : str
Path to pkl file.
Returns
-------
pareto_progs : list of Program.Program
List of pareto programs.
"""
with open(fpath, 'rb') as f:
pareto_progs = pick... |
Load pareto programs from pickle file.
Parameters
----------
fpath : str
Path to pkl file.
Returns
-------
pareto_progs : list of Program.Program
List of pareto programs.
| read_pareto_pkl | python | WassimTenachi/PhySO | physo/learn/monitoring.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/learn/monitoring.py | MIT |
def __init__(self,
library_args,
priors_config,
multi_X,
multi_y,
rewards_computer,
batch_size,
max_time_step,
multi_y_weights = 1.,
free_const_opti_args = None,
... |
Parameters
----------
library_args: dict
Arguments passed to library.__init__
priors_config : list of couples (str : dict)
List of priors. List containing couples with prior name as first item in couple (see prior.PRIORS_DICT for list
of available pri... | __init__ | python | WassimTenachi/PhySO | physo/physym/batch.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/batch.py | MIT |
def get_sibling_one_hot (self, step = None):
"""
Get siblings one hot of tokens at step. 0 one hot vectors for dummies.
Parameters
----------
step : int
Step of token from which sibling one hot should be returned.
By default, step = current step
Re... |
Get siblings one hot of tokens at step. 0 one hot vectors for dummies.
Parameters
----------
step : int
Step of token from which sibling one hot should be returned.
By default, step = current step
Returns
-------
one_hot : numpy.array of s... | get_sibling_one_hot | python | WassimTenachi/PhySO | physo/physym/batch.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/batch.py | MIT |
def get_parent_one_hot (self, step = None):
"""
Get parents one hot of tokens at step.
Parameters
----------
step : int
Step of token from which parent one hot should be returned.
By default, step = current step
Returns
-------
one_... |
Get parents one hot of tokens at step.
Parameters
----------
step : int
Step of token from which parent one hot should be returned.
By default, step = current step
Returns
-------
one_hot : numpy.array of shape (batch_size, n_choices) of i... | get_parent_one_hot | python | WassimTenachi/PhySO | physo/physym/batch.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/batch.py | MIT |
def get_previous_tokens_one_hot(self):
"""
Get previous step tokens as one hot.
Returns
-------
one_hot : numpy.array of shape (batch_size, n_choices) of int
One hot.
"""
# Return 0 if 0th step
if self.programs.curr_step == 0:
one_h... |
Get previous step tokens as one hot.
Returns
-------
one_hot : numpy.array of shape (batch_size, n_choices) of int
One hot.
| get_previous_tokens_one_hot | python | WassimTenachi/PhySO | physo/physym/batch.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/batch.py | MIT |
def get_sibling_units_obs (self, step = None):
"""
Get (required) units of sibling of tokens at step. Filling using INTERFACE_UNITS_UNAVAILABLE_FILLER where units
are not available. Adding a vector in addition to the units indicating if units are available or not (equal to
INTERFACE_UNIT... |
Get (required) units of sibling of tokens at step. Filling using INTERFACE_UNITS_UNAVAILABLE_FILLER where units
are not available. Adding a vector in addition to the units indicating if units are available or not (equal to
INTERFACE_UNITS_AVAILABLE where units are available and equal to INTERFA... | get_sibling_units_obs | python | WassimTenachi/PhySO | physo/physym/batch.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/batch.py | MIT |
def get_parent_units_obs (self, step = None):
"""
Get (required) units of parent of tokens at step. Filling using INTERFACE_UNITS_UNAVAILABLE_FILLER where units
are not available. Adding a vector in addition to the units indicating if units are available or not (equal to
INTERFACE_UNITS_... |
Get (required) units of parent of tokens at step. Filling using INTERFACE_UNITS_UNAVAILABLE_FILLER where units
are not available. Adding a vector in addition to the units indicating if units are available or not (equal to
INTERFACE_UNITS_AVAILABLE where units are available and equal to INTERFAC... | get_parent_units_obs | python | WassimTenachi/PhySO | physo/physym/batch.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/batch.py | MIT |
def get_previous_tokens_units_obs (self, step = None):
"""
Get (required) units of tokens before step. Filling using INTERFACE_UNITS_UNAVAILABLE_FILLER where units are not
available. Adding a vector in addition to the units indicating if units are available or not (equal to
INTERFACE_UNI... |
Get (required) units of tokens before step. Filling using INTERFACE_UNITS_UNAVAILABLE_FILLER where units are not
available. Adding a vector in addition to the units indicating if units are available or not (equal to
INTERFACE_UNITS_AVAILABLE where units are available and equal to INTERFACE_UNIT... | get_previous_tokens_units_obs | python | WassimTenachi/PhySO | physo/physym/batch.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/batch.py | MIT |
def get_tokens_units_obs (self, step = None):
"""
Get (required) units of tokens at step. Filling using INTERFACE_UNITS_UNAVAILABLE_FILLER where units are not
available. Adding a vector in addition to the units indicating if units are available or not (equal to
INTERFACE_UNITS_AVAILABLE ... |
Get (required) units of tokens at step. Filling using INTERFACE_UNITS_UNAVAILABLE_FILLER where units are not
available. Adding a vector in addition to the units indicating if units are available or not (equal to
INTERFACE_UNITS_AVAILABLE where units are available and equal to INTERFACE_UNITS_UN... | get_tokens_units_obs | python | WassimTenachi/PhySO | physo/physym/batch.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/batch.py | MIT |
def get_obs(self):
"""
Computes observation of current step for symbolic regression task.
Returns
-------
obs : numpy.array of shape (batch_size, 3*n_choices+1,) of float
"""
# Relatives one-hots
parent_one_hot = self.get_parent_one_hot() ... |
Computes observation of current step for symbolic regression task.
Returns
-------
obs : numpy.array of shape (batch_size, 3*n_choices+1,) of float
| get_obs | python | WassimTenachi/PhySO | physo/physym/batch.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/batch.py | MIT |
def get_rewards (self):
"""
Computes rewards of programs contained in batch.
Returns
-------
rewards : numpy.array of shape (batch_size,) of float
Rewards of programs.
"""
rewards = self.rewards_computer(programs = self.programs,
... |
Computes rewards of programs contained in batch.
Returns
-------
rewards : numpy.array of shape (batch_size,) of float
Rewards of programs.
| get_rewards | python | WassimTenachi/PhySO | physo/physym/batch.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/batch.py | MIT |
def ParallelExeAvailability(verbose=False):
"""
Checks if parallel run is available on this system and produces a recommended config.
Parameters
----------
verbose : bool
Prints log.
Returns
-------
recommended_config : dict
bool recommended_config[parallel_mode] : will p... |
Checks if parallel run is available on this system and produces a recommended config.
Parameters
----------
verbose : bool
Prints log.
Returns
-------
recommended_config : dict
bool recommended_config[parallel_mode] : will parallel mode work on this system ?
int rec... | ParallelExeAvailability | python | WassimTenachi/PhySO | physo/physym/batch_execute.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/batch_execute.py | MIT |
def BatchExecution (progs, X,
# Realization related
i_realization = 0,
n_samples_per_dataset = None,
# Mask
mask = None,
pad_with = np.NaN,
# Parallel mode related
... |
Executes prog(X) for each prog in progs and returns the results.
NB: Parallel execution is typically slower because of communication time (parallel_mode = False is recommended).
Parallel mode causes inter-process communication errors on some systems (probably due to the large number of
information to p... | BatchExecution | python | WassimTenachi/PhySO | physo/physym/batch_execute.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/batch_execute.py | MIT |
def BatchExecutionReduceGather (progs, X, reduce_wrapper,
# Realization related
i_realization = 0,
n_samples_per_dataset = None,
# Mask
mask = None,... |
Executes prog(X) for each prog in progs and gathers reduce_wrapper(prog(X)) as a result.
NB: Parallel execution is typically slower because of communication time (even just gathering a float).
Parameters
----------
progs : vect_programs.VectPrograms
Programs in the batch.
X : torch.tens... | BatchExecutionReduceGather | python | WassimTenachi/PhySO | physo/physym/batch_execute.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/batch_execute.py | MIT |
def BatchExecutionReward (progs, X, y_target, reward_function, y_weights = 1.,
# Realization related
i_realization = 0,
n_samples_per_dataset = None,
# Mask
mask = None,
... |
Executes prog(X) for each prog in progs and gathers reward_function(y_target, prog(X), y_weights) as a result.
NB: Parallel execution is typically slower because of communication time (even just gathering a float).
Parameters
----------
progs : vect_programs.VectPrograms
Programs in the bat... | BatchExecutionReward | python | WassimTenachi/PhySO | physo/physym/batch_execute.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/batch_execute.py | MIT |
def BatchFreeConstOpti (progs, X, y_target, free_const_opti_args=None, y_weights = 1.,
# Realization related
i_realization = 0,
n_samples_per_dataset = None,
# Mask
mask = None,
... |
Optimizes the free constants of each program in progs.
NB: Parallel execution is typically faster.
Parameters
----------
progs : vect_programs.VectPrograms
Programs in the batch.
X : torch.tensor of shape (n_dim, n_samples,) of float
Values of the input variables of the problem ... | BatchFreeConstOpti | python | WassimTenachi/PhySO | physo/physym/batch_execute.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/batch_execute.py | MIT |
def inspect_Xy (X, y):
"""
Runs assertions and analyzes shape of a single dataset corresponding to a single realization.
Converts to torch if necessary.
Parameters
----------
X : torch.tensor of shape (n_dim, data_size,) of float
Values of the input variables of the problem with n_dim = ... |
Runs assertions and analyzes shape of a single dataset corresponding to a single realization.
Converts to torch if necessary.
Parameters
----------
X : torch.tensor of shape (n_dim, data_size,) of float
Values of the input variables of the problem with n_dim = nb of input variables, and dat... | inspect_Xy | python | WassimTenachi/PhySO | physo/physym/dataset.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/dataset.py | MIT |
def inspect_multi_y_weights (multi_y_weights, multi_y):
"""
Runs assertions and analyzes shape of multi_y_weights.
Converts to torch if necessary.
Parameters
----------
multi_y_weights : list of len (n_realizations,) of torch.tensor of shape (?,) of float
or array_like of (n_... |
Runs assertions and analyzes shape of multi_y_weights.
Converts to torch if necessary.
Parameters
----------
multi_y_weights : list of len (n_realizations,) of torch.tensor of shape (?,) of float
or array_like of (n_realizations,) of float
or float, optional
... | inspect_multi_y_weights | python | WassimTenachi/PhySO | physo/physym/dataset.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/dataset.py | MIT |
def __init__(self, multi_X, multi_y, multi_y_weights=1., library=None):
"""
Parameters
----------
multi_X : list of len (n_realizations,) of torch.tensor of shape (n_dim, ?,) of float
List of X (one per realization). With X being values of the input variables of the problem w... |
Parameters
----------
multi_X : list of len (n_realizations,) of torch.tensor of shape (n_dim, ?,) of float
List of X (one per realization). With X being values of the input variables of the problem with n_dim = nb
of input variables.
multi_y : list of len (n_re... | __init__ | python | WassimTenachi/PhySO | physo/physym/dataset.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/dataset.py | MIT |
def assign_required_units_at_step (programs, step = None, from_scratch = False):
"""
Usage: computes units that will be used to update units of dummy representing next token to guess
Must be able to work with coords instead of step to work so it can be used on next token to guess dummies and not -
void ... |
Usage: computes units that will be used to update units of dummy representing next token to guess
Must be able to work with coords instead of step to work so it can be used on next token to guess dummies and not -
void tokens.
Parameters
----------
programs : vect_programs.VectPrograms
... | assign_required_units_at_step | python | WassimTenachi/PhySO | physo/physym/dimensional_analysis.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/dimensional_analysis.py | MIT |
def assign_required_units(programs, coords,):
"""
Computes and assigns physical units requirements to tokens at coords, works with complete or incomplete programs
(containing dummies).
In certain cases, a bottom-up physical units computation and assignment is performed on whole subtrees of
programs ... |
Computes and assigns physical units requirements to tokens at coords, works with complete or incomplete programs
(containing dummies).
In certain cases, a bottom-up physical units computation and assignment is performed on whole subtrees of
programs as it is necessary to compute the units constraints o... | assign_required_units | python | WassimTenachi/PhySO | physo/physym/dimensional_analysis.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/dimensional_analysis.py | MIT |
def assign_units_bottom_up (programs, coords_start, coords_end):
"""
Performs a bottom up (in the tree representation of programs) dimensional analysis and assigns units along the way
for multiple subtrees.
Parameters
----------
programs : vect_programs.VectPrograms
Programs on which bot... |
Performs a bottom up (in the tree representation of programs) dimensional analysis and assigns units along the way
for multiple subtrees.
Parameters
----------
programs : vect_programs.VectPrograms
Programs on which bottom up units assignment should be performed.
coords_start : numpy.ar... | assign_units_bottom_up | python | WassimTenachi/PhySO | physo/physym/dimensional_analysis.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/dimensional_analysis.py | MIT |
def ExecuteProgram (input_var_data, program_tokens, class_free_consts_vals=None, spe_free_consts_vals=None):
"""
Executes a symbolic function program.
Parameters
----------
input_var_data : torch.tensor of shape (n_dim, ?,) of float
Values of the input variables of the problem with n_dim = n... |
Executes a symbolic function program.
Parameters
----------
input_var_data : torch.tensor of shape (n_dim, ?,) of float
Values of the input variables of the problem with n_dim = nb of input variables.
program_tokens : list of token.Token
Symbolic function program in reverse Polish n... | ExecuteProgram | python | WassimTenachi/PhySO | physo/physym/execute.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/execute.py | MIT |
def ComputeInfixNotation (program_tokens):
"""
Computes infix str representation of a program.
(which is the usual way to note symbolic function: +34 (in polish notation) = 3+4 (in infix notation))
Parameters
----------
program_tokens : list of token.Token
List of tokens making up the pr... |
Computes infix str representation of a program.
(which is the usual way to note symbolic function: +34 (in polish notation) = 3+4 (in infix notation))
Parameters
----------
program_tokens : list of token.Token
List of tokens making up the program.
Returns
-------
program_str : s... | ComputeInfixNotation | python | WassimTenachi/PhySO | physo/physym/execute.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/execute.py | MIT |
def __init__(self, batch_size, library, n_realizations=1):
""""
Parameters
----------
batch_size : int
Number of programs in batch.
library : library.Library
Library of tokens that can appear in programs.
n_realizations : int
Number of ... | "
Parameters
----------
batch_size : int
Number of programs in batch.
library : library.Library
Library of tokens that can appear in programs.
n_realizations : int
Number of realizations for each program, ie. number of datasets each program has... | __init__ | python | WassimTenachi/PhySO | physo/physym/free_const.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/free_const.py | MIT |
def reset_class_values (self):
"""
Reset class free constants values to initial values.
"""
init_val = self.library.class_free_constants_init_val # (n_class_free_const,) of float
# Free constants values for each program as torch tensor for fast computation... |
Reset class free constants values to initial values.
| reset_class_values | python | WassimTenachi/PhySO | physo/physym/free_const.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/free_const.py | MIT |
def reset_spe_values (self):
"""
Reset spe free constants values to initial values.
"""
# Check and pad init_val if necessary to match n_realizations (for single float init val)
self.library.check_and_pad_spe_free_const_init_val (self.n_realizations)
init_val = self.libra... |
Reset spe free constants values to initial values.
| reset_spe_values | python | WassimTenachi/PhySO | physo/physym/free_const.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/free_const.py | MIT |
def detach (self):
"""
Detach values from computation graph and copies is_opti and opti_steps to detach them from higher level table
if there is one.
"""
self.class_values = self.class_values.clone().detach()
self.spe_values = self.spe_values .clone().detach()
... |
Detach values from computation graph and copies is_opti and opti_steps to detach them from higher level table
if there is one.
| detach | python | WassimTenachi/PhySO | physo/physym/free_const.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/free_const.py | MIT |
def get_const_of_prog (self, prog_idx):
"""
Return a FreeConstantsTable object with values for a single program (batch_size=1).
"""
res = FreeConstantsTable (batch_size=1, library=self.library, n_realizations=self.n_realizations)
# Returning arrays of (1,...) to have a reference ... |
Return a FreeConstantsTable object with values for a single program (batch_size=1).
| get_const_of_prog | python | WassimTenachi/PhySO | physo/physym/free_const.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/free_const.py | MIT |
def flatten_like_data (self, n_samples_per_dataset):
"""
Flattens free constants values to match flattened datasets.
This is useful for computing together class free consts and spe free consts and all datasets at the same time
during a single program execution.
Parameters
... |
Flattens free constants values to match flattened datasets.
This is useful for computing together class free consts and spe free consts and all datasets at the same time
during a single program execution.
Parameters
----------
n_samples_per_dataset : array_like of shape ... | flatten_like_data | python | WassimTenachi/PhySO | physo/physym/free_const.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/free_const.py | MIT |
def df (self):
"""
Return a pandas dataframe with free constants values.
Returns
-------
df : pandas.DataFrame
Dataframe with free constants values of shape (batch_size, n_class_free_const + n_spe_free_const*n_realizations).
"""
# Class free const df
... |
Return a pandas dataframe with free constants values.
Returns
-------
df : pandas.DataFrame
Dataframe with free constants values of shape (batch_size, n_class_free_const + n_spe_free_const*n_realizations).
| df | python | WassimTenachi/PhySO | physo/physym/free_const.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/free_const.py | MIT |
def MSE_loss (func, params, y_target, y_weights = 1.):
"""
Loss for free constant optimization.
Parameters
----------
func : callable
Function which's constants should be optimized taking params as argument.
params : list of torch.tensor
Free constants to optimize.
y_target :... |
Loss for free constant optimization.
Parameters
----------
func : callable
Function which's constants should be optimized taking params as argument.
params : list of torch.tensor
Free constants to optimize.
y_target : torch.tensor of shape (?,)
Target output of function.... | MSE_loss | python | WassimTenachi/PhySO | physo/physym/free_const.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/free_const.py | MIT |
def LBFGS_optimizer (params, f, n_steps=10, tol=1e-6, lbfgs_func_args={}):
"""
Params optimizer (wrapper around torch.optim.LBFGS).
See: https://pytorch.org/docs/stable/generated/torch.optim.LBFGS.html
Parameters
----------
params : list of torch.tensor
Free constants to optimize.
f ... |
Params optimizer (wrapper around torch.optim.LBFGS).
See: https://pytorch.org/docs/stable/generated/torch.optim.LBFGS.html
Parameters
----------
params : list of torch.tensor
Free constants to optimize.
f : callable
Function to minimize, taking params as argument.
n_steps : ... | LBFGS_optimizer | python | WassimTenachi/PhySO | physo/physym/free_const.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/free_const.py | MIT |
def optimize_free_const (func,
params,
y_target,
y_weights = 1.,
loss = "MSE",
method = "LBFGS",
method_args = None):
"""
Optimizes free constants p... |
Optimizes free constants params so that func output matches y_target.
Parameters
----------
func : callable
Function which's constants should be optimized taking params as argument.
params : list of torch.tensor
Free constants to optimize.
y_target : torch.tensor of shape (?,)
... | optimize_free_const | python | WassimTenachi/PhySO | physo/physym/free_const.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/free_const.py | MIT |
def __init__(self, custom_tokens = None, args_make_tokens = None, superparent_units = None, superparent_name = "y"):
"""
Defines choosable tokens in the library.
Parameters
----------
args_make_tokens : dict or None
If not None, arguments are passed to tokenize.make_t... |
Defines choosable tokens in the library.
Parameters
----------
args_make_tokens : dict or None
If not None, arguments are passed to tokenize.make_tokens and tokens are added to the library.
custom_tokens : list of token.Token or None
If not None, the toke... | __init__ | python | WassimTenachi/PhySO | physo/physym/library.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/library.py | MIT |
def check_and_pad_spe_free_const_init_val (self, n_realizations):
"""
Asserts that the sizes of free constants init values for each realization are consistent with the number of
realizations (n_realizations) and makes the necessary padding to ensure a shape of (n_realizations,) (for
sing... |
Asserts that the sizes of free constants init values for each realization are consistent with the number of
realizations (n_realizations) and makes the necessary padding to ensure a shape of (n_realizations,) (for
single float initial values).
Parameters
----------
n_rea... | check_and_pad_spe_free_const_init_val | python | WassimTenachi/PhySO | physo/physym/library.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/library.py | MIT |
def assert_units(self):
"""
Checks if all terminal tokens (arity = 0) have units constraints ie if units constraints can be computed.
Tokens in library come from various units assignments processes (from make_tokens : operation definition in
functions.py, input_var_units dict, constants_... |
Checks if all terminal tokens (arity = 0) have units constraints ie if units constraints can be computed.
Tokens in library come from various units assignments processes (from make_tokens : operation definition in
functions.py, input_var_units dict, constants_units dict ; from custom tokens ; s... | assert_units | python | WassimTenachi/PhySO | physo/physym/library.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/library.py | MIT |
def __init__(self, library, programs):
"""
Parameters
----------
library : library.Library
Library of choosable tokens.
programs : vect_programs.VectPrograms
Programs in the batch.
"""
self.lib = library
self.progs = progr... |
Parameters
----------
library : library.Library
Library of choosable tokens.
programs : vect_programs.VectPrograms
Programs in the batch.
| __init__ | python | WassimTenachi/PhySO | physo/physym/prior.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/prior.py | MIT |
def __init__(self, library, programs):
"""
Parameters
----------
library : library.Library
programs : vect_programs.VectPrograms
"""
Prior.__init__(self, library, programs)
# Number of tokens per arity
# Sum of tokens having arity = idx on choosabl... |
Parameters
----------
library : library.Library
programs : vect_programs.VectPrograms
| __init__ | python | WassimTenachi/PhySO | physo/physym/prior.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/prior.py | MIT |
def __init__(self, library, programs, min_length, max_length):
"""
Parameters
----------
library : library.Library
programs : vect_programs.VectPrograms
min_length : float
Minimum length that programs are allowed to have.
max_length : float
... |
Parameters
----------
library : library.Library
programs : vect_programs.VectPrograms
min_length : float
Minimum length that programs are allowed to have.
max_length : float
Maximum length that programs are allowed to have.
| __init__ | python | WassimTenachi/PhySO | physo/physym/prior.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/prior.py | MIT |
def __init__(self, library, programs, effectors, relationship, targets, max_nb_violations = None):
"""
Enforcing that [targets] cannot be the [relationship] of [effectors].
Parameters
----------
library : library.Library
programs : vect_programs.VectPrograms
effec... |
Enforcing that [targets] cannot be the [relationship] of [effectors].
Parameters
----------
library : library.Library
programs : vect_programs.VectPrograms
effectors : list of str
List of effector tokens' name.
relationship : str
Relations... | __init__ | python | WassimTenachi/PhySO | physo/physym/prior.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/prior.py | MIT |
def __init__(self, library, programs,):
"""
Enforcing functions are not child of their inverse function.
Parameters
----------
library : library.Library
programs : vect_programs.VectPrograms
"""
Prior.__init__(self, library, programs)
# Considerin... |
Enforcing functions are not child of their inverse function.
Parameters
----------
library : library.Library
programs : vect_programs.VectPrograms
| __init__ | python | WassimTenachi/PhySO | physo/physym/prior.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/prior.py | MIT |
def __init__(self, library, programs, functions, max_nesting = 1):
"""
Enforcing that [functions] can not be nested or only up to max_nesting level.
Parameters
----------
library : library.Library
programs : vect_programs.VectPrograms
functions : list of str
... |
Enforcing that [functions] can not be nested or only up to max_nesting level.
Parameters
----------
library : library.Library
programs : vect_programs.VectPrograms
functions : list of str
List of tokens' names which's nesting will be forbidden.
max_ne... | __init__ | python | WassimTenachi/PhySO | physo/physym/prior.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/prior.py | MIT |
def __init__(self, library, programs, max_nesting = 1):
"""
Enforcing that trigonometric functions can not be nested or only up to max_nesting level.
Parameters
----------
library : library.Library
programs : vect_programs.VectPrograms
max_nesting : int
... |
Enforcing that trigonometric functions can not be nested or only up to max_nesting level.
Parameters
----------
library : library.Library
programs : vect_programs.VectPrograms
max_nesting : int
Max level of nesting allowed. By default = 1, no nesting allowed.... | __init__ | python | WassimTenachi/PhySO | physo/physym/prior.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/prior.py | MIT |
def __init__(self, library, programs, targets, max):
"""
Parameters
----------
library : library.Library
programs : vect_programs.VectPrograms
targets : list of str
List of tokens' names which's number of occurrences should be constrained.
max : list o... |
Parameters
----------
library : library.Library
programs : vect_programs.VectPrograms
targets : list of str
List of tokens' names which's number of occurrences should be constrained.
max : list of int
List of maximum occurrences of tokens (must ha... | __init__ | python | WassimTenachi/PhySO | physo/physym/prior.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/prior.py | MIT |
def __init__(self, library, programs, expression):
"""
Parameters
----------
library : library.Library
programs : vect_programs.VectPrograms
expression : list of str
List of tokens to enforce. expression may contain library.invalid.name (ie. Tok.INVALID_TOKEN_... |
Parameters
----------
library : library.Library
programs : vect_programs.VectPrograms
expression : list of str
List of tokens to enforce. expression may contain library.invalid.name (ie. Tok.INVALID_TOKEN_NAME) in which
case all tokens are allowed. All to... | __init__ | python | WassimTenachi/PhySO | physo/physym/prior.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/prior.py | MIT |
def __init__(self, library, programs, prob_eps = 0.):
"""
Parameters
----------
library : library.Library
programs : vect_programs.VectPrograms
prob_eps : float
Value to return for the prior inplace of zeros (useful for avoiding sampling problems)
"""
... |
Parameters
----------
library : library.Library
programs : vect_programs.VectPrograms
prob_eps : float
Value to return for the prior inplace of zeros (useful for avoiding sampling problems)
| __init__ | python | WassimTenachi/PhySO | physo/physym/prior.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/prior.py | MIT |
def make_PriorCollection (library, programs, priors_config,):
"""
Makes PriorCollection object from arguments.
Parameters
----------
library : library.Library
Library of choosable tokens.
programs : vect_programs.VectPrograms
Programs in the batch.
priors_config : list of cou... |
Makes PriorCollection object from arguments.
Parameters
----------
library : library.Library
Library of choosable tokens.
programs : vect_programs.VectPrograms
Programs in the batch.
priors_config : list of couples (str : dict)
List of priors. List containing couples wit... | make_PriorCollection | python | WassimTenachi/PhySO | physo/physym/prior.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/prior.py | MIT |
def __init__(self, library, programs,):
"""
Parameters
----------
library : library.Library
Library of choosable tokens.
programs : vect_programs.VectPrograms
Programs in the batch.
"""
self.priors = []
self.lib = library
... |
Parameters
----------
library : library.Library
Library of choosable tokens.
programs : vect_programs.VectPrograms
Programs in the batch.
| __init__ | python | WassimTenachi/PhySO | physo/physym/prior.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/prior.py | MIT |
def __call__(self):
"""
Returns probabilities of priors for each choosable token in the library.
Returns
-------
mask_probabilities : numpy.array of shape (self.progs.batch_size, self.lib.n_choices) of float
"""
res = self.init_prob
for prior in self.prior... |
Returns probabilities of priors for each choosable token in the library.
Returns
-------
mask_probabilities : numpy.array of shape (self.progs.batch_size, self.lib.n_choices) of float
| __call__ | python | WassimTenachi/PhySO | physo/physym/prior.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/prior.py | MIT |
def __init__(self, programs, prog_idx=0, pos=0):
"""
See class documentation.
Parameters
----------
programs : vect_programs.VectPrograms
prog_idx : int
pos : int
"""
self.programs = programs
self.prog_idx = prog_idx
self.pos =... |
See class documentation.
Parameters
----------
programs : vect_programs.VectPrograms
prog_idx : int
pos : int
| __init__ | python | WassimTenachi/PhySO | physo/physym/program.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/program.py | MIT |
def child(self, i_child = 0):
"""
See class documentation.
Parameters
----------
i_child : int
Returns
-------
self : program.Cursor
"""
has_relative = self.programs.tokens.has_children_mask[tuple(self.coords)][0]
if not has_rel... |
See class documentation.
Parameters
----------
i_child : int
Returns
-------
self : program.Cursor
| child | python | WassimTenachi/PhySO | physo/physym/program.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/program.py | MIT |
def sibling(self, i_sibling = 0):
"""
See class documentation.
Parameters
----------
i_sibling : int
Returns
-------
self : program.Cursor
"""
has_relative = self.programs.tokens.has_siblings_mask[tuple(self.coords)][0]
if not has_r... |
See class documentation.
Parameters
----------
i_sibling : int
Returns
-------
self : program.Cursor
| sibling | python | WassimTenachi/PhySO | physo/physym/program.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/program.py | MIT |
def parent(self,):
"""
See class documentation.
Returns
-------
self : program.Cursor
"""
has_relative = self.programs.tokens.has_parent_mask[tuple(self.coords)][0]
if not has_relative:
err_msg = "Unable to navigate to parent, Token %s at pos =... |
See class documentation.
Returns
-------
self : program.Cursor
| parent | python | WassimTenachi/PhySO | physo/physym/program.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/program.py | MIT |
def __init__(self, tokens, library, free_consts = None, is_physical = None, candidate_wrapper = None, n_realizations=1):
"""
Parameters
----------
See attributes help for details.
"""
# Asserting that tokens make up a full tree representation, no more, no less
tot... |
Parameters
----------
See attributes help for details.
| __init__ | python | WassimTenachi/PhySO | physo/physym/program.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/program.py | MIT |
def execute_wo_wrapper(self, X, i_realization = 0, n_samples_per_dataset = None):
"""
Executes program on X.
Parameters
----------
X : torch.tensor of shape (n_dim, ?,) of float
Values of the input variables of the problem with n_dim = nb of input variables, ? = numbe... |
Executes program on X.
Parameters
----------
X : torch.tensor of shape (n_dim, ?,) of float
Values of the input variables of the problem with n_dim = nb of input variables, ? = number of samples.
i_realization : int, optional
Index of realization to use f... | execute_wo_wrapper | python | WassimTenachi/PhySO | physo/physym/program.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/program.py | MIT |
def optimize_constants(self, X, y_target, y_weights = 1., i_realization = 0, n_samples_per_dataset = None, args_opti = None, freeze_class_free_consts = False):
"""
Optimizes free constants of program.
Parameters
----------
X : torch.tensor of shape (n_dim, ?,) of float
... |
Optimizes free constants of program.
Parameters
----------
X : torch.tensor of shape (n_dim, ?,) of float
Values of the input variables of the problem with n_dim = nb of input variables, ? = number of samples.
y_target : torch.tensor of shape (?,) of float
... | optimize_constants | python | WassimTenachi/PhySO | physo/physym/program.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/program.py | MIT |
def make_skeleton (self):
"""
Strips program to its bare minimum light pickable version for eg. parallel execution purposes.
"""
# Exporting without library so it is lighter to pickle
self.library = None
self.free_consts.library = None
return None |
Strips program to its bare minimum light pickable version for eg. parallel execution purposes.
| make_skeleton | python | WassimTenachi/PhySO | physo/physym/program.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/program.py | MIT |
def get_sympy_local_dicts (self, replace_nan_with = 1.):
"""
Returns a list of local dicts for each realization of the program to replace free constants by their values in
sympy symbolic representation of the program.
Parameters
----------
replace_nan_with : float, option... |
Returns a list of local dicts for each realization of the program to replace free constants by their values in
sympy symbolic representation of the program.
Parameters
----------
replace_nan_with : float, optional
Value to replace NaNs with in free constants values.
... | get_sympy_local_dicts | python | WassimTenachi/PhySO | physo/physym/program.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/program.py | MIT |
def get_infix_sympy (self, do_simplify = False, evaluate_consts = False, replace_nan_with = 1.):
"""
Returns sympy symbolic representation of a program.
Parameters
----------
do_simplify : bool, optional
If True performs a symbolic simplification of program.
e... |
Returns sympy symbolic representation of a program.
Parameters
----------
do_simplify : bool, optional
If True performs a symbolic simplification of program.
evaluate_consts : bool, optional
If True replaces free constants by their values in the sympy sym... | get_infix_sympy | python | WassimTenachi/PhySO | physo/physym/program.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/program.py | MIT |
def get_infix_pretty (self, do_simplify = False):
"""
Returns a printable ASCII sympy.pretty representation of a program.
Parameters
----------
do_simplify : bool
If True performs a symbolic simplification of program.
Returns
-------
program_pr... |
Returns a printable ASCII sympy.pretty representation of a program.
Parameters
----------
do_simplify : bool
If True performs a symbolic simplification of program.
Returns
-------
program_pretty_str : str
| get_infix_pretty | python | WassimTenachi/PhySO | physo/physym/program.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/program.py | MIT |
def get_infix_latex (self,replace_dummy_symbol = True, new_dummy_symbol = "?", do_simplify = True):
"""
Returns an str latex representation of a program.
Parameters
----------
replace_dummy_symbol : bool
If True, dummy symbol is replaced by new_dummy_symbol.
n... |
Returns an str latex representation of a program.
Parameters
----------
replace_dummy_symbol : bool
If True, dummy symbol is replaced by new_dummy_symbol.
new_dummy_symbol : str or None
Replaces dummy symbol if replace_dummy_symbol is True.
do_sim... | get_infix_latex | python | WassimTenachi/PhySO | physo/physym/program.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/program.py | MIT |
def get_infix_fig (self,
replace_dummy_symbol = True,
new_dummy_symbol = "?",
do_simplify = True,
show_superparent_at_beginning = True,
text_size = 16,
text_pos = (0.0, 0.5),
... |
Returns pyplot (figure, axis) containing analytic symbolic function program.
Parameters
----------
replace_dummy_symbol : bool
If True, dummy symbol is replaced by new_dummy_symbol.
new_dummy_symbol : str or None
Replaces dummy symbol if replace_dummy_sym... | get_infix_fig | python | WassimTenachi/PhySO | physo/physym/program.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/program.py | MIT |
def get_infix_image(self,
replace_dummy_symbol = True,
new_dummy_symbol = "?",
do_simplify = True,
text_size = 16,
text_pos = (0.0, 0.5),
figsize = (8, 2),
... |
Returns image containing analytic symbolic function program.
Parameters
----------
replace_dummy_symbol : bool
If True, dummy symbol is replaced by new_dummy_symbol.
new_dummy_symbol : str or None
Replaces dummy symbol if replace_dummy_symbol is True.
... | get_infix_image | python | WassimTenachi/PhySO | physo/physym/program.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/program.py | MIT |
def show_infix(self,
replace_dummy_symbol = True,
new_dummy_symbol = "?",
do_simplify = False,
text_size=24,
text_pos=(0.0, 0.5),
figsize=(10, 1),
):
"""
Shows pyplot (fig... |
Shows pyplot (figure, axis) containing analytic symbolic function program.
Parameters
----------
replace_dummy_symbol : bool
If True, dummy symbol is replaced by new_dummy_symbol.
new_dummy_symbol : str or None
Replaces dummy symbol if replace_dummy_symbo... | show_infix | python | WassimTenachi/PhySO | physo/physym/program.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/program.py | MIT |
def SquashedNRMSE (y_target, y_pred, y_weights = 1.):
"""
Squashed NRMSE reward.
Parameters
----------
y_target : torch.tensor of shape (?,) of float
Target output data.
y_pred : torch.tensor of shape (?,) of float
Predicted data.
y_weights : torch.tensor of shape (?,) of f... |
Squashed NRMSE reward.
Parameters
----------
y_target : torch.tensor of shape (?,) of float
Target output data.
y_pred : torch.tensor of shape (?,) of float
Predicted data.
y_weights : torch.tensor of shape (?,) of float, optional
Weights for each data point. By defaul... | SquashedNRMSE | python | WassimTenachi/PhySO | physo/physym/reward.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/reward.py | MIT |
def RewardsComputer(programs,
X,
y_target,
n_samples_per_dataset,
y_weights = 1.,
free_const_opti_args = None,
reward_function = SquashedNRMSE,
zero_out_unphysical = False,
... |
Computes rewards of programs on X data accordingly with target y_target and reward reward_function using torch
for acceleration.
Parameters
----------
programs : Program.VectProgram
Programs contained in batch to evaluate.
X : torch.tensor of shape (n_dim, ?,) of float
Values of... | RewardsComputer | python | WassimTenachi/PhySO | physo/physym/reward.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/reward.py | MIT |
def make_RewardsComputer(reward_function = SquashedNRMSE,
zero_out_unphysical = False,
zero_out_duplicates = False,
keep_lowest_complexity_duplicate = False,
# Parallel related
parallel_mode ... |
Helper function to make custom reward computing function.
Parameters
----------
reward_function : callable
Function that taking y_target (torch.tensor of shape (?,) of float), y_pred (torch.tensor of shape (?,)
of float) and optionally y_weights (torch.tensor of shape (?,) of float, o... | make_RewardsComputer | python | WassimTenachi/PhySO | physo/physym/reward.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/reward.py | MIT |
def __init__(self,
# ---- Token representation ----
name,
sympy_repr,
# ---- Token main properties ----
arity,
complexity = DEFAULT_COMPLEXITY,
var_type = 0,
# Function specific
... |
Note: __init__ accepts None for some parameters for ease of use which are then converted to the right value and
type as attributes.
Parameters
----------
name : str
A short name for the token (eg. 'add' for addition).
sympy_repr : str
Sympy repres... | __init__ | python | WassimTenachi/PhySO | physo/physym/token.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/token.py | MIT |
def __init__(self, shape, invalid_token_idx):
"""
Parameters
----------
shape : (int, int)
Shape of the matrix.
invalid_token_idx : int
Index of the invalid token in the library of tokens.
"""
# -------------------------------------------... |
Parameters
----------
shape : (int, int)
Shape of the matrix.
invalid_token_idx : int
Index of the invalid token in the library of tokens.
| __init__ | python | WassimTenachi/PhySO | physo/physym/token.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/token.py | MIT |
def retrieve_complexity(complexity_dict, curr_name):
"""
Helper function to safely retrieve complexity of token named curr_name from a dictionary of complexities
(complexity_dict).
Parameters
----------
complexity_dict : dict of {str : float} or None
If dictionary is None or empty, retur... |
Helper function to safely retrieve complexity of token named curr_name from a dictionary of complexities
(complexity_dict).
Parameters
----------
complexity_dict : dict of {str : float} or None
If dictionary is None or empty, returns token.DEFAULT_COMPLEXITY.
curr_name : str
If ... | retrieve_complexity | python | WassimTenachi/PhySO | physo/physym/tokenize.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/tokenize.py | MIT |
def retrieve_init_val (init_val_dict, curr_name):
"""
Helper function to safely retrieve value of token named curr_name from a dictionary of initial values.
(init_val_dict).
Parameters
----------
init_val_dict : dict of {str : float or array_like of floats} or None
If dictionary is None ... |
Helper function to safely retrieve value of token named curr_name from a dictionary of initial values.
(init_val_dict).
Parameters
----------
init_val_dict : dict of {str : float or array_like of floats} or None
If dictionary is None or empty, returns token.DEFAULT_FREE_CONST_INIT_VAL.
... | retrieve_init_val | python | WassimTenachi/PhySO | physo/physym/tokenize.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/tokenize.py | MIT |
def retrieve_units(units_dict, curr_name):
"""
Helper function to safely retrieve units of token named curr_name from a dictionary of units (units_dict).
Parameters
----------
units_dict : dict of {str : array_like} or None
If dictionary is None or empty, returned curr_is_constraining_phy_un... |
Helper function to safely retrieve units of token named curr_name from a dictionary of units (units_dict).
Parameters
----------
units_dict : dict of {str : array_like} or None
If dictionary is None or empty, returned curr_is_constraining_phy_units is False and curr_phy_units is None.
(... | retrieve_units | python | WassimTenachi/PhySO | physo/physym/tokenize.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/tokenize.py | MIT |
def make_tokens(
# operations
op_names = "all",
use_protected_ops = False,
# input variables
input_var_ids = None,
input_var_units = None,
input_var_complexity = None,
... |
Makes a list of tokens for a run based on a list of operation names, input variables ids and constants values.
Parameters
----------
-------- Operations (eg. add, mul, cos, exp) --------
op_names : list of str or str, optional
List of names of operations that will b... | make_tokens | python | WassimTenachi/PhySO | physo/physym/tokenize.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/tokenize.py | MIT |
Subsets and Splits
Django Code with Docstrings
Filters Python code examples from Django repository that contain Django-related code, helping identify relevant code snippets for understanding Django framework usage patterns.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves specific code examples from the Flask repository but doesn't provide meaningful analysis or patterns beyond basic data retrieval.
HTTPX Repo Code and Docstrings
Retrieves specific code examples from the httpx repository, which is useful for understanding how particular libraries are used but doesn't provide broader analytical insights about the dataset.
Requests Repo Docstrings & Code
Retrieves code examples with their docstrings and file paths from the requests repository, providing basic filtering but limited analytical value beyond finding specific code samples.
Quart Repo Docstrings & Code
Retrieves code examples with their docstrings from the Quart repository, providing basic code samples but offering limited analytical value for understanding broader patterns or relationships in the dataset.