comparison algorithms/logistic_regression.py @ 494:02a331ba833b

merge
author Joseph Turian <turian@gmail.com>
date Tue, 28 Oct 2008 11:40:56 -0400
parents 180d125dc7e2
children 7560817a07e8
comparison
equal deleted inserted replaced
493:32509c479e2d 494:02a331ba833b
16 self.w = N.zeros((n_in, n_out)) 16 self.w = N.zeros((n_in, n_out))
17 self.b = N.zeros(n_out) 17 self.b = N.zeros(n_out)
18 self.lr = 0.01 18 self.lr = 0.01
19 self.__hide__ = ['params'] 19 self.__hide__ = ['params']
20 20
21 def __init__(self, x=None, targ=None, w=None, b=None, lr=None): 21 def __init__(self, x=None, targ=None, w=None, b=None, lr=None, regularize=False):
22 super(Module_Nclass, self).__init__() #boilerplate 22 super(Module_Nclass, self).__init__() #boilerplate
23 23
24 self.x = x if x is not None else T.matrix() 24 self.x = x if x is not None else T.matrix()
25 self.targ = targ if targ is not None else T.lvector() 25 self.targ = targ if targ is not None else T.lvector()
26 26
34 T.dot(self.x, self.w) + self.b, self.targ) 34 T.dot(self.x, self.w) + self.b, self.targ)
35 sum_xent = T.sum(xent) 35 sum_xent = T.sum(xent)
36 36
37 self.y = y 37 self.y = y
38 self.sum_xent = sum_xent 38 self.sum_xent = sum_xent
39 self.cost = sum_xent
39 40
40 #define the apply method 41 #define the apply method
41 self.pred = T.argmax(T.dot(self.x, self.w) + self.b, axis=1) 42 self.pred = T.argmax(T.dot(self.x, self.w) + self.b, axis=1)
42 self.apply = module.Method([self.x], self.pred) 43 self.apply = module.Method([self.x], self.pred)
43 44
55 self.w = N.random.randn(n_in,1) 56 self.w = N.random.randn(n_in,1)
56 self.b = N.random.randn(1) 57 self.b = N.random.randn(1)
57 self.lr = 0.01 58 self.lr = 0.01
58 self.__hide__ = ['params'] 59 self.__hide__ = ['params']
59 60
60 def __init__(self, x=None, targ=None, w=None, b=None, lr=None): 61 def __init__(self, x=None, targ=None, w=None, b=None, lr=None, regularize=False):
61 super(Module, self).__init__() #boilerplate 62 super(Module, self).__init__() #boilerplate
62 63
63 self.x = x if x is not None else T.matrix() 64 self.x = x if x is not None else T.matrix()
64 self.targ = targ if targ is not None else T.lcol() 65 self.targ = targ if targ is not None else T.lcol()
65 66
74 sum_xent = T.sum(xent) 75 sum_xent = T.sum(xent)
75 76
76 self.y = y 77 self.y = y
77 self.xent = xent 78 self.xent = xent
78 self.sum_xent = sum_xent 79 self.sum_xent = sum_xent
80 self.cost = sum_xent
79 81
80 #define the apply method 82 #define the apply method
81 self.pred = (T.dot(self.x, self.w) + self.b) > 0.0 83 self.pred = (T.dot(self.x, self.w) + self.b) > 0.0
82 self.apply = module.Method([self.x], self.pred) 84 self.apply = module.Method([self.x], self.pred)
83 85