diff --git a/.gitignore b/.gitignore index 9e06052..8f0c1e6 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ obj Release Debug + +_ReSharper* \ No newline at end of file diff --git a/LibSvm/JavaPorts/StringTokenizer.cs b/LibSvm/JavaPorts/StringTokenizer.cs new file mode 100644 index 0000000..3ff4824 --- /dev/null +++ b/LibSvm/JavaPorts/StringTokenizer.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace LibSvm.JavaPorts +{ + class StringTokenizer + { + private readonly IList _tokens; + private int currentToken = -1; + private static readonly char[] DefaultDelimeters = new[] {' ', '\t', '\n', '\r', '\f',}; + + public StringTokenizer(string untokenizedString) : this(untokenizedString, DefaultDelimeters) + { + } + + public StringTokenizer(string untokenizedString, char[] delimiters) + { + _tokens = untokenizedString.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); + } + + public string NextToken() + { + currentToken++; + return _tokens[currentToken]; + } + + public int CountTokens() + { + return _tokens.Count - currentToken; + } + } +} diff --git a/LibSvm/LibSvm.csproj b/LibSvm/LibSvm.csproj index f332d83..fd291e0 100644 --- a/LibSvm/LibSvm.csproj +++ b/LibSvm/LibSvm.csproj @@ -44,6 +44,7 @@ + diff --git a/LibSvm/Svm.cs b/LibSvm/Svm.cs index 4098f50..da8490c 100644 --- a/LibSvm/Svm.cs +++ b/LibSvm/Svm.cs @@ -1,7 +1,10 @@ using System; using System.Collections.Generic; +using System.Diagnostics; +using System.IO; using System.Linq; using System.Text; +using LibSvm.JavaPorts; namespace LibSvm { @@ -988,94 +991,94 @@ public static void CrossValidation(SvmProblem prob, SvmParameter param, int nr_f } } - //static readonly string[] svm_type_table = { "c_svc", "nu_svc", "one_class", "epsilon_svr", "nu_svr", }; - //static readonly string[] kernel_type_table = { "linear", "polynomial", "rbf", "sigmoid", "precomputed" }; + static readonly string[] svm_type_table = { "c_svc", "nu_svc", "one_class", "epsilon_svr", "nu_svr", }; + static readonly string[] kernel_type_table = { "linear", "polynomial", "rbf", "sigmoid", "precomputed" }; - //implement later - //public static void svm_save_model(String model_file_name, svm_model model) - //{ - // DataOutputStream fp = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(model_file_name))); - - // svm_parameter param = model.param; - - // fp.writeBytes("svm_type "+svm_type_table[param.svm_type]+"\n"); - // fp.writeBytes("kernel_type "+kernel_type_table[param.kernel_type]+"\n"); - - // if(param.kernel_type == svm_parameter.POLY) - // fp.writeBytes("degree "+param.degree+"\n"); - - // if(param.kernel_type == svm_parameter.POLY || - // param.kernel_type == svm_parameter.RBF || - // param.kernel_type == svm_parameter.SIGMOID) - // fp.writeBytes("gamma "+param.gamma+"\n"); - - // if(param.kernel_type == svm_parameter.POLY || - // param.kernel_type == svm_parameter.SIGMOID) - // fp.writeBytes("coef0 "+param.coef0+"\n"); - - // int nr_class = model.nr_class; - // int l = model.l; - // fp.writeBytes("nr_class "+nr_class+"\n"); - // fp.writeBytes("total_sv "+l+"\n"); - - // { - // fp.writeBytes("rho"); - // for(int i=0;i