Beispiel #1
0
        static void Main(string[] args)
        {
            // read the arguments and stick them into the config manager
            ConfigManager.Instance.ParseArguments(args);
  
            // next need to get the file name and read the elements into dense training data
            ITrainingData trainingData = new DenseTrainingData();

            // initialize the dot product kernel, stick it in the SVM algorithm 
            // TODO: use the arguments to determine the kernel to use
            // 1) dot product
            // 2) radial basis function kernel
            // 3) polynomial kernel (how to specify the degree of polynomial)
            IKernel kernel = new DotProductKernel();
            ISVMAlgorithm svm = new SMOSVMAlgorithm(trainingData, kernel);

            // SVM algorithm run
            CalculationStore data = svm.run();

            // print the weight vectors and 'b' constants
            data.Print();

            // record the results of the SVM run
            CalculationStore.RecordResults();
        }
Beispiel #2
0
        public void TrainingDataArgumentExceptionTest()
        {
            int lineIndex = 0;
            IFileManager testFileManager = new SVM_SMO.Fakes.StubIFileManager()
            {
                ReadLine = () =>
                {
                    if (lineIndex++ == 0) return "";
                    else return null;
                },
                ResetReader = () => { lineIndex = 0; }
            };

            ITrainingData trainingData = new DenseTrainingData(testFileManager);
        }
Beispiel #3
0
        public void TrainingDataTest()
        {
            int lineIndex = 0;
            string[] lines = new [] { "0 1 2 1", "2 -4 1.5 -1", "" };
            IFileManager testFileManager = new SVM_SMO.Fakes.StubIFileManager()
            {
                ReadLine = () => { return lines[lineIndex++]; },
                ResetReader = () => { lineIndex = 0; }
            };

            ITrainingData trainingData = new DenseTrainingData(testFileManager);

            Assert.AreEqual(0, trainingData.GetTrainingData(0, 0));
            Assert.AreEqual(1, trainingData.GetTrainingData(0, 1));
            Assert.AreEqual(2, trainingData.GetTrainingData(0, 2));
            Assert.AreEqual(1, trainingData.GetTrainingResult(0));

            Assert.AreEqual(2,   trainingData.GetTrainingData(1, 0));
            Assert.AreEqual(-4,  trainingData.GetTrainingData(1, 1));
            Assert.AreEqual(1.5, trainingData.GetTrainingData(1, 2));
            Assert.AreEqual(-1,  trainingData.GetTrainingResult(1));
        }