-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgp_synth_plugins.py
76 lines (69 loc) · 1.87 KB
/
gp_synth_plugins.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
# Copyright (c) 2018 MIT Probabilistic Computing Project.
# Released under Apache 2.0; refer to LICENSE.txt.
import numpy as np
import venture.lite.types as vt
from venture.lite import gp
from venture.lite.sp_help import deterministic_typed
from gp_synth_compilers import compile_ast_to_embedded_dsl
from gp_synth_interpreter import interpret_embedded_dsl
def load_csv(path):
return np.loadtxt(path)
def __venture_start__(ripl):
ripl.execute_program('''
assume gp_cov_wn = (c) -> {
gp_cov_scale(c, gp_cov_bump(1e-9, 1e-11))
};
define gp_cov_wn = (c) -> {
gp_cov_scale(c, gp_cov_bump(1e-9, 1e-11))
};
''')
ripl.bind_foreign_inference_sp(
'sort',
deterministic_typed(
np.sort,
[
vt.ArrayUnboxedType(vt.NumberType()),
],
vt.ArrayUnboxedType(vt.NumberType()),
min_req_args=1
)
)
ripl.bind_foreign_inference_sp(
'get_mean',
deterministic_typed(
np.mean,
[
vt.ArrayUnboxedType(vt.NumberType()),
],
vt.NumberType(),
min_req_args=1
)
)
ripl.bind_foreign_inference_sp(
'load_csv',
deterministic_typed(
load_csv,
[vt.StringType()],
vt.ArrayUnboxedType(vt.NumberType()),
min_req_args=1
)
)
ripl.bind_foreign_sp(
'compile_ast_to_venturescript',
deterministic_typed(
compile_ast_to_embedded_dsl,
[vt.AnyType()],
vt.StringType(),
min_req_args=1
)
)
ripl.bind_foreign_sp(
'eval_expr',
deterministic_typed(
interpret_embedded_dsl,
[vt.StringType()],
gp.gpType,
min_req_args=1
)
)