Uniform Arity Prior

class physo.physym.prior.UniformArityPrior(library, programs)

Uniform probability distribution over tokens by their arities. This prior encourages tokens with an arity that is under-represented and discourages tokens with an arity that is over-represented by normalising token probabilities by the number of tokens having its arity.

__init__(library, programs)
Parameters:
  • library (library.Library) –

  • programs (vect_programs.VectPrograms) –

Example of usage from the config file:

priors_config  = [
                ...
                ("UniformArityPrior", None),
                ...
                 ]

Hard Length Prior

class physo.physym.prior.HardLengthPrior(library, programs, min_length, max_length)

Forces programs to have lengths such that min_length <= lengths <= max_length finished. Enforces lengths <= max_length by forbidding non-terminal tokens when choosing non-terminal tokens would mean exceeding max length of program. Enforces min_length <= lengths by forbidding terminal tokens when choosing a terminal token would mean finishing a program before min_length.

__init__(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) – Maximum length that programs are allowed to have.

Example of usage from the config file:

priors_config  = [
                ...
                ("HardLengthPrior"  , {"min_length": 4, "max_length": 35, }),
                ...
                 ]

Soft Length Prior

class physo.physym.prior.SoftLengthPrior(library, programs, length_loc, scale)

Soft prior that encourages programs to have a length close to length_loc. Before loc: scales terminal token probabilities by gaussian where dangling == 1 (ie. programs that might finish next step). After loc: scales non-terminal token probabilities by gaussian.

__init__(library, programs, length_loc, scale)
Parameters:
  • library (library.Library) –

  • programs (vect_programs.VectPrograms) –

  • length_loc (float) – Desired length of programs.

  • scale (float) – Scale of gaussian used as prior.

Example of usage from the config file:

priors_config  = [
                ...
                ("SoftLengthPrior"  , {"length_loc": 8, "scale": 5, }),
                ...
                 ]

Relationship Constraint Prior

class physo.physym.prior.RelationshipConstraintPrior(library, programs, effectors, relationship, targets, max_nb_violations=None)

Forces programs to comply with relationships constraints. Enforcing that [targets] cannot be the [relationship] of [effectors]. Where targets are choosable tokens for the current batch, effectors are already chosen tokens having a [relationship] relationship (descendant, child or sibling) with targets. This constraint between elements of effectors list and targets list in a one to one fashion so effectors and targets list should have the same size. Eg. effectors = [“sin”, “n2”, “exp”], relationship = “child”, targets = [“cos”, “sqrt”, “log”] forbids cos from being the child of sin, sqrt from being the child of n2 and log from being the child of exp.

__init__(library, programs, effectors, relationship, targets, max_nb_violations=None)

Enforcing that [targets] cannot be the [relationship] of [effectors]. :param library: :type library: library.Library :param programs: :type programs: vect_programs.VectPrograms :param effectors: List of effector tokens’ name. :type effectors: list of str :param relationship: Relationship to forbid between effectors and targets (“descendant”, “child” or “sibling”). :type relationship: str :param targets: List of target tokens’ name. :type targets: list of str :param max_nb_violations: List containing max number of acceptable violations for each constraint relationship in case there are

multiple relatives having [relationship] with [targets] (eg. multiple ancestors). By default = None, zero violations are allowed. Should have the same size as effectors and targets lists. Remark: using max_nb_violations with values > 0 on single relative relationship cases (eg. parent) would mean applying no constraint whatsoever.

Example of usage from the config file:

priors_config  = [
                ...
                ("RelationshipConstraintPrior"  , {"effectors"    : ["exp" , "log", "sin", "exp", "sub"],
                                                   "targets"      : ["log" , "exp", "sin", "cos", "neg"],
                                                   "relationship" : "child",
                                                   }),
                ...
                 ]

No Useless Inverse Prior

class physo.physym.prior.NoUselessInversePrior(library, programs)

Forbids useless inverse sequences. Enforcing that op can not be the child of op^(-1) and that op^(-1) can not be the child of op for all op having an inverse op^(-1) listed in functions.INVERSE_OP_DICT.

__init__(library, programs)

Enforcing functions are not child of their inverse function. :param library: :type library: library.Library :param programs: :type programs: vect_programs.VectPrograms

Example of usage from the config file:

priors_config  = [
                ...
                ("NoUselessInversePrior"  , None),
                ...
                 ]

Nested Functions

class physo.physym.prior.NestedFunctions(library, programs, functions, max_nesting=1)

Regulates nesting for a group of tokens. Enforcing that any token in [functions] can only have up to [max_nesting] ancestors listed in [functions].

__init__(library, programs, functions, max_nesting=1)

Enforcing that [functions] can not be nested or only up to max_nesting level. :param library: :type library: library.Library :param programs: :type programs: vect_programs.VectPrograms :param functions: List of tokens’ names which’s nesting will be forbidden. :type functions: list of str :param max_nesting: Max level of nesting allowed. By default = 1, no nesting allowed. :type max_nesting: int

Example of usage from the config file:

priors_config  = [
                ...
                ("NestedFunctions", {"functions":["exp",], "max_nesting" : 1}),
                ("NestedFunctions", {"functions":["log",], "max_nesting" : 1}),
                ...
                 ]

Nested Trigonometry Prior

class physo.physym.prior.NestedTrigonometryPrior(library, programs, max_nesting=1)

Regulates nesting of trigonometric functions listed in functions.TRIGONOMETRIC_OP. Enforcing that any trigonometric function can only have up to [max_nesting] ancestors that also are trigonometric functions.

__init__(library, programs, max_nesting=1)

Enforcing that trigonometric functions can not be nested or only up to max_nesting level. :param library: :type library: library.Library :param programs: :type programs: vect_programs.VectPrograms :param max_nesting: Max level of nesting allowed. By default = 1, no nesting allowed. :type max_nesting: int

Example of usage from the config file:

priors_config  = [
                ...
                ("NestedTrigonometryPrior", {"max_nesting" : 1}),
                ...
                 ]

Occurrences Prior

class physo.physym.prior.OccurrencesPrior(library, programs, targets, max)

Enforces that [targets] can not appear more than [max] times in programs.

__init__(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 of int) – List of maximum occurrences of tokens (must have the same length as targets).

Example of usage from the config file:

priors_config  = [
                ...
                ("OccurrencesPrior", {"targets" : ["1",], "max" : [3,] }),
                ...
                 ]

Symbolic Prior

class physo.physym.prior.SymbolicPrior(library, programs, expression)

Enforces that programs must be exactly like [expression].

__init__(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_NAME) in which case all tokens are allowed. All tokens are allowed after the last token in expression.

Example of usage from the config file:

priors_config  = [
                ...
                # Forcing expression to look like a + ...
                ('SymbolicPrior', {'expression': ["+", "a", ]}),
                ...
                 ]

Physical Units Prior

class physo.physym.prior.PhysicalUnitsPrior(library, programs, prob_eps=0.0)

Enforces that next token should be physically consistent units-wise with current program based on current units constraints computed live (during program generation). If there is no way get a constraint all tokens are allowed.

__init__(library, programs, prob_eps=0.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)

Example of usage from the config file:

priors_config  = [
                ...
                # Zeroing out to epsilon level unphysical symbolic choices
                ("PhysicalUnitsPrior", {"prob_eps": np.finfo(np.float32).eps}),
                ...
                 ]