public override double ComputeCost(Vector theta)
{
double j = 0.0;
Matrix ThetaX = theta.Slice(0, (R.Rows * CollaborativeFeatures) - 1).Reshape(CollaborativeFeatures, VectorType.Col);
Matrix ThetaY = theta.Slice((R.Rows * CollaborativeFeatures), theta.Length - 1).Reshape(CollaborativeFeatures, VectorType.Col);
j = (1.0 / 2.0) * ((ThetaY * ThetaX.T).T - YReformed).Each(i => System.Math.Pow(i, 2.0)).Each((v, r, c) => v * R[r, c]).Sum();
if (Lambda != 0)
{
j = j + ((Lambda / 2.0) * (ThetaY.Each(i => System.Math.Pow(i, 2.0)).Sum()) + (Lambda / 2.0 * ThetaX.Each(i => System.Math.Pow(i, 2.0)).Sum()));
}
return j;
}