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

Class LogisticRegression

code/logistic_sgd.py:52–172  ·  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 datapoints lie
71
72 :type n_out: int
73 :param n_out: number of output units, the dimension of the space in
74 which the labels lie
75
76 """
77 # start-snippet-1
78 # initialize with 0 the weights W as a matrix of shape (n_in, n_out)
79 self.W = theano.shared(
80 value=numpy.zeros(
81 (n_in, n_out),
82 dtype=theano.config.floatX
83 ),
84 name='W',
85 borrow=True
86 )
87 # initialize the biases b as a vector of n_out 0s
88 self.b = theano.shared(
89 value=numpy.zeros(
90 (n_out,),
91 dtype=theano.config.floatX
92 ),
93 name='b',
94 borrow=True
95 )
96
97 # symbolic expression for computing the matrix of class-membership
98 # probabilities
99 # Where:
100 # W is a matrix where column-k represent the separation hyperplane for
101 # class-k
102 # x is a matrix where row-j represents input training sample-j
103 # b is a vector where element-k represent the free parameter of
104 # hyperplane-k
105 self.p_y_given_x = T.nnet.softmax(T.dot(input, self.W) + self.b)
106
107 # symbolic description of how to compute prediction as class whose
108 # probability is maximal
109 self.y_pred = T.argmax(self.p_y_given_x, axis=1)

Callers 5

__init__Method · 0.90
__init__Method · 0.90
evaluate_lenet5Function · 0.90
__init__Method · 0.90
sgd_optimization_mnistFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected