public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        double width   = 2.1;
        double epsilon = 1e-5;
        double C       = 1.0;

        double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat");
        double[,] testdata_real  = Load.load_numbers("../data/fm_test_real.dat");

        double[] trainlab = Load.load_labels("../data/label_train_twoclass.dat");

        RealFeatures feats_train = new RealFeatures();

        feats_train.set_feature_matrix(traindata_real);
        RealFeatures feats_test = new RealFeatures();

        feats_test.set_feature_matrix(testdata_real);

        GaussianKernel kernel = new GaussianKernel(feats_train, feats_train, width);

        BinaryLabels labels = new BinaryLabels(trainlab);

        GPBTSVM svm = new GPBTSVM(C, kernel, labels);

        svm.set_epsilon(epsilon);
        svm.train();
        kernel.init(feats_train, feats_test);
        double[] out_labels = LabelsFactory.to_binary(svm.apply()).get_labels();

        foreach (double item in out_labels)
        {
            Console.Write(item);
        }
    }
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        double learn_rate = 1.0;
        int    max_iter   = 1000;

        double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat");
        double[,] testdata_real  = Load.load_numbers("../data/fm_test_real.dat");

        double[]     trainlab    = Load.load_labels("../data/label_train_twoclass.dat");
        RealFeatures feats_train = new RealFeatures();

        feats_train.set_feature_matrix(traindata_real);
        RealFeatures feats_test = new RealFeatures();

        feats_test.set_feature_matrix(testdata_real);
        BinaryLabels       labels     = new BinaryLabels(trainlab);
        AveragedPerceptron perceptron = new AveragedPerceptron(feats_train, labels);

        perceptron.set_learn_rate(learn_rate);
        perceptron.set_max_iter(max_iter);
        perceptron.train();

        perceptron.set_features(feats_test);
        double[] out_labels = LabelsFactory.to_binary(perceptron.apply()).get_labels();

        foreach (double item in out_labels)
        {
            Console.Write(item);
        }
    }
Beispiel #3
0
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        double C       = 0.9;
        double epsilon = 1e-3;

        Math.init_random(17);
        double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat");
        double[,] testdata_real  = Load.load_numbers("../data/fm_test_real.dat");

        double[] trainlab = Load.load_labels("../data/label_train_twoclass.dat");

        RealFeatures feats_train = new RealFeatures();

        feats_train.set_feature_matrix(traindata_real);
        RealFeatures feats_test = new RealFeatures();

        feats_test.set_feature_matrix(testdata_real);

        BinaryLabels labels = new BinaryLabels(trainlab);

        LibLinear svm = new LibLinear(C, feats_train, labels);

        svm.set_liblinear_solver_type(LIBLINEAR_SOLVER_TYPE.L2R_L2LOSS_SVC_DUAL);
        svm.set_epsilon(epsilon);
        svm.set_bias_enabled(true);
        svm.train();
        svm.set_features(feats_test);
        double[] out_labels = LabelsFactory.to_binary(svm.apply()).get_labels();

        foreach (double item in out_labels)
        {
            Console.Write(item);
        }
    }
Beispiel #4
0
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        int gamma = 3;

        double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat");
        double[,] testdata_real  = Load.load_numbers("../data/fm_test_real.dat");

        double[] trainlab = Load.load_labels("../data/label_train_twoclass.dat");

        RealFeatures feats_train = new RealFeatures();

        feats_train.set_feature_matrix(traindata_real);
        RealFeatures feats_test = new RealFeatures();

        feats_test.set_feature_matrix(testdata_real);

        BinaryLabels labels = new BinaryLabels(trainlab);

        LDA lda = new LDA(gamma, feats_train, labels);

        lda.train();

        Console.WriteLine(lda.get_bias());

        //Console.WriteLine(lda.get_w().toString());
        foreach (double item in lda.get_w())
        {
            Console.Write(item);
        }


        lda.set_features(feats_test);
        double[] out_labels = LabelsFactory.to_binary(lda.apply()).get_labels();

        foreach (double item in out_labels)
        {
            Console.Write(item);
        }

        modshogun.exit_shogun();
    }
Beispiel #5
0
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();

        bool reverse = false;
        int  order   = 3;
        int  gap     = 0;

        String[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat");
        String[] fm_test_dna  = Load.load_dna("../data/fm_test_dna.dat");

        StringCharFeatures charfeat    = new StringCharFeatures(fm_train_dna, EAlphabet.DNA);
        StringWordFeatures feats_train = new StringWordFeatures(charfeat.get_alphabet());

        feats_train.obtain_from_char(charfeat, order - 1, order, gap, false);

        charfeat = new StringCharFeatures(fm_test_dna, EAlphabet.DNA);
        StringWordFeatures feats_test = new StringWordFeatures(charfeat.get_alphabet());

        feats_test.obtain_from_char(charfeat, order - 1, order, gap, false);

        BinaryLabels labels = new BinaryLabels(Load.load_labels("../data/label_train_dna.dat"));

        PluginEstimate pie = new PluginEstimate();

        pie.set_labels(labels);
        pie.set_features(feats_train);
        pie.train();

        SalzbergWordStringKernel kernel = new SalzbergWordStringKernel(feats_train, feats_train, pie, labels);

        double[,] km_train = kernel.get_kernel_matrix();
        kernel.init(feats_train, feats_test);
        pie.set_features(feats_test);
        LabelsFactory.to_binary(pie.apply()).get_labels();
        double[,] km_test = kernel.get_kernel_matrix();

        modshogun.exit_shogun();
    }
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();

        int    num   = 1000;
        double dist  = 1.0;
        double width = 2.1;
        double C     = 1.0;

        Random RandomNumber = new Random();

        double[,] traindata_real = new double[2, num * 2];
        for (int i = 0; i < num; i++)
        {
            traindata_real[0, i]       = RandomNumber.NextDouble() - dist;
            traindata_real[0, i + num] = RandomNumber.NextDouble() + dist;
            traindata_real[1, i]       = RandomNumber.NextDouble() - dist;
            traindata_real[1, i + num] = RandomNumber.NextDouble() + dist;
        }

        double[,] testdata_real = new double[2, num * 2];
        for (int i = 0; i < num; i++)
        {
            testdata_real[0, i]       = RandomNumber.NextDouble() - dist;
            testdata_real[0, i + num] = RandomNumber.NextDouble() + dist;
            testdata_real[1, i]       = RandomNumber.NextDouble() - dist;
            testdata_real[1, i + num] = RandomNumber.NextDouble() + dist;
        }

        double[] trainlab = new double[num * 2];
        for (int i = 0; i < num; i++)
        {
            trainlab[i]       = -1;
            trainlab[i + num] = 1;
        }

        double[] testlab = new double[num * 2];
        for (int i = 0; i < num; i++)
        {
            testlab[i]       = -1;
            testlab[i + num] = 1;
        }

        RealFeatures   feats_train = new RealFeatures(traindata_real);
        RealFeatures   feats_test  = new RealFeatures(testdata_real);
        GaussianKernel kernel      = new GaussianKernel(feats_train, feats_train, width);
        BinaryLabels   labels      = new BinaryLabels(trainlab);
        LibSVM         svm         = new LibSVM(C, kernel, labels);

        svm.train();

        double[] result = LabelsFactory.to_binary(svm.apply(feats_test)).get_labels();

        int err_num = 0;

        for (int i = 0; i < num; i++)
        {
            if (result[i] > 0)
            {
                err_num += 1;
            }
            if (result[i + num] < 0)
            {
                err_num += 1;
            }
        }

        double testerr = err_num / (2 * num);

        Console.WriteLine(testerr);
        modshogun.exit_shogun();
    }