Exemplo n.º 1
0
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        double width        = 0.8;
        int    C            = 1;
        double epsilon      = 1e-5;
        double tube_epsilon = 1e-2;

        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(traindata_real);
        RealFeatures   feats_test  = new RealFeatures(testdata_real);
        GaussianKernel kernel      = new GaussianKernel(feats_train, feats_train, width);

        RegressionLabels labels = new RegressionLabels(trainlab);

        LibSVR svr = new LibSVR(C, epsilon, kernel, labels);

        svr.set_tube_epsilon(tube_epsilon);
        svr.train();

        kernel.init(feats_train, feats_test);
        double[] out_labels = LabelsFactory.to_regression(svr.apply()).get_labels();

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

        modshogun.exit_shogun();
    }
Exemplo n.º 2
0
    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);
        }
    }
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();

        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_multiclass.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);
        MulticlassLabels labels = new MulticlassLabels(trainlab);

        GaussianNaiveBayes gnb = new GaussianNaiveBayes(feats_train, labels);

        gnb.train();
        double[] out_labels = LabelsFactory.to_multiclass(gnb.apply(feats_test)).get_labels();

        foreach (double item in out_labels)
        {
            Console.Write(item);
        }
    }
Exemplo n.º 5
0
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        int k = 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_multiclass.dat");

        RealFeatures      feats_train = new RealFeatures(traindata_real);
        RealFeatures      feats_test  = new RealFeatures(testdata_real);
        EuclideanDistance distance    = new EuclideanDistance(feats_train, feats_train);

        MulticlassLabels labels = new MulticlassLabels(trainlab);

        KNN knn = new KNN(k, distance, labels);

        knn.train();
        double[] out_labels = LabelsFactory.to_multiclass(knn.apply(feats_test)).get_labels();

        foreach (double item in out_labels)
        {
            Console.Write(item);
        }
    }
Exemplo n.º 6
0
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        double width = 0.8;
        double tau   = 1e-6;

        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(traindata_real);
        RealFeatures   feats_test  = new RealFeatures(testdata_real);
        GaussianKernel kernel      = new GaussianKernel(feats_train, feats_train, width);

        RegressionLabels labels = new RegressionLabels(trainlab);

        KernelRidgeRegression krr = new KernelRidgeRegression(tau, kernel, labels);

        krr.train(feats_train);

        kernel.init(feats_train, feats_test);
        double[] out_labels = LabelsFactory.to_regression(krr.apply()).get_labels();

        foreach (double item in out_labels)
        {
            Console.Write(item);
        }
    }
Exemplo n.º 7
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);
        }
    }
Exemplo n.º 8
0
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        double width    = 2.1;
        double epsilon  = 1e-5;
        double C        = 1.0;
        int    mkl_norm = 2;

        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_multiclass.dat");

        CombinedKernel   kernel      = new CombinedKernel();
        CombinedFeatures feats_train = new CombinedFeatures();
        CombinedFeatures feats_test  = new CombinedFeatures();

        RealFeatures subkfeats1_train = new RealFeatures(traindata_real);
        RealFeatures subkfeats1_test  = new RealFeatures(testdata_real);

        GaussianKernel subkernel = new GaussianKernel(10, width);

        feats_train.append_feature_obj(subkfeats1_train);
        feats_test.append_feature_obj(subkfeats1_test);
        kernel.append_kernel(subkernel);

        RealFeatures subkfeats2_train = new RealFeatures(traindata_real);
        RealFeatures subkfeats2_test  = new RealFeatures(testdata_real);

        LinearKernel subkernel2 = new LinearKernel();

        feats_train.append_feature_obj(subkfeats2_train);
        feats_test.append_feature_obj(subkfeats2_test);
        kernel.append_kernel(subkernel2);

        RealFeatures subkfeats3_train = new RealFeatures(traindata_real);
        RealFeatures subkfeats3_test  = new RealFeatures(testdata_real);

        PolyKernel subkernel3 = new PolyKernel(10, 2);

        feats_train.append_feature_obj(subkfeats3_train);
        feats_test.append_feature_obj(subkfeats3_test);
        kernel.append_kernel(subkernel3);

        kernel.init(feats_train, feats_train);

        MulticlassLabels labels = new MulticlassLabels(trainlab);

        MKLMulticlass mkl = new MKLMulticlass(C, kernel, labels);

        mkl.set_epsilon(epsilon);
        mkl.set_mkl_epsilon(epsilon);
        mkl.set_mkl_norm(mkl_norm);

        mkl.train();

        kernel.init(feats_train, feats_test);
        double[] outMatrix = LabelsFactory.to_multiclass(mkl.apply()).get_labels();
    }
        /// <summary>
        /// Makes the labels once the boxes in the Shipment are populated.
        /// </summary>
        public void MakeBoxLabels()
        {
            if (Shipment.Boxes != null)
            {
                //set properties to label factory
                LabelsFactory.ShipmentBoxes   = Shipment.Boxes;
                LabelsFactory.AmzWarehouse    = Shipment.FullfillmentShipTo;
                LabelsFactory.ShipFromAddress = Shipment.CompanyShipFrom;
                LabelsFactory.BoxCount        = Shipment.Boxes.Count;

                //create the labels after the necessary items have been passed into the constructor
                LabelsFactory.CreateLabels();
            }
        }
Exemplo n.º 10
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();
    }
Exemplo n.º 11
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();
    }
Exemplo n.º 12
0
    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_multiclass.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);

        MulticlassLabels labels = new MulticlassLabels(trainlab);

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

        svm.set_batch_mode(false);
        svm.set_epsilon(epsilon);
        svm.train();
        double[] out_labels = LabelsFactory.to_multiclass(svm.apply(feats_train)).get_labels();

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

        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();
    }