BP_LDA.LDA_Learn.ComputeSupervisedLoss C# (CSharp) Метод

ComputeSupervisedLoss() публичный статический Метод

public static ComputeSupervisedLoss ( SparseMatrix Dt, DenseMatrix y, string OutputType ) : float
Dt LinearAlgebra.SparseMatrix
y LinearAlgebra.DenseMatrix
OutputType string
Результат float
		public static float ComputeSupervisedLoss(SparseMatrix Dt, DenseMatrix y, string OutputType)
		{
			if (Dt.nCols != y.nCols || Dt.nRows != y.nRows)
			{
				throw new Exception("The numbers of samples from label and prediction do not match.");
			}
			DenseMatrix TmpDenseMat = new DenseMatrix(y);
			SparseMatrix TmpSparseMat = new SparseMatrix(Dt);
			DenseRowVector TmpDenseRowVec = new DenseRowVector(Dt.nCols);
			float TrainingLoss = 0.0f;
			switch (OutputType)
			{
			case "softmaxCE":
				MatrixOperation.ScalarAddMatrix(TmpDenseMat, y, 1e-20f);
				MatrixOperation.Log(TmpDenseMat);
				MatrixOperation.ElementwiseMatrixMultiplyMatrix(TmpSparseMat, Dt, TmpDenseMat);
				MatrixOperation.VerticalSumMatrix(TmpDenseRowVec, TmpSparseMat);
				TrainingLoss = TmpDenseRowVec.Sum() * (-1.0f);
				break;
			case "linearQuad":
				MatrixOperation.MatrixSubtractMatrix(TmpDenseMat, Dt);
				MatrixOperation.ElementwiseSquare(TmpDenseMat);
				MatrixOperation.VerticalSumMatrix(TmpDenseRowVec, TmpDenseMat);
				TrainingLoss = TmpDenseRowVec.Sum();
				break;
			case "linearCE":
				MatrixOperation.ScalarAddMatrix(TmpDenseMat, y, 1e-20f);
				MatrixOperation.Log(TmpDenseMat);
				MatrixOperation.ElementwiseMatrixMultiplyMatrix(TmpSparseMat, Dt, TmpDenseMat);
				MatrixOperation.VerticalSumMatrix(TmpDenseRowVec, TmpSparseMat);
				TrainingLoss = TmpDenseRowVec.Sum() * (-1.0f);
				break;
			default:
				throw new Exception("Unknown OutputType.");
			}

			return TrainingLoss;
		}
		public static float ComputeSupervisedLoss(SparseMatrix Dt, SparseMatrix y, string OutputType)

Same methods

LDA_Learn::ComputeSupervisedLoss ( SparseMatrix Dt, SparseMatrix y, string OutputType ) : float