1.something balabala...
it is the basic SVM classifier written in C#. Although there are some good tool(like SVMLIB), but the C/C++ code is too difficult for me to understand. If I use those packages, I feel like I just utilize black boxes to do alien job.
And in my working field(manufacturing/heavy industry),python is not so suitable to cooperate with PLC/Industrial control system/machine tools/plenty of sensors....balabala... Many python libs can not be used as well.
Therefore I decided to build a SVM using C# by my own.
I surveyed the internet and learned how to make the SVM work. I firstly used the method revealed in 1979, and it needs plenty of QR calculation, and the matrix evaluation made me crazy. So I turned to SMO algorithm. That is a genuis algorithm, which makes SVM highy efficient and fast. I use Simplified SMO as solver.
In this stage, this SVM can only classify 2 classes. it will extend to multi class SVM soon.
2.Training
2.1input
the type:
doule[][]inputvalues; //for input data,
int[]labels;// for labels
Take iris data for example:
the data length is 150, and it has 4 elements each row.
doule[][]IRIS_data=new double[150][];
for(int i=0;i<150;i++)
{
IRIS_data[i]={parameter1,parameter2,parameter3,parameter4};// not legeal C# syntax, but for expressing.
}
int[]labels is the array that contains +1/-1, to let machine distingulish the class of corresponding row.
for example: there are 2 kinds of iris
type A:+1, type B:-1
so the array labels will be like:
labels={1,-1,1....};// not legeal C# syntax, but for expressing.
2.2output
the output type :
double[]W_vector;// for W vector,
double b;//b coefficient
because the target function we want is:
double y=0;
for(int i=0;i<W_vector.Length;i++)y+=(W_vector[i])*(X[i]);
y+=b;
, use W and b to refer the result of new input data y >=+1 or y<=-1
3.predict
the data to be predicted is
double[][]newdata
and the output will be
int[]Result_Labels
4.reference:
[0]http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.43.4376&rep=rep1&type=pdf
[3]https://martin-thoma.com/solving-linear-equations-with-gaussian-elimination/