-
Notifications
You must be signed in to change notification settings - Fork 9
/
featprocessing.py
61 lines (46 loc) · 1.63 KB
/
featprocessing.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
import numpy as np
class FeatProcessorParams:
def __init__(self):
raise NotImplementedError()
class FeatProcessor:
def __init__(self, params):
raise NotImplementedError()
def fit(self, X):
""" X is [num_examples, num_features] """
raise NotImplementedError()
def process(self, X):
""" Process the examples in X ***in place*** """
raise NotImplementedError()
@staticmethod
def create_feat_processor(params):
assert isinstance(params, FeatProcessorParams)
if isinstance(params, FeatProcessorIdentityParams):
return FeatProcessorIdentity(params)
elif isinstance(params, FeatProcessorScaleParams):
return FeatProcessorScale(params)
else:
raise ValueError('params instance not recognized')
#=============================================================================
class FeatProcessorIdentityParams(FeatProcessorParams):
def __init__(self):
pass
class FeatProcessorIdentity(FeatProcessor):
def __init__(self, params):
pass
def fit(self, X):
pass
def process(self, X):
pass
#=============================================================================
class FeatProcessorScaleParams(FeatProcessorParams):
def __init__(self, scale=None):
self.scale = scale
class FeatProcessorScale(FeatProcessor):
def __init__(self, params):
assert isinstance(params, FeatProcessorScaleParams)
self.params = params
def fit(self, X):
pass
def process(self, X):
assert self.params.scale != None
X *= self.params.scale