From e7720fedcea487729468b12969f078c6c48d1c41 Mon Sep 17 00:00:00 2001 From: LWChris Date: Wed, 22 May 2019 17:15:59 +0200 Subject: [PATCH 1/2] All SV in saved model have 0 nodes --- LibSVMsharp/Core/svm_node.cs | 11 +++-------- LibSVMsharp/SVMNode.cs | 4 +--- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/LibSVMsharp/Core/svm_node.cs b/LibSVMsharp/Core/svm_node.cs index f237531..43e5e2d 100644 --- a/LibSVMsharp/Core/svm_node.cs +++ b/LibSVMsharp/Core/svm_node.cs @@ -1,16 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; +using System.Runtime.InteropServices; namespace LibSVMsharp.Core { [StructLayout(LayoutKind.Sequential)] public struct svm_node { - internal int index; - internal double value; + public int index; + public double value; } } diff --git a/LibSVMsharp/SVMNode.cs b/LibSVMsharp/SVMNode.cs index b73f398..00b1ddb 100644 --- a/LibSVMsharp/SVMNode.cs +++ b/LibSVMsharp/SVMNode.cs @@ -1,9 +1,7 @@ using LibSVMsharp.Core; using System; using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; namespace LibSVMsharp { @@ -51,7 +49,7 @@ public static SVMNode[] Convert(IntPtr ptr) { svm_node node = (svm_node)Marshal.PtrToStructure(i_ptr_nodes, typeof(svm_node)); i_ptr_nodes = IntPtr.Add(i_ptr_nodes, Marshal.SizeOf(typeof(svm_node))); - if (node.index > 0) + if (node.index >= 0) { nodes.Add(new SVMNode(node.index, node.value)); } From e7816ddcca9318fd237c5ed80bbb94b1123cc4ac Mon Sep 17 00:00:00 2001 From: LWChris Date: Wed, 22 May 2019 17:21:33 +0200 Subject: [PATCH 2/2] PredictValues extension called PredictProbability method; fixes #24 --- LibSVMsharp/Extensions/SVMProblemExtensions.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/LibSVMsharp/Extensions/SVMProblemExtensions.cs b/LibSVMsharp/Extensions/SVMProblemExtensions.cs index 2969e78..68ec6af 100644 --- a/LibSVMsharp/Extensions/SVMProblemExtensions.cs +++ b/LibSVMsharp/Extensions/SVMProblemExtensions.cs @@ -2,8 +2,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace LibSVMsharp.Extensions { @@ -82,7 +80,7 @@ public static double[] PredictValues(this SVMProblem problem, SVMModel model, ou double[] target = problem.X.Select(x => { double[] estimations; - double y = x.PredictProbability(ptr_model, out estimations); + double y = x.PredictValues(ptr_model, out estimations); temp.Add(estimations); return y; }).ToArray();