subtract($target)->square()->mean()->mean(); } /** * Calculate the gradient of the cost function with respect to the output. * * @internal * * @param Matrix $output * @param Matrix $target * @return Matrix */ public function differentiate(Matrix $output, Matrix $target) : Matrix { return $output->subtract($target); } /** * Return the string representation of the object. * * @internal * * @return string */ public function __toString() : string { return 'Least Squares'; } }