additionproblem.py
def generate_inputs_and_targets(length, num_examples):
  """ Generate addition-problem input, target example sequences.

  Example input sequence (transposed): `[[0.1 0.9 0.7 0.7 0.2],
                                         [0.0 1.0 0.0 0.0 1.0]]`
  Corresponding target: `1.1`

  Note that we follow Arjovsky et al., Unitary Evolution Recurrent Neural
  Networks, 2016 and mark one number randomly from the left half of the
  sequence and one randomly from the right half of the sequence.

  Args:
    length: An integer.
    num_examples: An integer.

  Returns:
    A tuple, `(inputs, targets)`. `inputs` is a 3-D float array with shape
    `[num_examples, length, 2]`. `targets` is a 1-D float array with shape
    `[num_examples]`.
  """
  inputs_1 = np.random.uniform(size=[num_examples, length])
  inputs_2 = np.zeros([num_examples, length], dtype=np.float)
  inputs_2[:, 0] = 1.0
  inputs_2[:, -1] = 1.0
  half_of_length, _ = divmod(length, 2)
  for row in inputs_2:
    np.random.shuffle(row[:half_of_length])
    np.random.shuffle(row[half_of_length:])
  inputs = np.concatenate([inputs_1[:, :, np.newaxis], inputs_2[:, :, np.newaxis]], axis=2)
  targets = np.sum(inputs_1 * inputs_2, axis=1)
  return inputs, targets
 Generate addition-problem input, target example sequences.

  Example input sequence (transposed): `[[0.1 0.9 0.7 0.7 0.2],
                                         [0.0 1.0 0.0 0.0 1.0]]`
  Corresponding target: `1.1`

  Note that we follow Arjovsky et al., Unitary Evolution Recurrent Neural
  Networks, 2016 and mark one number randomly from the left half of the
  sequence and one randomly from the right half of the sequence.

  Args:
    length: An integer.
    num_examples: An integer.

  Returns:
    A tuple, `(inputs, targets)`. `inputs` is a 3-D float array with shape
    `[num_examples, length, 2]`. `targets` is a 1-D float array with shape
    `[num_examples]`.
  
Generate addition-problem input, target example sequences.

Note that we follow Arjovsky et al., Unitary Evolution Recurrent Neural
Networks, 2016 and mark one number randomly from the left half of the
sequence and one randomly from the right half of the sequence.
Generate addition - problem input target example sequences . Note that we follow Arjovsky et al . Unitary Evolution Recurrent Neural Networks 2016 and mark one number randomly from the left half of the sequence and one randomly from the right half of the sequence .
def generate_inputs_and_targets(length, num_examples):
  inputs_1 = np.random.uniform(size=[num_examples, length])
  inputs_2 = np.zeros([num_examples, length], dtype=np.float)
  inputs_2[:, 0] = 1.0
  inputs_2[:, -1] = 1.0
  half_of_length, _ = divmod(length, 2)
  for row in inputs_2:
    np.random.shuffle(row[:half_of_length])
    np.random.shuffle(row[half_of_length:])
  inputs = np.concatenate([inputs_1[:, :, np.newaxis], inputs_2[:, :, np.newaxis]], axis=2)
  targets = np.sum(inputs_1 * inputs_2, axis=1)
  return inputs, targets
def generate_inputs_and_targets ( length , num_examples ) : inputs_1 = np . random . uniform ( size = [ num_examples , length ] ) inputs_2 = np . zeros ( [ num_examples , length ] , dtype = np . float ) inputs_2 [ : , 0 ] = 1.0 inputs_2 [ : , - 1 ] = 1.0 half_of_length , _ = divmod ( length , 2 ) for row in inputs_2 : np . random . shuffle ( row [ : half_of_length ] ) np . random . shuffle ( row [ half_of_length : ] ) inputs = np . concatenate ( [ inputs_1 [ : , : , np . newaxis ] , inputs_2 [ : , : , np . newaxis ] ] , axis = 2 ) targets = np . sum ( inputs_1 * inputs_2 , axis = 1 ) return inputs , targets
Generate addition-problem input, target example sequences.
Generate addition - problem input target example sequences .
""" Generate addition-problem input, target example sequences.

  Example input sequence (transposed): `[[0.1 0.9 0.7 0.7 0.2],
                                         [0.0 1.0 0.0 0.0 1.0]]`
  Corresponding target: `1.1`

  Note that we follow Arjovsky et al., Unitary Evolution Recurrent Neural
  Networks, 2016 and mark one number randomly from the left half of the
  sequence and one randomly from the right half of the sequence.

  Args:
    length: An integer.
    num_examples: An integer.

  Returns:
    A tuple, `(inputs, targets)`. `inputs` is a 3-D float array with shape
    `[num_examples, length, 2]`. `targets` is a 1-D float array with shape
    `[num_examples]`.
  """
A tuple, `(inputs, targets)`. `inputs` is a 3-D float array with shape
`[num_examples, length, 2]`. `targets` is a 1-D float array with shape
`[num_examples]`.
A tuple ` ( inputs targets ) ` . ` inputs ` is a 3 - D float array with shape ` [ num_examples length 2 ] ` . ` targets ` is a 1 - D float array with shape ` [ num_examples ] ` .
length
None
num_examples
None