/**
  * Train the neural network for the specified pattern.
  * The neural network
  * can be trained for more than one pattern. To do this simply call the
  * train method more than once.
  *
  * @param
  *        	MLData pattern
  *        	The pattern to train for.
  */
 public function addPattern(MLData $pattern)
 {
     if ($pattern->size() != $this->getNeuronCount()) {
         throw new NeuralNetworkError("Network with " + $this->getNeuronCount() + " neurons, cannot learn a pattern of size " + $pattern->size());
     }
     // Create a row matrix from the input, convert boolean to bipolar
     $m2 = Matrix::createRowMatrix($pattern->getData());
     // Transpose the matrix and multiply by the original input matrix
     $m1 = MatrixMath\transpose($m2);
     $m3 = MatrixMath\multiply($m1, $m2);
     // matrix 3 should be square by now, so create an identity
     // matrix of the same size.
     $identity = MatrixMath\identity($m3->getRows());
     // subtract the identity matrix
     $m4 = MatrixMath\subtract($m3, $identity);
     // now add the calculated matrix, for this pattern, to the
     // existing weight matrix.
     $this->convertHopfieldMatrix($m4);
 }
 public function testIdentity()
 {
     try {
         MatrixMath\identity(0);
         $this->assertTrue(false);
     } catch (MatrixError $e) {
     }
     $checkData = [[1, 0], [0, 1]];
     $check = Matrix::matrixFromDoubles($checkData);
     $matrix = MatrixMath\identity(2);
     $this->assertTrue($check->equals($matrix));
 }