コード例 #1
0
ファイル: neural_net_impl.py プロジェクト: wyao/intro_to_ai
  def EncodeLabel(self, label):
    """
    Arguments:
    ---------
    label: a number between 0 and 9

    Returns:
    ---------
    a list of length 10 representing the distributed
    encoding of the output.

    Description:
    -----------
    Computes the distributed encoding of a given label.

    Example:
    -------
    0 => [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
    3 => [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

    Notes:
    ----
    Make sure that the elements of the encoding are floats.
    
    """
    target = Target()
    target.values = [1.0 if i == label else 0.0 for i in xrange(10)]
    return target
コード例 #2
0
  def EncodeLabel(self, label):
    """
    Arguments:
    ---------
    label: a number between 0 and 9

    Returns:
    ---------
    a list of length 10 representing the distributed
    encoding of the output.

    Description:
    -----------
    Computes the distributed encoding of a given label.

    Example:
    -------
    0 => [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
    3 => [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

    Notes:
    ----
    Make sure that the elements of the encoding are floats.

    """
    # Code seems to expect a Target instance rather than a simple list
    # encoded_label = [0.0] * 10
    # encoded_label[label] = 1.0
    # return encoded_label

    new_target = Target()
    new_target.values = [0.0] * 10
    new_target.values[label] = 1.0
    return new_target
コード例 #3
0
    def EncodeLabel(self, label):
        """
    Arguments:
    ---------
    label: a number between 0 and 9

    Returns:
    ---------
    a list of length 10 representing the distributed
    encoding of the output.

    Description:
    -----------
    Computes the distributed encoding of a given label.

    Example:
    -------
    0 => [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
    3 => [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

    Notes:
    ----
    Make sure that the elements of the encoding are floats.
    
    """

        List = [0.0 for x in range(10)]
        List[label] = 1.0
        target = Target()
        target.values = List
        return target
コード例 #4
0
ファイル: neural_net_impl.py プロジェクト: lucasdgf/cs181
def Train(network, inputs, targets, learning_rate, epochs):
  """
  Arguments:
  ---------
  network       : a NeuralNetwork instance
  inputs        : a list of Input instances
  targets       : a list of Target instances
  learning_rate : a learning_rate (a float)
  epochs        : a number of epochs (an integer)

  Returns:
  -------
  Nothing

  Description:
  -----------
  This function should train the network for a given number of epochs. That is,
  run the *Backprop* over the training set *epochs*-times
  """
  network.CheckComplete()

  # check if inputs and targets lists have the same length
  assert len(inputs) == len(targets)

  # run *epoches*-times
  for i in range(epochs):
    for j in range(len(inputs)):
      target = Target()
      target.values = targets[j]
      Backprop(network, inputs[j], target, learning_rate)
コード例 #5
0
  def EncodeLabel(self, label):
    """
    Arguments:
    ---------
    label: a number between 0 and 9

    Returns:
    ---------
    a list of length 10 representing the distributed
    encoding of the output.

    Description:
    -----------
    Computes the distributed encoding of a given label.

    Example:
    -------
    0 => [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
    3 => [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

    Notes:
    ----
    Make sure that the elements of the encoding are floats.

    """
    # Code seems to expect a Target instance rather than a simple list
    # encoded_label = [0.0] * 10
    # encoded_label[label] = 1.0
    # return encoded_label

    new_target = Target()
    new_target.values = [0.0] * 2
    new_target.values[label] = 1.0
    return new_target
コード例 #6
0
  def EncodeLabel(self, label):
    """
    Arguments:
    ---------
    // label: a number between 0 and 9
    label: a number between 0 and 1

    Returns:
    ---------
    // a list of length 10 representing the distributed
    encoding of the output.
    a list of length 2 representing the distributed
    encoding of the output

    Description:
    -----------
    Computes the distributed encoding of a given label.

    Example:
    -------
    0 => [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
    3 => [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

    Notes:
    ----
    Make sure that the elements of the encoding are floats.

    """
    t = Target()
    t.values = [0. for i in range(4)]
    t.values[label] = 1.
    # if label == 1:
    #   pick = random.choice([0, 1, 2])
    #   t.values[pick] = 1.
    # else:
    #   t.values[3] = 1.
    # print t.values
    return t