private void ReadXmlSupportVectorFeatures(XmlReader rdr, out FeatureList supportFeatures) { var featurePoints = new List <double>(); rdr.MoveToContent(); //start walking down the tree if (rdr.NodeType == XmlNodeType.Element && rdr.Name == XmlXsupTag) { //at elements rdr.ReadStartElement(); // Read the xsup tag, to get to the contents //first bias while (rdr.NodeType != XmlNodeType.EndElement && !rdr.EOF) { switch (rdr.Name) { case XmlFeatureTag: featurePoints.Add(rdr.ReadElementContentAsDouble()); break; default: rdr.Skip(); break; } } if (!rdr.EOF) { rdr.ReadEndElement(); } } rdr.Close(); supportFeatures = new FeatureList(featurePoints); }
private void ReadValues(int scanNum, double parentMz, double xScore2, double xScore3, double xScoreRatio, double bScore2, double bScore3, double pk1Prob, double pk2Prob, double pk3Prob, double pk4Prob, double fscore2, double fscore3, double xScore2_CO, double xScore3_CO, double xScore2_H2O, double xScore3_H20, double xScore2_NH3, double xScore3_NH3) { var features = new List <double> { scanNum, parentMz, xScore2, xScore3, xScoreRatio, bScore2, bScore3, pk1Prob, pk2Prob, pk3Prob, pk4Prob, fscore2, fscore3, xScore2_CO, xScore3_CO, xScore2_H2O, xScore3_H20, xScore2_NH3, xScore3_NH3 }; var scanFeatures = new FeatureList(features); _testVector.Add(scanFeatures); for (var i = 0; i < NumFeatures; i++) { var val = features[i]; if (val <= _minValues[i]) { _minValues[i] = val; } if (val >= _maxValues[i]) { _maxValues[i] = val; } } }
public void SVMClassification(int startIndex, int stopIndex, int k_bias) { var chunk_xtest = new List <FeatureList>(); var chunk_xsup = new List <FeatureList>(); var numSupport = stopIndex - startIndex; var numTest = _testVector.Count; const int chunksize = 100; var ind1 = new List <int>(); var ind2 = new List <int>(); var chunks1 = (numSupport / chunksize) + 1; var chunks2 = (numTest / chunksize) + 1; // Performing y2(ind2)=y2(ind2)+ kchunk*w(ind1); for (var ch1 = 1; ch1 <= chunks1; ch1++) { //Get ind1 var low_ind1_index = (ch1 - 1) * chunksize + startIndex; var high_ind1_index = (ch1 * chunksize) - 1 + startIndex; if (high_ind1_index > stopIndex) { high_ind1_index = stopIndex; } ind1.Clear(); for (var index = 0; index <= (high_ind1_index - low_ind1_index); index++) { ind1.Add(index + low_ind1_index); } //Get support vectors chunk_xsup.Clear(); for (var j = 0; j < ind1.Count; j++) { var xsupIndex = ind1[j]; var thisSupportVector = new FeatureList(_supportVectors[xsupIndex]); chunk_xsup.Add(thisSupportVector); } for (var ch2 = 1; ch2 <= chunks2; ch2++) { //Get ind2 var low_ind2_index = (ch2 - 1) * chunksize; var high_ind2_index = (ch2 * chunksize) - 1; if (high_ind2_index > numTest) { high_ind2_index = numTest - 1; } ind2.Clear(); for (var index2 = 0; index2 <= (high_ind2_index - low_ind2_index); index2++) { ind2.Add(index2 + low_ind2_index); } //Get X vector chunk_xtest.Clear(); for (var j = 0; j < ind2.Count; j++) { var xIndex = ind2[j]; var thisTestVector = _testVector[xIndex]; chunk_xtest.Add(new FeatureList(thisTestVector)); } //Get the kernel var svmKernel = GetKernel(chunk_xtest, chunk_xsup); //Read in the weights w(ind1) var w = Matrix <double> .Build.Dense(ind1.Count, 1, 0); for (var i = 0; i < ind1.Count; i++) { var index = ind1[i]; w[i, 0] = _weights[index]; } // m1 = kchunk*w(ind1) var m1 = svmKernel.Multiply(w); //y2(ind2) += m1; for (var i = 0; i < ind2.Count; i++) { var index = ind2[i]; _predictedY[index] += m1[i, 0]; } } } //Add w0 for (var i = 0; i < _predictedY.Count; i++) { _predictedY[i] += _biases[k_bias]; } }
public FeatureList(FeatureList a) { Array.Copy(a._features, _features, NumFeatures); }