コード例 #1
0
ファイル: Backup.cs プロジェクト: duanbb/PhD-CSharp
        static public void SVMCrowdScaleForRegression(int trainNumber)
        {
            string folderName = trainNumber + "Regression";

            SVMLearn svmLearn = new SVMLearn();
            svmLearn.mode = Mode.Regression;
            svmLearn.kernelType = Kernel.Polynomial;
            svmLearn.ExecuteLearner("svm_learn.exe", folderName + "CrowdScale/train.dat", folderName + "CrowdScale/model.txt", folderName + "CrowdScale/learnLog.txt", false);
            new SVMClassify().ExecuteClassifier("svm_classify.exe", folderName + "CrowdScale/test.dat", folderName + "CrowdScale/model.txt", folderName + "CrowdScale/output.txt", folderName + "CrowdScale/clasifylog.txt", false);
        }
コード例 #2
0
        static private void SVMExample()
        {
            SVMLearn svmLearn = new SVMLearn();

            svmLearn.ExecuteLearner("svm_learn.exe", "example/train.dat", "example/model.txt", "example/learnLog.txt", false);

            SVMClassify svmClassify = new SVMClassify();

            svmClassify.ExecuteClassifier("svm_classify.exe", "example/test.dat", "example/model.txt", "example/output.txt", "example/clasifylog.txt", false);
        }
コード例 #3
0
        static public void SVMCrowdScale(int numberOfTrain, Kernel kernel, int ParamD, double ParamG, double ParamS, double ParamC)
        {
            string   folderName = numberOfTrain + "Classification";
            SVMLearn svmLearn0  = new SVMLearn();

            svmLearn0.kernelType = kernel;
            svmLearn0.ParamD     = ParamD;
            svmLearn0.ParamG     = ParamG;
            svmLearn0.ParamS     = ParamS;
            svmLearn0.ParamC     = ParamC;
            svmLearn0.ExecuteLearner("svm_learn.exe", folderName + "CrowdScale/0train.dat", folderName + "CrowdScale/0model.txt", folderName + "CrowdScale/0learnLog.txt", false);
            new SVMClassify().ExecuteClassifier("svm_classify.exe", folderName + "CrowdScale/0test.dat", folderName + "CrowdScale/0model.txt", folderName + "CrowdScale/0output.txt", folderName + "CrowdScale/0clasifylog.txt", false);

            SVMLearn svmLearn1 = new SVMLearn();

            svmLearn1.kernelType = kernel;
            svmLearn1.ParamD     = ParamD;
            svmLearn1.ParamG     = ParamG;
            svmLearn1.ParamS     = ParamS;
            svmLearn1.ParamC     = ParamC;
            svmLearn1.ExecuteLearner("svm_learn.exe", folderName + "CrowdScale/1train.dat", folderName + "CrowdScale/1model.txt", folderName + "CrowdScale/1learnLog.txt", false);
            new SVMClassify().ExecuteClassifier("svm_classify.exe", folderName + "CrowdScale/1test.dat", folderName + "CrowdScale/1model.txt", folderName + "CrowdScale/1output.txt", folderName + "CrowdScale/1clasifylog.txt", false);

            SVMLearn svmLearn2 = new SVMLearn();

            svmLearn2.kernelType = kernel;
            svmLearn2.ParamD     = ParamD;
            svmLearn2.ParamG     = ParamG;
            svmLearn2.ParamS     = ParamS;
            svmLearn2.ParamC     = ParamC;
            svmLearn2.ExecuteLearner("svm_learn.exe", folderName + "CrowdScale/2train.dat", folderName + "CrowdScale/2model.txt", folderName + "CrowdScale/2learnLog.txt", false);
            new SVMClassify().ExecuteClassifier("svm_classify.exe", folderName + "CrowdScale/2test.dat", folderName + "CrowdScale/2model.txt", folderName + "CrowdScale/2output.txt", folderName + "CrowdScale/2clasifylog.txt", false);

            SVMLearn svmLearn3 = new SVMLearn();

            svmLearn3.kernelType = kernel;
            svmLearn3.ParamD     = ParamD;
            svmLearn3.ParamG     = ParamG;
            svmLearn3.ParamS     = ParamS;
            svmLearn3.ParamC     = ParamC;
            svmLearn3.ExecuteLearner("svm_learn.exe", folderName + "CrowdScale/3train.dat", folderName + "CrowdScale/3model.txt", folderName + "CrowdScale/3learnLog.txt", false);
            new SVMClassify().ExecuteClassifier("svm_classify.exe", folderName + "CrowdScale/3test.dat", folderName + "CrowdScale/3model.txt", folderName + "CrowdScale/3output.txt", folderName + "CrowdScale/3clasifylog.txt", false);

            SVMLearn svmLearn4 = new SVMLearn();

            svmLearn4.kernelType = kernel;
            svmLearn4.ParamD     = ParamD;
            svmLearn4.ParamG     = ParamG;
            svmLearn4.ParamS     = ParamS;
            svmLearn4.ParamC     = ParamC;
            svmLearn4.ExecuteLearner("svm_learn.exe", folderName + "CrowdScale/4train.dat", folderName + "CrowdScale/4model.txt", folderName + "CrowdScale/4learnLog.txt", false);
            new SVMClassify().ExecuteClassifier("svm_classify.exe", folderName + "CrowdScale/4test.dat", folderName + "CrowdScale/4model.txt", folderName + "CrowdScale/4output.txt", folderName + "CrowdScale/4clasifylog.txt", false);
        }
コード例 #4
0
        public override void buildClassifier(Instances instances)
        {
            m_mustValue = null;
            var weights = MincostLiblinearClassifier.GetCount(instances);

            if (weights[0] == 0)
            {
                m_mustValue = 2;
                m_delta     = 0;
                return;
            }
            else if (weights[2] == 0)
            {
                m_mustValue = 0;
                m_delta     = 0;
                return;
            }

            m_sampleInstances = new Instances(instances, 0);

            // can classifier handle the data?
            getCapabilities().testWithFail(instances);

            Instances trainInstances = new Instances(instances, 0, instances.numInstances());

            AddInstancesAccordWeight(trainInstances);

            if (System.IO.File.Exists(m_trainingFile))
            {
                System.IO.File.Delete(m_trainingFile);
            }
            libsvmSaver.setInstances(trainInstances);
            libsvmSaver.setFile(new java.io.File(m_trainingFile));
            libsvmSaver.writeBatch();

            //ConvertNorminalToString(m_trainingFile);

            if (System.IO.File.Exists(m_modelFile))
            {
                System.IO.File.Delete(m_modelFile);
            }

            string[] options = Utils.splitOptions(m_trainArgs);
            int      idx     = Utils.getOptionPos('c', options);

            if (idx != -1)
            {
                double c = Convert.ToDouble(options[idx + 1]);
                c = c * trainInstances.numInstances() / 100.0;
                options[idx + 1] = c.ToString();
                m_trainArgs      = Utils.joinOptions(options);
            }

            learner.ExecuteLearner(s_learnerPath, m_trainingFile, m_modelFile, m_trainArgs);
            if (!System.IO.File.Exists(m_modelFile))
            {
                throw new InvalidOperationException(learner.Output);
            }
            m_modelData = System.IO.File.ReadAllBytes(m_modelFile);

            GetBestDelta(instances);

            if (System.IO.File.Exists(m_trainingFile))
            {
                System.IO.File.Delete(m_trainingFile);
            }
        }