ó
\ÿˆIc           @   sY   d  Z  d d l m Z d d l m Z d d l m Z d Z d „  Z d „  Z	 e ƒ  d S(	   sw   Test function to teach the neural network an XOR function.

This is a very basic test of Neural Network functionality.
iÿÿÿÿ(   t   TrainingExample(   t   Layer(   t   BasicNetworki    c    	      C   sC  d GHg  }  |  j  t d d g d g ƒ ƒ |  j  t d d g d g ƒ ƒ |  j  t d d g d g ƒ ƒ |  j  t d d g d g ƒ ƒ t j d ƒ } t j d | ƒ } t j d | ƒ } t | | | ƒ } d GHd } d } | j |  |  t | | ƒ d	 GHxA |  D]9 } | j	 | j
 ƒ } t rd
 | j
 | j | f GHqqWd S(   s¢   Train a neural network, and then test it to see how it does.

    Since we have so few examples, we use all of them for training,
    validation and testing.
    s   Setting up training examples...i    i   i   i   s   Training the network...g      à?gš™™™™™¹?s   Predicting...s
   %s;%s=> %sN(   t   appendR    R   t   OutputLayert   HiddenLayert
   InputLayerR   t   traint   stopping_criteriat   predictt   inputst   VERBOSEt   outputs(	   t   examplest   outputt   hiddent   inputt   networkt   learning_ratet   momentumt   examplet
   prediction(    (    s   test_NNExclusiveOr.pyt   main   s(    c         C   s9   |  d d k r% t  r% d G| GHq% n  |  d k r5 d Sd S(   s#   Define when to stop iterating.
    id   i    s   error:iÐ  i   (   R   (   t   num_iterationst   validation_errort   training_error(    (    s   test_NNExclusiveOr.pyR   1   s    N(
   t   __doc__t   Bio.NeuralNetwork.TrainingR    t!   Bio.NeuralNetwork.BackPropagationR   t)   Bio.NeuralNetwork.BackPropagation.NetworkR   R   R   R   (    (    (    s   test_NNExclusiveOr.pyt   <module>   s   	#	