DataSharp/Data/Analysis/SupportVectorMachine.cs
/// <summary>
/// Calculates weights of this SVM using formula in the paper.
/// </summary>
Calculates weights of this SVM using formula in the paper.
Calculates weights of this SVM using formula in the paper .
private void CalculateSupportVectors()
        {
            for (int i = 0; i < sampleCount; i++)
                weights += alphas[i] * labels[i] * dataMatrix.GetRow(i);
            LinkedList<int> nonZeroIndices = new LinkedList<int>();
            for (int i = 0; i < alphas.Count; i++)
            {
                if (alphas[i] > 0)
                    nonZeroIndices.AddLast(i);
            }
            supportVectors = new Matrix(nonZeroIndices.Count, dataMatrix.ColumnCount);
            supportVectorLabels = new Vector(nonZeroIndices.Count);
            supportVectorAlphas = new Vector(nonZeroIndices.Count);
            int rowCount = 0;
            foreach (int i in nonZeroIndices)
            {
                supportVectorLabels[rowCount] = labels[i];
                supportVectors.SetRow(rowCount, dataMatrix.GetRow(i));
                supportVectorAlphas[rowCount] = alphas[i];
                rowCount++;
            }
        }
private void CalculateSupportVectors ( ) { for ( int i = 0 ; i < sampleCount ; i ++ ) weights += alphas [ i ] * labels [ i ] * dataMatrix . GetRow ( i ) ; LinkedList < int > nonZeroIndices = new LinkedList < int > ( ) ; for ( int i = 0 ; i < alphas . Count ; i ++ ) { if ( alphas [ i ] > 0 ) nonZeroIndices . AddLast ( i ) ; } supportVectors = new Matrix ( nonZeroIndices . Count , dataMatrix . ColumnCount ) ; supportVectorLabels = new Vector ( nonZeroIndices . Count ) ; supportVectorAlphas = new Vector ( nonZeroIndices . Count ) ; int rowCount = 0 ; foreach ( int i in nonZeroIndices ) { supportVectorLabels [ rowCount ] = labels [ i ] ; supportVectors . SetRow ( rowCount , dataMatrix . GetRow ( i ) ) ; supportVectorAlphas [ rowCount ] = alphas [ i ] ; rowCount ++ ; } }
Calculates weights of this SVM using formula in the paper.
Calculates weights of this SVM using formula in the paper .