예제 #1
0
def test_compile_array(): 
    code = expr_lang.compile_expr('(log2 x) + (log2 y)')
    env = {'x': np.array([2, 4]), 'y': np.array([4, 8])}
    res = code(env)
    expected = np.array([3,5])
    print "Expected:", expected, "Received:", res 
    assert np.all(res == expected)
예제 #2
0
    def __init__(self,
                 feature_exprs,
                 model,
                 encoder=None,
                 window_sizes={
                     '5s': 50,
                     '50s': 500
                 },
                 raw_features={
                     'bid': online_features.best_bid,
                     'offer': online_features.best_offer
                 },
                 min_frames_before_prediction=2):

        self.raw_features = raw_features
        self.window_sizes = window_sizes
        self.agg = mk_agg(raw_features, window_sizes)

        self.feature_exprs = feature_exprs
        # a list of expr_lang functions which map a symbol environment to the
        # evaluated feature expression
        self.compiled_features = [
            expr_lang.compile_expr(expr) for expr in feature_exprs
        ]

        # the set of symbols that need to be present in an environment so that
        # all the feature expressions can be evaluated
        self.feature_symbols = expr_lang.symbol_set(feature_exprs)
        self.encoder = encoder
        self.model = model
        self.min_frames_before_prediction = min_frames_before_prediction
        self.longest_window = np.max(window_sizes.values())
예제 #3
0
 def __setstate__(self, state):
     self.__dict__ = state
     # reconstruct feature expr functions, since they weren't pickled
     self.compiled_features = [
         expr_lang.compile_expr(expr) for expr in self.feature_exprs
     ]
     # reconstruct the aggregator which wasn't pickled
     self.agg = mk_agg(state['raw_features'], state['window_sizes'])
예제 #4
0
def test_compiler_env():
    env = {'x':3, 'y':4}
    code = expr_lang.compile_expr('x+y')
    res1 = code(env)
    print "Expected 7, got", res1 
    assert res1 == 7
    env['x'] = 4
    res2 = code(env)
    print "Expected 8, got", res2 
    assert res2 == 8
 def __init__(self, 
         feature_exprs, 
         model,
         encoder=None,
         window_sizes={'5s': 50, '50s': 500}, 
         raw_features={'bid': online_features.best_bid, 'offer': online_features.best_offer}, 
         min_frames_before_prediction=2):
     
     self.raw_features = raw_features
     self.window_sizes = window_sizes 
     self.agg = mk_agg(raw_features, window_sizes) 
     
     self.feature_exprs = feature_exprs 
     # a list of expr_lang functions which map a symbol environment to the
     # evaluated feature expression 
     self.compiled_features = [expr_lang.compile_expr(expr) for expr in feature_exprs]
     
     # the set of symbols that need to be present in an environment so that 
     # all the feature expressions can be evaluated 
     self.feature_symbols = expr_lang.symbol_set(feature_exprs)
     self.encoder = encoder 
     self.model = model 
     self.min_frames_before_prediction = min_frames_before_prediction
     self.longest_window = np.max(window_sizes.values())
예제 #6
0
def test_compiler_nested():
    code = expr_lang.compile_expr('(10+4)%2')
    res = code({})
    print "Received: ", res
    assert res == 7 
예제 #7
0
def test_compiler_simple():
    code = expr_lang.compile_expr('3+4')
    assert code({}) == 7 
 def __setstate__(self, state):
     self.__dict__ = state  
     # reconstruct feature expr functions, since they weren't pickled 
     self.compiled_features = [expr_lang.compile_expr(expr) for expr in self.feature_exprs]
     # reconstruct the aggregator which wasn't pickled 
     self.agg = mk_agg(state['raw_features'], state['window_sizes'])