MCPcopy Index your code
hub / github.com/lisa-lab/DeepLearningTutorials / LogisticRegression

Class LogisticRegression

code/logistic_cg.py:52–142  ·  view source on GitHub ↗

Multi-class Logistic Regression Class The logistic regression is fully described by a weight matrix :math:`W` and bias vector :math:`b`. Classification is done by projecting data points onto a set of hyperplanes, the distance to which is used to determine a class membership probabil

Source from the content-addressed store, hash-verified

50
51
52class LogisticRegression(object):
53 """Multi-class Logistic Regression Class
54
55 The logistic regression is fully described by a weight matrix :math:`W`
56 and bias vector :math:`b`. Classification is done by projecting data
57 points onto a set of hyperplanes, the distance to which is used to
58 determine a class membership probability.
59 """
60
61 def __init__(self, input, n_in, n_out):
62 """ Initialize the parameters of the logistic regression
63
64 :type input: theano.tensor.TensorType
65 :param input: symbolic variable that describes the input of the
66 architecture ( one minibatch)
67
68 :type n_in: int
69 :param n_in: number of input units, the dimension of the space in
70 which the datapoint lies
71
72 :type n_out: int
73 :param n_out: number of output units, the dimension of the space in
74 which the target lies
75
76 """
77
78 # initialize theta = (W,b) with 0s; W gets the shape (n_in, n_out),
79 # while b is a vector of n_out elements, making theta a vector of
80 # n_in*n_out + n_out elements
81 self.theta = theano.shared(
82 value=numpy.zeros(
83 n_in * n_out + n_out,
84 dtype=theano.config.floatX
85 ),
86 name='theta',
87 borrow=True
88 )
89 # W is represented by the fisr n_in*n_out elements of theta
90 self.W = self.theta[0:n_in * n_out].reshape((n_in, n_out))
91 # b is the rest (last n_out elements)
92 self.b = self.theta[n_in * n_out:n_in * n_out + n_out]
93
94 # compute vector of class-membership probabilities in symbolic form
95 self.p_y_given_x = T.nnet.softmax(T.dot(input, self.W) + self.b)
96
97 # compute prediction as class whose probability is maximal in
98 # symbolic form
99 self.y_pred = T.argmax(self.p_y_given_x, axis=1)
100
101 # keep track of model input
102 self.input = input
103
104 def negative_log_likelihood(self, y):
105 """Return the negative log-likelihood of the prediction of this model
106 under a given target distribution.
107
108 .. math::
109

Callers 1

cg_optimization_mnistFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected