Exemplo n.º 1
0
 def __init__(self, dimensions, onIteration=None, initial_weights=None):
     self.dimensions = dimensions
     if initial_weights is not None:
         self.weights = initial_weights
     self.weights = normalize([0.000001 for _ in xrange(dimensions)])
     self.bias = 0.0
     self.cached_weights = normalize([0.000001 for _ in xrange(dimensions)])
     self.cached_bias = 0.0
     self.counter = 1.0
     self.onIteration = onIteration
Exemplo n.º 2
0
def gen_random_training_data(num_examples, dimensions, initial_weights=None, initial_bias=None):
    if initial_weights is None:
        weights = normalize([random.uniform(-1, 1) for _ in xrange(dimensions)])
    else:
        weights = initial_weights
    if initial_bias is None:
        bias = random.uniform(-1, 1)
    else:
        bias = initial_bias
    training_data = []
    for _ in xrange(num_examples):
        feature_vector = [random.uniform(-1, 1) for _ in xrange(dimensions)]
        classification = classify(feature_vector, weights, bias)
        training_data.append((feature_vector, classification))
    return training_data, weights, bias