Skip to content

autora.theorist.bsr.misc

get_ops_expr()

Get the literal expression for the operation, the {} placeholder represents an expression that is recursively evaluated from downstream operations. If an operator's expression contains additional parameters (e.g. slope/intercept in linear operator), write the parameter like {param} - the param will be passed in using expr.format(xxx, **params) format.

Return

A dictionary that maps operator name to its literal expression.

Source code in temp_dir/bsr/src/autora/theorist/bsr/misc.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def get_ops_expr() -> Dict[str, str]:
    """
    Get the literal expression for the operation, the `{}` placeholder represents
    an expression that is recursively evaluated from downstream operations. If an
    operator's expression contains additional parameters (e.g. slope/intercept in
    linear operator), write the parameter like `{param}` - the param will be passed
    in using `expr.format(xxx, **params)` format.

    Return:
        A dictionary that maps operator name to its literal expression.
    """
    ops_expr = {
        "neg": "-({})",
        "sin": "sin({})",
        "pow2": "({})^2",
        "pow3": "({})^3",
        "exp": "exp({})",
        "cos": "cos({})",
        "+": "{}+{}",
        "*": "({})*({})",
        "-": "{}-{}",
        "inv": "1/[{}]",
        "linear": "{a}*({})+{b}",
    }
    return ops_expr

normalize_prior_dict(prior_dict)

Normalize the prior weights for the operators so that the weights sum to 1 and thus can be directly interpreted/used as probabilities.

Source code in temp_dir/bsr/src/autora/theorist/bsr/misc.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
def normalize_prior_dict(prior_dict: Dict[str, float]):
    """
    Normalize the prior weights for the operators so that the weights sum to
    1 and thus can be directly interpreted/used as probabilities.
    """
    prior_sum = 0.0
    for k in prior_dict:
        prior_sum += prior_dict[k]
    if prior_sum > 0:
        for k in prior_dict:
            prior_dict[k] = prior_dict[k] / prior_sum
    else:
        for k in prior_dict:
            prior_dict[k] = 1 / len(prior_dict)