def get_unit_values(self, features):
    """Calculate the activation of each unit in a neural network.

    Args:
      features: a vector of feature values

    Returns:
      units, a list of lists of numbers, where
        units[a][b] is the activation of unit b in layer a
    """

    units = list()    
    units.append(features)

    for x in range(0, len(self.weights)):
      layer = list()
      for y in range(0, len(self.weights[x])):
        v = common.dot(units[x], self.weights[x][y])
        layer.append(self.activation(v))
          
      units.append(layer)

    # COMPLETE THIS IMPLEMENTATION
    #print units
    return units
Пример #2
0
  def predict(self, features):
    """Return the prediction given perceptron weights on an example.

    Args:
      features: A vector of features, [f1, f2, ... fn], all numbers

    Returns:
      1 if w1 * f1 + w2 * f2 + ... * wn * fn + t > 0
      0 otherwise
    """
    if not len(self.weights) == len(features):
      features = features + [1]

    if common.dot(self.weights, features) > 0:
      return 1
    else:
      return 0
Пример #3
0
  def get_unit_values(self, features):
    """Calculate the activation of each unit in a neural network.

    Args:
      features: a vector of feature values

    Returns:
      units, a list of lists of numbers, where
        units[a][b] is the activation of unit b in layer a
    """
    # COMPLETE THIS IMPLEMENTATION
    self.units = []
    self.units.append (features)
    for i in xrange (len (self.weights)):
      self.units.append ([])

    for layer in xrange (1, len (self.weights) + 1):
      for unitWeights in self.weights[layer - 1]:
         self.units[layer].append (self.activation (common.dot (unitWeights, self.units[layer - 1])))
    return self.units
  def predict(self, features):
    """Return the prediction given perceptron weights on an example.

    Args:
      features: A vector of features, [f1, f2, ... fn], all numbers

    Returns:
      1 if w1 * f1 + w2 * f2 + ... * wn * fn + t > 0
      0 otherwise
    """
    features.append(1)
    
    ret = 0
    value = common.dot(self.weights, features)
    
    if(value >0):
      ret = 1

    del features[-1]
    
    return ret
Пример #5
0
    def predict(self, features):
        """Return the prediction given perceptron weights on an example.

        Args:
          features: A vector of features, [f1, f2, ... fn], all numbers

        Returns:
          1 if w1 * f1 + w2 * f2 + ... * wn * fn + t > 0
          0 otherwise
        """
        # COMPLETE THIS IMPLEMENTATION
        # sum = 0
        # for f, w in zip(features, self.weights):
        #   sum = sum + f * w
        # features.append (1)
        _tt = 0
        if len(features) is not len(self.weights):
            _tt = self.weights[len(self.weights) - 1]
            self.weights.remove(_tt)
        self.sum = common.dot(features, self.weights)
        self.sum += _tt
        return common.step(self.sum)