コード例 #1
0
ファイル: IOTests.cs プロジェクト: vcfriend/svmnet
        public void ReadProblem()
        {
            Problem expected = SVMUtilities.CreateTwoClassProblem(100);
            Problem actual   = Problem.Read("train0.problem");

            Assert.AreEqual(expected, actual);
        }
コード例 #2
0
ファイル: IOTests.cs プロジェクト: vcfriend/svmnet
        public void WriteProblem()
        {
            Problem prob = SVMUtilities.CreateTwoClassProblem(100);

            using (MemoryStream stream = new MemoryStream())
                using (StreamReader input = new StreamReader("train0.problem"))
                {
                    Problem.Write(stream, prob);
                    string expected = input.ReadToEnd().Replace("\r\n", "\n");
                    string actual   = Encoding.ASCII.GetString(stream.ToArray());
                    Assert.AreEqual(expected, actual);
                }
        }
コード例 #3
0
ファイル: IOTests.cs プロジェクト: vcfriend/svmnet
        public void ReadModel()
        {
            Problem        train     = SVMUtilities.CreateTwoClassProblem(100);
            Parameter      param     = new Parameter();
            RangeTransform transform = RangeTransform.Compute(train);
            Problem        scaled    = transform.Scale(train);

            param.KernelType = KernelType.LINEAR;

            Training.SetRandomSeed(SVMUtilities.TRAINING_SEED);
            Model expected = Training.Train(scaled, param);
            Model actual   = Model.Read("svm0.model");

            Assert.AreEqual(expected, actual);
        }
コード例 #4
0
ファイル: IOTests.cs プロジェクト: vcfriend/svmnet
        public void WriteModel()
        {
            Problem        train     = SVMUtilities.CreateTwoClassProblem(100);
            Parameter      param     = new Parameter();
            RangeTransform transform = RangeTransform.Compute(train);
            Problem        scaled    = transform.Scale(train);

            param.KernelType = KernelType.LINEAR;

            Training.SetRandomSeed(SVMUtilities.TRAINING_SEED);
            Model model = Training.Train(scaled, param);

            using (MemoryStream stream = new MemoryStream())
                using (StreamReader input = new StreamReader("svm0.model"))
                {
                    Model.Write(stream, model);
                    string expected = input.ReadToEnd().Replace("\r\n", "\n");
                    string actual   = Encoding.ASCII.GetString(stream.ToArray());
                    Assert.AreEqual(expected, actual);
                }
        }
コード例 #5
0
        private double testTwoClassModel(int count, SvmType svm, KernelType kernel, bool probability = false, string outputFile = null)
        {
            Problem        train     = SVMUtilities.CreateTwoClassProblem(count);
            Parameter      param     = new Parameter();
            RangeTransform transform = RangeTransform.Compute(train);
            Problem        scaled    = transform.Scale(train);

            param.Gamma       = .5;
            param.SvmType     = svm;
            param.KernelType  = kernel;
            param.Probability = probability;
            if (svm == SvmType.C_SVC)
            {
                param.Weights[-1] = 1;
                param.Weights[1]  = 1;
            }

            Model model = Training.Train(scaled, param);

            Problem test = SVMUtilities.CreateTwoClassProblem(count, false);

            scaled = transform.Scale(test);
            return(Prediction.Predict(scaled, outputFile, model, false));
        }