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 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 __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 |
def __init__(self, batch_size, max_time_step, library, candidate_wrapper=None, n_realizations=None):
"""
Parameters
----------
batch_size : int
Number of programs in batch.
max_time_step : int
Max number of tokens programs can contain.
library : li... |
Parameters
----------
batch_size : int
Number of programs in batch.
max_time_step : int
Max number of tokens programs can contain.
library : library.Library
Library of tokens that can appear in programs.
candidate_wrapper : callable or... | __init__ | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def lib (self, attr):
"""
Gives access to vectorized properties of tokens in library without having to use [0, :] (as batch_size = 1 in
vectorized properties of library).
Parameters
----------
attr : str
Attribute of library vectorized properties to access.
... |
Gives access to vectorized properties of tokens in library without having to use [0, :] (as batch_size = 1 in
vectorized properties of library).
Parameters
----------
attr : str
Attribute of library vectorized properties to access.
Returns
-------
... | lib | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def append (self, new_tokens_idx, forbid_inconsistent_units = False):
"""
Appends new tokens to batch.
New tokens appended to already complete programs (ie. out of tree tokens) are ignored.
Note that units requirements and update is not done in append (as it is computationally costly and... |
Appends new tokens to batch.
New tokens appended to already complete programs (ie. out of tree tokens) are ignored.
Note that units requirements and update is not done in append (as it is computationally costly and unnecessary
if units are not used). Use the assign_required_units method... | append | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def set_programs (self, tokens_idx, forbid_inconsistent_units = False):
"""
Sets all programs in batch by appending tokens_idx step by step.
Parameters
----------
tokens_idx : numpy.array of shape (batch_size, int <= max_time_step) of int
Index of tokens making up pro... |
Sets all programs in batch by appending tokens_idx step by step.
Parameters
----------
tokens_idx : numpy.array of shape (batch_size, int <= max_time_step) of int
Index of tokens making up programs in the library.
If programs have different shapes, tokens_idx mus... | set_programs | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def assign_required_units (self, step = None, ignore_unphysical = True,):
"""
Runs required units assignment routine (assign_required_units) on programs at step.
Parameters
----------
step : int or None
Required units assignment routine is run on tokens at step. By de... |
Runs required units assignment routine (assign_required_units) on programs at step.
Parameters
----------
step : int or None
Required units assignment routine is run on tokens at step. By default, step = current step.
ignore_unphysical : bool
Should routi... | assign_required_units | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def mask_to_coords (self, mask):
"""
Helper function returning coordinates where mask is True.
Parameters
----------
mask : numpy.array of shape (batch_size, max_time_step) of bool
Mask.
Returns
-------
mask_sum, coordinates : int, numpy.array ... |
Helper function returning coordinates where mask is True.
Parameters
----------
mask : numpy.array of shape (batch_size, max_time_step) of bool
Mask.
Returns
-------
mask_sum, coordinates : int, numpy.array of shape (2, mask_sum) of int
Nu... | mask_to_coords | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def coords_to_mask (self, coords):
"""
Helper function returning mask of batch shape (batch_size, max_time_step,) containing True at coords.
Parameters
----------
coords : numpy.array of shape (2, ?) of int
Coordinates where mask should be True
Returns
... |
Helper function returning mask of batch shape (batch_size, max_time_step,) containing True at coords.
Parameters
----------
coords : numpy.array of shape (2, ?) of int
Coordinates where mask should be True
Returns
-------
mask : numpy.array of shape (... | coords_to_mask | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def coords_of_step (self, step):
"""
Helper method returning the tuple of coordinates corresponding to a step.
Parameters
----------
step : int
Step.
Returns
-------
coords : numpy.array of shape (2, batch_size,) of int
Coordinates,... |
Helper method returning the tuple of coordinates corresponding to a step.
Parameters
----------
step : int
Step.
Returns
-------
coords : numpy.array of shape (2, batch_size,) of int
Coordinates, 0th array in batch dim and 1th array in tim... | coords_of_step | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def get_parent (self, coords):
"""
Get parent's coordinates of tokens at coords.
Parameters
----------
coords : numpy.array of shape (2, ?) of int
Coords of tokens, 0th array in batch dim and 1th array in time dim.
Returns
-------
parent_coords... |
Get parent's coordinates of tokens at coords.
Parameters
----------
coords : numpy.array of shape (2, ?) of int
Coords of tokens, 0th array in batch dim and 1th array in time dim.
Returns
-------
parent_coords : numpy.array of shape (2, ?) of int
... | get_parent | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def get_siblings (self, coords):
"""
Get siblings' coordinates of tokens at coords.
Parameters
----------
coords : numpy.array of shape (2, ?) of int
Coords of tokens, 0th array in batch dim and 1th array in time dim.
Returns
-------
siblings_c... |
Get siblings' coordinates of tokens at coords.
Parameters
----------
coords : numpy.array of shape (2, ?) of int
Coords of tokens, 0th array in batch dim and 1th array in time dim.
Returns
-------
siblings_coords : numpy.array of shape (1 + Tok.MAX_NB... | get_siblings | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def get_children (self, coords):
"""
Get children's coordinates of tokens at coords.
Parameters
----------
coords : numpy.array of shape (2, ?) of int
Coords of tokens, 0th array in batch dim and 1th array in time dim.
Returns
-------
children_... |
Get children's coordinates of tokens at coords.
Parameters
----------
coords : numpy.array of shape (2, ?) of int
Coords of tokens, 0th array in batch dim and 1th array in time dim.
Returns
-------
children_coords : numpy.array of shape (1 + Tok.MAX_N... | get_children | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def get_ancestors (self, coords):
"""
Get ancestors' coordinates of tokens at coords.
Parameters
----------
coords : numpy.array of shape (2, ?) of int
Coords of tokens, 0th array in batch dim and 1th array in time dim.
Returns
-------
ancestor... |
Get ancestors' coordinates of tokens at coords.
Parameters
----------
coords : numpy.array of shape (2, ?) of int
Coords of tokens, 0th array in batch dim and 1th array in time dim.
Returns
-------
ancestors_coords : numpy.array of shape (1 + max_time... | get_ancestors | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def get_parent_idx(self, coords, no_parent_idx_filler=None):
"""
Get parents idx of tokens at coords.
Parameters
----------
coords : numpy.array of shape (2, ?,) of int
Coords of tokens, 0th array in batch dim and 1th array in time dim.
no_parent_idx_filler : ... |
Get parents idx of tokens at coords.
Parameters
----------
coords : numpy.array of shape (2, ?,) of int
Coords of tokens, 0th array in batch dim and 1th array in time dim.
no_parent_idx_filler : int
Fill value to return where tokens have no parent.
... | get_parent_idx | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def get_sibling_idx(self, coords, no_sibling_idx_filler=None):
"""
Get siblings idx of tokens at coords.
Parameters
----------
coords : numpy.array of shape (2, ?,) of int
Coords of tokens, 0th array in batch dim and 1th array in time dim.
no_sibling_idx_fille... |
Get siblings idx of tokens at coords.
Parameters
----------
coords : numpy.array of shape (2, ?,) of int
Coords of tokens, 0th array in batch dim and 1th array in time dim.
no_sibling_idx_filler : int
Fill value to return where tokens have no sibling.
... | get_sibling_idx | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def get_ancestors_idx(self, coords, no_ancestor_idx_filler=None):
"""
Get ancestors idx of tokens at step.
Parameters
----------
coords : numpy.array of shape (2, ?,) of int
Coords of tokens, 0th array in batch dim and 1th array in time dim.
no_ancestor_idx_fi... |
Get ancestors idx of tokens at step.
Parameters
----------
coords : numpy.array of shape (2, ?,) of int
Coords of tokens, 0th array in batch dim and 1th array in time dim.
no_ancestor_idx_filler : int
Fill value to return where tokens have no ancestors an... | get_ancestors_idx | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def get_parent_idx_of_step(self, step=None, no_parent_idx_filler=None):
"""
Get parents idx of tokens at step.
Parameters
----------
step : int
Step of token from which parent idx should be returned.
By default, step = current step
no_parent_idx_fi... |
Get parents idx of tokens at step.
Parameters
----------
step : int
Step of token from which parent idx should be returned.
By default, step = current step
no_parent_idx_filler : int
Fill value to return where tokens have no parent.
Re... | get_parent_idx_of_step | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def get_sibling_idx_of_step(self, step=None, no_sibling_idx_filler=None):
"""
Get siblings idx of tokens at step.
Parameters
----------
step : int
Step of token from which sibling idx should be returned.
By default, step = current step
no_sibling_i... |
Get siblings idx of tokens at step.
Parameters
----------
step : int
Step of token from which sibling idx should be returned.
By default, step = current step
no_sibling_idx_filler : int
Fill value to return where tokens have no sibling.
... | get_sibling_idx_of_step | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def get_ancestors_idx_of_step(self, step=None, no_ancestor_idx_filler=None):
"""
Get ancestors idx of tokens at step.
Parameters
----------
step : int
Step of token from which ancestors idx should be returned.
By default, step = current step
no_anc... |
Get ancestors idx of tokens at step.
Parameters
----------
step : int
Step of token from which ancestors idx should be returned.
By default, step = current step
no_ancestor_idx_filler : int
Fill value to return where tokens have no ancestors a... | get_ancestors_idx_of_step | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def count_tokens_idx (self, tokens_idx):
"""
Creates a library size vector containing count of token idx (along ?1 dim) in tokens_idx for each line of
tokens_idx. Eg: [ [2, 2, 1, 2, 5], [1, 1, 1, 0, 4] ] -> [0,1,3,0,0,1] [1,3,0,0,1,0] assuming n_library = 5.
Parameters
----------... |
Creates a library size vector containing count of token idx (along ?1 dim) in tokens_idx for each line of
tokens_idx. Eg: [ [2, 2, 1, 2, 5], [1, 1, 1, 0, 4] ] -> [0,1,3,0,0,1] [1,3,0,0,1,0] assuming n_library = 5.
Parameters
----------
tokens_idx : numpy.array of shape (?, ?1) o... | count_tokens_idx | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def get_property_of_relative(self, coords, relative, attr):
"""
Returns the attribute (eg. phy_units, arity etc.) of the [relative] of tokens at coords. Fills with default
value of attribute in VectTokens where tokens at coords do not have [relative].
Parameters
----------
... |
Returns the attribute (eg. phy_units, arity etc.) of the [relative] of tokens at coords. Fills with default
value of attribute in VectTokens where tokens at coords do not have [relative].
Parameters
----------
coords : numpy.array of shape (2, ?,) of int
Coords of to... | get_property_of_relative | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def set_parent(self, coords_dest, has_mask, pos_val):
"""
Sets parent properties of tokens of coordinates coords_dest with new values given in args.
Parameters
----------
coords_dest : numpy.array of shape (2, ?) of int
Coords where to set property, 0th array in batch... |
Sets parent properties of tokens of coordinates coords_dest with new values given in args.
Parameters
----------
coords_dest : numpy.array of shape (2, ?) of int
Coords where to set property, 0th array in batch dim and 1th array in time dim.
has_mask : numpy.array of... | set_parent | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def set_children(self, coords_dest, has_mask, pos_val, nb):
"""
Sets children properties of tokens of coordinates coords_dest with new values given in args.
Parameters
----------
coords_dest : numpy.array of shape (2, ?) of int
Coords where to set property, 0th array ... |
Sets children properties of tokens of coordinates coords_dest with new values given in args.
Parameters
----------
coords_dest : numpy.array of shape (2, ?) of int
Coords where to set property, 0th array in batch dim and 1th array in time dim.
has_mask : numpy.array ... | set_children | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def set_siblings(self, coords_dest, has_mask, pos_val, nb):
"""
Sets siblings properties of tokens of coordinates coords_dest with new values given in args.
Parameters
----------
coords_dest : numpy.array of shape (2, ?) of int
Coords where to set property, 0th array ... |
Sets siblings properties of tokens of coordinates coords_dest with new values given in args.
Parameters
----------
coords_dest : numpy.array of shape (2, ?) of int
Coords where to set property, 0th array in batch dim and 1th array in time dim.
has_mask : numpy.array ... | set_siblings | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def set_ancestors(self, coords_dest, has_mask, pos_val, nb):
"""
Sets ancestors properties of tokens of coordinates coords_dest with new values given in args.
Parameters
----------
coords_dest : numpy.array of shape (2, ?) of int
Coords where to set property, 0th arra... |
Sets ancestors properties of tokens of coordinates coords_dest with new values given in args.
Parameters
----------
coords_dest : numpy.array of shape (2, ?) of int
Coords where to set property, 0th array in batch dim and 1th array in time dim.
has_mask : numpy.array... | set_ancestors | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def register_ancestor(self, coords_dest, ):
"""
Registers tokens located at coords_dest in their own ancestor records (as a token counts as its own ancestor)
and updates the number of ancestors. Depths must be up-to-date for this function to perform correctly.
Parameters
--------... |
Registers tokens located at coords_dest in their own ancestor records (as a token counts as its own ancestor)
and updates the number of ancestors. Depths must be up-to-date for this function to perform correctly.
Parameters
----------
coords_dest : numpy.array of shape (2, ?) of... | register_ancestor | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def set_units (self, coords_dest, new_is_constraining_phy_units, new_phy_units):
"""
Sets units properties of tokens of coordinates coords_dest with new values given in args.
Parameters
----------
coords_dest : numpy.array of shape (2, ?) of int
Coords where to set ne... |
Sets units properties of tokens of coordinates coords_dest with new values given in args.
Parameters
----------
coords_dest : numpy.array of shape (2, ?) of int
Coords where to set new tokens, 0th array in batch dim and 1th array in time dim.
new_is_constraining_phy_... | set_units | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def set_static_units_from_idx (self, coords_dest, tokens_idx_src):
"""
Sets units properties of tokens at coords_dest from units of tokens tokens_idx_src as given in the library.
Parameters
----------
coords_dest : numpy.array of shape (2, ?) of int
Coords where to se... |
Sets units properties of tokens at coords_dest from units of tokens tokens_idx_src as given in the library.
Parameters
----------
coords_dest : numpy.array of shape (2, ?) of int
Coords where to set new tokens, 0th array in batch dim and 1th array in time dim.
tokens... | set_static_units_from_idx | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def set_non_positional_from_idx (self, coords_dest, tokens_idx_src):
"""
Sets non_positional properties and index of new tokens as given in the library.
Parameters
----------
coords_dest : numpy.array of shape (2, ?) of int
Coords where to set new tokens, 0th array in... |
Sets non_positional properties and index of new tokens as given in the library.
Parameters
----------
coords_dest : numpy.array of shape (2, ?) of int
Coords where to set new tokens, 0th array in batch dim and 1th array in time dim.
tokens_idx_src : numpy.array of sh... | set_non_positional_from_idx | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def move_dummies (self, coords_src, coords_dest, do_update_relationships_pos = True, do_fill_with_void = True):
"""
Moves dummies from coords_src to coords_dest.
! This function only works for dummies placed as placeholders that are completing programs. !
-> Does not work for moved ... |
Moves dummies from coords_src to coords_dest.
! This function only works for dummies placed as placeholders that are completing programs. !
-> Does not work for moved tokens that have sibling relationships to each others
and does not update dummies' children nor their ances... | move_dummies | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def update_relationships_pos_of_moved_tokens (coords_b_move, coords_a_move):
"""
Updates position of dummy tokens that were moved in other tokens corresponding to family relationships
(parent, siblings).
! This function only works for dummies placed as placeholders that a... |
Updates position of dummy tokens that were moved in other tokens corresponding to family relationships
(parent, siblings).
! This function only works for dummies placed as placeholders that are completing programs. !
-> Does not work for moved tokens that have sibli... | update_relationships_pos_of_moved_tokens | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def fill_with_void(self, coords_dest):
"""
Helper function that fills coords_dest with void invalid token.
Parameters
----------
coords_dest : numpy.array of shape (2, ?) of int
Coords where to fill with void, 0th array in batch dim and 1th array in time dim.
... |
Helper function that fills coords_dest with void invalid token.
Parameters
----------
coords_dest : numpy.array of shape (2, ?) of int
Coords where to fill with void, 0th array in batch dim and 1th array in time dim.
| fill_with_void | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def compute_sum_arities(self, step=0):
"""
Computes total arities of programs along time dim from step = 0 to step = step.
Parameters
----------
step : int
Step where to end summation.
Returns
-------
sum : numpy.array of shape (batch_size,) of... |
Computes total arities of programs along time dim from step = 0 to step = step.
Parameters
----------
step : int
Step where to end summation.
Returns
-------
sum : numpy.array of shape (batch_size,) of int
Sum along time dim of size (batch... | compute_sum_arities | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def n_completed(self):
"""
Lengths of programs when completed by dummies.
Returns
-------
completed_lengths : numpy.array of shape (batch_size,) of int
"""
# Computes length when completed by dummies.
return self.n_lengths + self.n_dummies # (batch_size,)... |
Lengths of programs when completed by dummies.
Returns
-------
completed_lengths : numpy.array of shape (batch_size,) of int
| n_completed | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def n_complexity(self):
"""
Complexities of programs.
Returns
-------
complexity : numpy.array of shape (batch_size,) of int
"""
# Summing over time dim
return self.tokens.complexity.sum(axis=1) # (batch_size,) of int |
Complexities of programs.
Returns
-------
complexity : numpy.array of shape (batch_size,) of int
| n_complexity | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def n_free_const_occurrences(self):
"""
Number of occurrences of free const in programs.
This is to know if we should bother running the optimization process.
Returns
-------
occurrences : numpy.array of shape (batch_size,) of int
"""
is_free_const = ((sel... |
Number of occurrences of free const in programs.
This is to know if we should bother running the optimization process.
Returns
-------
occurrences : numpy.array of shape (batch_size,) of int
| n_free_const_occurrences | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def get_prog_tokens(self, prog_idx=0):
"""
Returns a list of tokens representing a single program of idx = prog_idx.
Discards void tokens beyond program length.
Parameters
----------
prog_idx : int
Index of program in batch.
Returns
-------
... |
Returns a list of tokens representing a single program of idx = prog_idx.
Discards void tokens beyond program length.
Parameters
----------
prog_idx : int
Index of program in batch.
Returns
-------
tokens : numpy.array of token.Token
... | get_prog_tokens | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def get_prog(self, prog_idx=0, skeleton = False, detach = False):
"""
Returns a Program object of program of idx = prog_idx in batch.
Discards void tokens beyond program length.
Parameters
----------
prog_idx : int
Index of program in batch.
skeleton :... |
Returns a Program object of program of idx = prog_idx in batch.
Discards void tokens beyond program length.
Parameters
----------
prog_idx : int
Index of program in batch.
skeleton : bool
Only exports the bare minimum pickable version of the progr... | get_prog | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def batch_exe_reduce_gather (self, 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
----------
X : torch.tensor of shape (n_dim, n_samples,) of float
... | batch_exe_reduce_gather | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def batch_exe_reward (self, X, y_target, reward_function, y_weights = 1.,
# Realization related
i_realization = 0,
n_samples_per_dataset = None,
# Mask
... |
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
----------
X : torch.tensor of shape (n_dim, n_sample... | batch_exe_reward | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def batch_optimize_constants (self, X, y_target, free_const_opti_args=None, y_weights = 1.,
# Realization related
i_realization = 0,
n_samples_per_dataset = None,
# Mask
... |
Optimizes the free constants of each program in progs.
NB: Parallel execution is typically faster.
Parameters
----------
X : torch.tensor of shape (n_dim, n_samples,) of float
Values of the input variables of the problem with n_dim = nb of input variables.
y_... | batch_optimize_constants | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def get_infix_str (self, prog_idx = 0):
"""
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
----------
prog_idx : int
Index of program in VectProg... |
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
----------
prog_idx : int
Index of program in VectPrograms.
Returns
-------
progr... | get_infix_str | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
def get_infix_sympy (self, prog_idx = 0, do_simplify = True):
"""
Returns sympy symbolic representation of a program.
Parameters
----------
prog_idx : int
Index of program in VectPrograms.
do_simplify : bool
If True performs a symbolic simplificati... |
Returns sympy symbolic representation of a program.
Parameters
----------
prog_idx : int
Index of program in VectPrograms.
do_simplify : bool
If True performs a symbolic simplification of program.
Returns
-------
program_sympy : sy... | get_infix_sympy | python | WassimTenachi/PhySO | physo/physym/vect_programs.py | https://github.com/WassimTenachi/PhySO/blob/master/physo/physym/vect_programs.py | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.