-
Notifications
You must be signed in to change notification settings - Fork 3
/
wisard_wrapper.pyx
71 lines (69 loc) · 2.96 KB
/
wisard_wrapper.pyx
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
import numpy as np
from libcpp.vector cimport vector
from libcpp.algorithm cimport sort as stdsort
from libcpp.string cimport string
cdef extern from "Discriminator.h" namespace "wnn":
cdef cppclass Discriminator:
Discriminator(int, int, string)
int n_rams, n_locs, n_bits, n_pixels,
double maxmi
string name, maptype
vector[double] mi
vector[int] map
int getNBits()
int getSize()
int getNRams()
double getMaxMI()
vector[double] getMI()
vector[int] getMapping()
string toString(int)
void TrainByTuple(vector[int]&) except +
void Train(vector[double]&, vector[double]&, vector[double]&, int) except +
void TrainNoScale(vector[double]&, int) except +
void UnTrainByTuple(vector[int]&) except +
double ClassifyByTuple(vector[int]&) except +
double Classify(vector[double]&, vector[double]&, vector[double]&, int) except +
double ClassifyNoScale(vector[double]&, int) except +
vector[double] ResponseByTuple(vector[int]&) except +
vector[double] Response(vector[double]&, vector[double]&, vector[double]&, int) except +
vector[double] ResponseNoScale(vector[double]&, int) except +
cdef class PyDiscriminator:
cdef Discriminator *thisptr # hold a C++ instance which we're wrapping
def __cinit__(self, bits, size, maptype="random"):
self.thisptr = new Discriminator(bits, size, maptype.encode('utf-8'))
def __dealloc__(self):
del self.thisptr
def getNBits(self):
return self.thisptr.getNBits()
def getSize(self):
return self.thisptr.getSize()
def getMaxMI(self):
return self.thisptr.getMaxMI()
def getNRams(self):
return self.thisptr.getNRams()
def getMI(self):
return np.array(self.thisptr.getMI())
def getMapping(self):
return np.array(self.thisptr.getMapping())
def Train(self, data, ranges, offsets, tics):
self.thisptr.Train(data, ranges, offsets, tics)
def TrainNoScale(self, data, tics):
self.thisptr.TrainNoScale(data, tics)
def TrainByTuple(self, tuple):
self.thisptr.TrainByTuple(tuple)
def UnTrainByTuple(self, tuple):
self.thisptr.UnTrainByTuple(tuple)
def ClassifyByTuple(self, tuple):
return self.thisptr.ClassifyByTuple(tuple)
def Classify(self, data, ranges, offsets, tics):
return self.thisptr.Classify(data, ranges, offsets, tics)
def ClassifyNoScale(self, data, tics):
return self.thisptr.ClassifyNoScale(data, tics)
def ResponseByTuple(self, tuple):
return np.array(self.thisptr.ResponseByTuple(tuple))
def Response(self, data, ranges, offsets, tics):
return np.array(self.thisptr.Response(data, ranges, offsets, tics))
def ResponseNoScale(self, data, tics):
return np.array(self.thisptr.ResponseNoScale(data, tics))
def toString(self, int mode=0):
return self.thisptr.toString(mode)