Compute the loss.

@param \Rubix\Tensor\Tensor $expected
@param \Rubix\Tensor\Tensor $output
@return float
14272
public function compute(Tensor $expected, Tensor $output) : float
    {
        $expected = $expected->clip(EPSILON, 1.);
        $output = $output->clip(EPSILON, 1.);

        return $expected->divide($output)->log()
            ->multiply($expected)->sum()->mean();
    }
458123
def get_loss(self, logits: mx.sym.Symbol, labels: mx.sym.Symbol) -> mx.sym.Symbol:
        
        raise NotImplementedError()
1325934
public function fail($label, $computed, $test, $expected) {
    if ($this->output && !$this->output->isQuiet()) {
      $this->output->write("<fg=red>F</fg=red>");
    }
    $this->failed += 1;
    
    $this->failures[] = array(
      'label'    => $label,
      'computed' => $computed,
      'test'     => $test,
      'expected' => $expected
    );
  }
143002
def _expectation(p, mean, none, kern, feat, nghp=None):
    
    Xmu, Xcov = p.mu, p.cov

    with tf.control_dependencies([tf.assert_equal(
            tf.shape(Xmu)[1], tf.constant(kern.input_dim, settings.int_type),
            message="Currently cannot handle slicing in exKxz.")]):
        Xmu = tf.identity(Xmu)

    with params_as_tensors_for(kern, feat):
        D = tf.shape(Xmu)[1]
        lengthscales = kern.lengthscales if kern.ARD \
            else tf.zeros((D,), dtype=settings.float_type) + kern.lengthscales

        chol_L_plus_Xcov = tf.cholesky(tf.matrix_diag(lengthscales ** 2) + Xcov)  # NxDxD
        all_diffs = tf.transpose(feat.Z) - tf.expand_dims(Xmu, 2)  # NxDxM

        sqrt_det_L = tf.reduce_prod(lengthscales)
        sqrt_det_L_plus_Xcov = tf.exp(tf.reduce_sum(tf.log(tf.matrix_diag_part(chol_L_plus_Xcov)), axis=1))
        determinants = sqrt_det_L / sqrt_det_L_plus_Xcov  # N

        exponent_mahalanobis = tf.cholesky_solve(chol_L_plus_Xcov, all_diffs)  # NxDxM
        non_exponent_term = tf.matmul(Xcov, exponent_mahalanobis, transpose_a=True)
        non_exponent_term = tf.expand_dims(Xmu, 2) + non_exponent_term  # NxDxM

        exponent_mahalanobis = tf.reduce_sum(all_diffs * exponent_mahalanobis, 1)  # NxM
        exponent_mahalanobis = tf.exp(-0.5 * exponent_mahalanobis)  # NxM

        return kern.variance * (determinants[:, None] * exponent_mahalanobis)[:, None, :] * non_exponent_term
905531
public function compareString($expected,$actual)
	{
		$expected.="\0";
		$actual.="\0";
		$expectedLength=$this->strlen($expected);
		$actualLength=$this->strlen($actual);
		$diff=$expectedLength-$actualLength;
		for($i=0;$i<$actualLength;$i++)
			$diff|=(ord($actual[$i])^ord($expected[$i%$expectedLength]));
		return $diff===0;
	}
370753
def compute_output(self, o, output_shape=None):
    
    if self.combine_dims:
      o = mtf.transpose(o, o.shape - self.o_dims + self.o_dims)
      o = mtf.replace_dimensions(o, self.o_dims, self.wo.shape.dims[0])
      reduced_dims = [self.wo.shape.dims[0]]
    else:
      reduced_dims = self.o_dims
    return mtf.einsum(
        [o, self.wo], output_shape=output_shape, reduced_dims=reduced_dims)
402570
def mean_squared_error(pred:Tensor, targ:Tensor)->Rank0Tensor:
    ""
    pred,targ = flatten_check(pred,targ)
    return F.mse_loss(pred, targ)
