Skip to content

autora.theorist.bsr.prior

_get_ops_init()

Get the initialization functions for operators that require additional parameters.

Returns:

Name Type Description
ops_init Dict[str, Union[Callable, object]]

a dictionary that maps operator name to either a parameter dict (in the case that the initialization is hard-coded) or an initialization function (when it is randomized). The dictionary value will be used in growing the node (see funcs_legacy.py).

Source code in temp_dir/bsr/src/autora/theorist/bsr/prior.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def _get_ops_init() -> Dict[str, Union[Callable, object]]:
    """
    Get the initialization functions for operators that require additional
    parameters.

    Returns:
        ops_init: a dictionary that maps operator name to either a parameter
            dict (in the case that the initialization is hard-coded) or an
            initialization function (when it is randomized). The dictionary
            value will be used in growing the `node` (see `funcs_legacy.py`).
    """
    ops_init = {
        "ln": linear_init,
        "inv": {"cutoff": 1e-10},
        "exp": {"cutoff": 1e-10},
    }
    return ops_init

_get_ops_with_arity()

Get the operator function and arity (number of operands) of each operator.

Returns:

Name Type Description
ops_fn_and_arity

a dictionary that maps operator name to a list, where the first item is the operator function and the second is the number of operands that it takes.

Source code in temp_dir/bsr/src/autora/theorist/bsr/prior.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def _get_ops_with_arity():
    """
    Get the operator function and arity (number of operands) of each operator.

    Returns:
        ops_fn_and_arity: a dictionary that maps operator name to a list, where
            the first item is the operator function and the second is the number of
            operands that it takes.
    """
    ops_fn_and_arity = {
        "ln": [linear_op, 1],
        "exp": [exp_op, 1],
        "inv": [inv_op, 1],
        "neg": [neg_op, 1],
        "sin": [sin_op, 1],
        "cos": [cos_op, 1],
        "pow2": [make_pow_op(2), 1],
        "pow3": [make_pow_op(3), 1],
        "+": [plus_op, 2],
        "*": [multiply_op, 2],
        "-": [minus_op, 2],
    }
    return ops_fn_and_arity

get_prior_dict(prior_name='Uniform')

Get the dictionary of prior information as well as several list of key operator properties

Argument

prior_name: the name of the prior dictionary to use

Returns:

Name Type Description
ops_name_lst

the list of operator names

ops_weight_lst

the list of operator weights

prior_dict

the dictionary of operator prior information

Source code in temp_dir/bsr/src/autora/theorist/bsr/prior.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
def get_prior_dict(prior_name="Uniform"):
    """
    Get the dictionary of prior information as well as several list of key operator properties

    Argument:
        prior_name: the name of the prior dictionary to use

    Returns:
        ops_name_lst: the list of operator names
        ops_weight_lst: the list of operator weights
        prior_dict: the dictionary of operator prior information
    """
    ops_prior = _get_prior(prior_name)
    ops_init = _get_ops_init()
    ops_fn_and_arity = _get_ops_with_arity()

    ops_name_lst = list(ops_prior.keys())
    ops_weight_lst = list(ops_prior.values())
    prior_dict = {
        k: {
            "init": ops_init.get(k, {}),
            "fn": ops_fn_and_arity[k][0],
            "arity": ops_fn_and_arity[k][1],
            "weight": ops_prior[k],
        }
        for k in ops_prior
    }

    return ops_name_lst, ops_weight_lst, prior_dict

get_prior_list(prior_name='Uniform')

Get a dictionary of key prior properties

Argument

prior_name: the name of the prior dictionary to use

Returns:

Type Description

a dictionary that maps a prior property (e.g. name) to the list of such properties for each operator.

Source code in temp_dir/bsr/src/autora/theorist/bsr/prior.py
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
def get_prior_list(prior_name="Uniform"):
    """
    Get a dictionary of key prior properties

    Argument:
        prior_name: the name of the prior dictionary to use

    Returns:
        a dictionary that maps a prior property (e.g. `name`) to the list of such properties
            for each operator.
    """
    ops_prior = _get_prior(prior_name)
    ops_init = _get_ops_init()
    ops_fn_and_arity = _get_ops_with_arity()

    ops_name_lst = list(ops_prior.keys())
    ops_weight_lst = list(ops_prior.values())
    ops_init_lst = [ops_init.get(k, None) for k in ops_name_lst]
    ops_fn_lst = [ops_fn_and_arity[k][0] for k in ops_name_lst]
    ops_arity_lst = [ops_fn_and_arity[k][1] for k in ops_name_lst]
    return {
        "name": ops_name_lst,
        "weight": ops_weight_lst,
        "init": ops_init_lst,
        "fn": ops_fn_lst,
        "arity": ops_arity_lst,
    }

linear_init(**hyper_params)

Initialization function for the linear operator. Two parameters, slope (a) and intercept (b) are initialized.

Parameters:

Name Type Description Default
hyper_params

the dictionary for hyperparameters. Specifically, this function requires sigma_a and sigma_b to be present.

{}

Returns: a dictionary with initialized a and b parameters.

Source code in temp_dir/bsr/src/autora/theorist/bsr/prior.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def linear_init(**hyper_params) -> Dict:
    """
    Initialization function for the linear operator. Two parameters, slope
    (a) and intercept (b) are initialized.

    Arguments:
        hyper_params: the dictionary for hyperparameters. Specifically, this
            function requires `sigma_a` and `sigma_b` to be present.
    Returns:
        a dictionary with initialized `a` and `b` parameters.
    """
    sigma_a, sigma_b = hyper_params.get("sigma_a", 1), hyper_params.get("sigma_b", 1)
    return {
        "a": norm.rvs(loc=1, scale=np.sqrt(sigma_a)),
        "b": norm.rvs(loc=0, scale=np.sqrt(sigma_b)),
    }