Beispiel #1
0
 def gradient(self, sample, y):
     vec = [y * 1] + [float(y) * x for x in sample]
     div = (1.0 + math.exp(float(y) * perceptron.inner_product((1,) + sample, self.weights)))
     vec = [-1.0 * x / div for x in vec]
     return vec
Beispiel #2
0
 def cross_entropy_error(self, sample, y):
     return math.log(1.0 + math.exp(-y * perceptron.inner_product((1,) + sample, self.weights)))
Beispiel #3
0
 def classify(self, input_vector):
     s = perceptron.inner_product(self.weights, (1,) + input_vector)
     return math.exp(s) / (1 + math.exp(s))