In Rumelhart, Hinton and Williams (1986) back-propagation learns to tell whether a row of binary input units is symmetric about its centre, using only two hidden units. A network like that can be checked exhaustively, because a row of binary units has only possible states. Write the checker.
Implement symmetry_report(W1, b1, w2, b2) for a network with one layer of hidden units.
Network. W1 has shape (h, n): W1[k][i] is the weight from input to hidden unit , and b1[k] is its bias. w2[k] is the weight from hidden unit to the single output unit and b2 is the output bias. Every hidden unit and the output unit is logistic:
Inputs to test. All binary vectors , in the order of itertools.product([0, 1], repeat=n). A vector is symmetric when for every . The network says "symmetric" when .
Output: a dict with keys
"n_symmetric": the number of symmetric vectors (int)."accuracy": the fraction of the vectors the network classifies correctly (float)."errors": the misclassified vectors as strings of digits such as "100010", in enumeration order."sym_min": the smallest output on a symmetric vector, and "nonsym_max": the largest output on a non-symmetric vector (floats; use None if there is no vector of that kind)."unique_sums": one bool per hidden unit. Let . It is True when the binary settings of the first inputs give different values of (two values count as equal when they differ by less than ).