49404
public static function match($actual, $expected)
    {
        $length = static::actual($actual);
        static::_buildDescription($actual, $length, $expected);

        return $length === $expected;
    }
1169160
def _expectation(p, mean1, none1, mean2, none2, nghp=None):
    
    with params_as_tensors_for(mean2):
        N = tf.shape(p.mu)[0]
        e_xxt = p.cov + (p.mu[:, :, None] * p.mu[:, None, :])  # NxDxD
        e_xxt_A = tf.matmul(e_xxt, tf.tile(mean2.A[None, ...], (N, 1, 1)))  # NxDxQ
        e_x_bt = p.mu[:, :, None] * mean2.b[None, None, :]  # NxDxQ

        return e_xxt_A + e_x_bt
31583
private function verifyOutput($output) {
        $output = trim($output);
        $result = 'unknown';
        if (preg_match('/: ([^:]+)$/', $output, $matches) ) {
            $result = $matches[1];
        }

        $this->message = $result;

        if (array_key_exists($result, $this->messageStatus) ) {
            $this->status = $this->messageStatus[$result];
        }
        else {
            $this->status = $this->messageStatus['unknown'];
        }

        return ($this->status === 0);
    }
340624
private function handleOutput(string $output): self
    {
        $this->output .= $output;

        if (!self::inTest()) {
            echo $output;
        }

        return $this;
    }
109260
public function is($actual, $expected)
	{
		if (!is_scalar($actual) || !is_scalar($expected)) {
			throw new \Exception("'try/predict-is' can only compare scalar values. 'try/predict' for complex predictions.");
		}

		if ($actual !== $expected) {
			throw new \Exception("Expected '$expected', but got '$actual'.");
		}
	}
126754
public static function match($actual, $expected)
    {
        $actual = static::_nl($actual);
        $expected = static::_nl($expected);
        return $actual == $expected;
    }
229009
def _expectation(p, mean1, none1, mean2, none2, nghp=None):
    
    with params_as_tensors_for(mean1):
        N = tf.shape(p.mu)[0]
        e_xxt = p.cov + (p.mu[:, :, None] * p.mu[:, None, :])  # NxDxD
        e_A_xxt = tf.matmul(tf.tile(mean1.A[None, ...], (N, 1, 1)), e_xxt, transpose_a=True)  # NxQxD
        e_b_xt = mean1.b[None, :, None] * p.mu[:, None, :]  # NxQxD

        return e_A_xxt + e_b_xt
320279
public function assertSameSize($expected, $message = '')
    {
        Assert::assertSameSize($expected, $this->getData(), $message);

        return $this;
    }
899868
public function addOutput($output)
    {
        if (!$this->getOutputs()) {
            return $this->setOutputs(array($output));
        } else {
            return $this->setOutputs(
                array_merge($this->getOutputs(), array($output))
            );
        }
    }
860634
private double computeOutputError(double[] output, double[] gradient) {
        if (output.length != outputLayer.units) {
            throw new IllegalArgumentException(String.format("Invalid output vector size: %d, expected: %d", output.length, outputLayer.units));
        }

        double error = 0.0;
        for (int i = 0; i < outputLayer.units; i++) {
            double out = outputLayer.output[i];
            double g = output[i] - out;

            if (errorFunction == ErrorFunction.LEAST_MEAN_SQUARES) {
                error += 0.5 * g * g;
            } else if (errorFunction == ErrorFunction.CROSS_ENTROPY) {
                if (activationFunction == ActivationFunction.SOFTMAX) {
                    error -= output[i] * log(out);
                } else if (activationFunction == ActivationFunction.LOGISTIC_SIGMOID) {
                    // We have only one output neuron in this case.
                    error = -output[i] * log(out) - (1.0 - output[i]) * log(1.0 - out);
                }
            }

            if (errorFunction == ErrorFunction.LEAST_MEAN_SQUARES && activationFunction == ActivationFunction.LOGISTIC_SIGMOID) {
                g *= out * (1.0 - out);
            }

            gradient[i] = g;
        }

        return error;
    }