
'''Example using the theanets package for learning the XOR relation.'''

import climate
import logging
import numpy as np
import theanets

climate.enable_default_logging()

X = np.array([[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]])
Y = np.array([0, 1, 1, 0, ])

Xi = np.random.randint(0, 2, size=(256, 2))
train = [
    (Xi + 0.1 * np.random.randn(*Xi.shape)).astype('f'),
    (Xi[:, 0] ^ Xi[:, 1]).astype('f')[:, None],
]

e = theanets.Experiment(theanets.Regressor,
                        layers=(2, 2, 1),
                        learning_rate=0.1,
                        momentum=0.5,
                        patience=300)
e.run(train, train)

logging.info("Input:\n%s", X)
logging.info("XOR output:\n%s", Y)
logging.info("NN XOR predictions:\n%s", e.network(X.astype('f')))


'''Example using the theanets package for learning the XOR relation.'''

import climate
import logging
import numpy as np
import theanets

climate.enable_default_logging()

X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]], dtype='f')
Y = np.array([[0], [1], [1], [0]], dtype='f')

e = theanets.Experiment(theanets.Regressor, layers=(2, 2, 1))
e.train([X, Y], optimize='rprop', min_improvement=0.2, patience=500)

logging.info("Input:\n%s", X)
logging.info("XOR output:\n%s", Y)
logging.info("NN XOR predictions:\n%s", e.network(X.astype('f')).round(2))

Use rprop for xor example.
Use rprop for xor example.

  
  '''Example using the theanets package for learning the XOR relation.'''
  
  import climate
  import logging
  import numpy as np
  import theanets
  
  climate.enable_default_logging()
  
- X = np.array([[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]])
- Y = np.array([0, 1, 1, 0, ])
+ X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]], dtype='f')
+ Y = np.array([[0], [1], [1], [0]], dtype='f')
  
- Xi = np.random.randint(0, 2, size=(256, 2))
- train = [
-     (Xi + 0.1 * np.random.randn(*Xi.shape)).astype('f'),
-     (Xi[:, 0] ^ Xi[:, 1]).astype('f')[:, None],
- ]
- 
- e = theanets.Experiment(theanets.Regressor,
+ e = theanets.Experiment(theanets.Regressor, layers=(2, 2, 1))
+ e.train([X, Y], optimize='rprop', min_improvement=0.2, patience=500)
-                         layers=(2, 2, 1),
-                         learning_rate=0.1,
-                         momentum=0.5,
-                         patience=300)
- e.run(train, train)
  
  logging.info("Input:\n%s", X)
  logging.info("XOR output:\n%s", Y)
- logging.info("NN XOR predictions:\n%s", e.network(X.astype('f')))
+ logging.info("NN XOR predictions:\n%s", e.network(X.astype('f')).round(2))
  
Use rprop for xor example.
## Code Before:

'''Example using the theanets package for learning the XOR relation.'''

import climate
import logging
import numpy as np
import theanets

climate.enable_default_logging()

X = np.array([[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]])
Y = np.array([0, 1, 1, 0, ])

Xi = np.random.randint(0, 2, size=(256, 2))
train = [
    (Xi + 0.1 * np.random.randn(*Xi.shape)).astype('f'),
    (Xi[:, 0] ^ Xi[:, 1]).astype('f')[:, None],
]

e = theanets.Experiment(theanets.Regressor,
                        layers=(2, 2, 1),
                        learning_rate=0.1,
                        momentum=0.5,
                        patience=300)
e.run(train, train)

logging.info("Input:\n%s", X)
logging.info("XOR output:\n%s", Y)
logging.info("NN XOR predictions:\n%s", e.network(X.astype('f')))

## Instruction:
Use rprop for xor example.
## Code After:

'''Example using the theanets package for learning the XOR relation.'''

import climate
import logging
import numpy as np
import theanets

climate.enable_default_logging()

X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]], dtype='f')
Y = np.array([[0], [1], [1], [0]], dtype='f')

e = theanets.Experiment(theanets.Regressor, layers=(2, 2, 1))
e.train([X, Y], optimize='rprop', min_improvement=0.2, patience=500)

logging.info("Input:\n%s", X)
logging.info("XOR output:\n%s", Y)
logging.info("NN XOR predictions:\n%s", e.network(X.astype('f')).round(2))
