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");

		// already tried double[][]
		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);

		Perceptron perceptron = new Perceptron(feats_train, labels);
		perceptron.set_learn_rate(learn_rate);
		perceptron.set_max_iter(max_iter);
		perceptron.train();

		perceptron.set_features(feats_test);
		//  already tried double[][]
		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();

		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);
	}
    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 = BinaryLabels.obtain_from_generic(perceptron.apply()).get_labels();

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

        modshogun.exit_shogun();
    }
Exemplo n.º 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);
		}

	}
    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 = BinaryLabels.obtain_from_generic(svm.apply()).get_labels();

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

        modshogun.exit_shogun();
    }
Exemplo n.º 6
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");

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

        LibSVMOneClass svm = new LibSVMOneClass(C, kernel);

        svm.set_epsilon(epsilon);
        svm.train();

        kernel.init(feats_train, feats_test);
        double[] out_labels = BinaryLabels.obtain_from_generic(svm.apply()).get_labels();

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

        modshogun.exit_shogun();
    }
Exemplo n.º 7
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 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 = BinaryLabels.obtain_from_generic(svm.apply()).get_labels();

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

        modshogun.exit_shogun();
    }
    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);
        BinaryLabels.obtain_from_generic(pie.apply()).get_labels();
        double[,] km_test=kernel.get_kernel_matrix();

        modshogun.exit_shogun();
    }
Exemplo n.º 10
0
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        double width = 1.6;

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

        RealFeatures   feats_train = new RealFeatures(train_real);
        GaussianKernel subkernel   = new GaussianKernel(feats_train, feats_train, width);

        BinaryLabels labels = new BinaryLabels(trainlab);

        AUCKernel kernel = new AUCKernel(0, subkernel);

        kernel.setup_auc_maximization(labels);

        double[,] km_train = kernel.get_kernel_matrix();

        int numRows = km_train.GetLength(0);
        int numCols = km_train.GetLength(1);

        Console.Write("km_train:\n");

        for (int i = 0; i < numRows; i++)
        {
            for (int j = 0; j < numCols; j++)
            {
                Console.Write(km_train[i, j] + " ");
            }
            Console.Write("\n");
        }
    }
Exemplo n.º 11
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);
        }
    }
    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);
        }
    }
Exemplo n.º 13
0
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        double width = 1.6;

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

        RealFeatures feats_train = new RealFeatures(train_real);
        GaussianKernel subkernel = new GaussianKernel(feats_train, feats_train, width);

        BinaryLabels labels = new BinaryLabels(trainlab);

        AUCKernel kernel = new AUCKernel(0, subkernel);
        kernel.setup_auc_maximization(labels);

        double[,] km_train = kernel.get_kernel_matrix();

        int numRows = km_train.GetLength(0);
        int numCols = km_train.GetLength(1);

        Console.Write("km_train:\n");

        for(int i = 0; i < numRows; i++){
            for(int j = 0; j < numCols; j++){
                Console.Write(km_train[i,j] +" ");
            }
            Console.Write("\n");
        }

        modshogun.exit_shogun();
    }
Exemplo n.º 14
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_twoclass.dat");

        RealFeatures tfeats  = new RealFeatures(traindata_real);
        PolyKernel   tkernel = new PolyKernel(10, 3);

        tkernel.init(tfeats, tfeats);
        double[,] K_train = tkernel.get_kernel_matrix();

        RealFeatures pfeats = new RealFeatures(testdata_real);

        tkernel.init(tfeats, pfeats);
        double[,] K_test = tkernel.get_kernel_matrix();

        CombinedFeatures feats_train = new CombinedFeatures();

        feats_train.append_feature_obj(new RealFeatures(traindata_real));

        CombinedKernel kernel = new CombinedKernel();

        kernel.append_kernel(new CustomKernel(K_train));
        kernel.append_kernel(new PolyKernel(10, 2));
        kernel.init(feats_train, feats_train);

        BinaryLabels labels = new BinaryLabels(trainlab);

        MKLClassification mkl = new MKLClassification();

        mkl.set_mkl_norm(1);
        mkl.set_kernel(kernel);
        mkl.set_labels(labels);

        mkl.train();

        CombinedFeatures feats_pred = new CombinedFeatures();

        feats_pred.append_feature_obj(new RealFeatures(testdata_real));

        CombinedKernel kernel2 = new CombinedKernel();

        kernel2.append_kernel(new CustomKernel(K_test));
        kernel2.append_kernel(new PolyKernel(10, 2));
        kernel2.init(feats_train, feats_pred);

        mkl.set_kernel(kernel2);
        mkl.apply();

        modshogun.exit_shogun();
    }
    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_twoclass.dat");

        RealFeatures tfeats = new RealFeatures(traindata_real);
        PolyKernel tkernel = new PolyKernel(10,3);
        tkernel.init(tfeats, tfeats);
        double[,] K_train = tkernel.get_kernel_matrix();

        RealFeatures pfeats = new RealFeatures(testdata_real);
        tkernel.init(tfeats, pfeats);
        double[,] K_test = tkernel.get_kernel_matrix();

        CombinedFeatures feats_train = new CombinedFeatures();
        feats_train.append_feature_obj(new RealFeatures(traindata_real));

        CombinedKernel kernel = new CombinedKernel();
           		kernel.append_kernel(new CustomKernel(K_train));
        kernel.append_kernel(new PolyKernel(10,2));
        kernel.init(feats_train, feats_train);

        BinaryLabels labels = new BinaryLabels(trainlab);

        MKLClassification mkl = new MKLClassification();
        mkl.set_mkl_norm(1);
        mkl.set_kernel(kernel);
        mkl.set_labels(labels);

        mkl.train();

        CombinedFeatures feats_pred = new CombinedFeatures();
        feats_pred.append_feature_obj(new RealFeatures(testdata_real));

        CombinedKernel kernel2 = new CombinedKernel();
        kernel2.append_kernel(new CustomKernel(K_test));
        kernel2.append_kernel(new PolyKernel(10, 2));
        kernel2.init(feats_train, feats_pred);

        mkl.set_kernel(kernel2);
        mkl.apply();

        modshogun.exit_shogun();
    }
    public static void Main(string[] argv)
    {
        modshogun.init_shogun_with_defaults();

        double[] ground_truth = Load.load_labels("../data/label_train_twoclass.dat");
        Random   RandomNumber = new Random();

        double[] predicted = new double[ground_truth.Length];
        for (int i = 0; i < ground_truth.Length; i++)
        {
            predicted[i] = RandomNumber.NextDouble();
        }

        BinaryLabels ground_truth_labels = new BinaryLabels(ground_truth);
        BinaryLabels predicted_labels    = new BinaryLabels(predicted);

        ContingencyTableEvaluation base_evaluator = new ContingencyTableEvaluation();

        base_evaluator.evaluate(predicted_labels, ground_truth_labels);

        AccuracyMeasure evaluator1 = new AccuracyMeasure();
        double          accuracy   = evaluator1.evaluate(predicted_labels, ground_truth_labels);

        ErrorRateMeasure evaluator2 = new ErrorRateMeasure();
        double           errorrate  = evaluator2.evaluate(predicted_labels, ground_truth_labels);

        BALMeasure evaluator3 = new BALMeasure();
        double     bal        = evaluator3.evaluate(predicted_labels, ground_truth_labels);

        WRACCMeasure evaluator4 = new WRACCMeasure();
        double       wracc      = evaluator4.evaluate(predicted_labels, ground_truth_labels);

        F1Measure evaluator5 = new F1Measure();
        double    f1         = evaluator5.evaluate(predicted_labels, ground_truth_labels);

        CrossCorrelationMeasure evaluator6 = new CrossCorrelationMeasure();
        double crosscorrelation            = evaluator6.evaluate(predicted_labels, ground_truth_labels);

        RecallMeasure evaluator7 = new RecallMeasure();
        double        recall     = evaluator7.evaluate(predicted_labels, ground_truth_labels);

        PrecisionMeasure evaluator8 = new PrecisionMeasure();
        double           precision  = evaluator8.evaluate(predicted_labels, ground_truth_labels);

        SpecificityMeasure evaluator9  = new SpecificityMeasure();
        double             specificity = evaluator9.evaluate(predicted_labels, ground_truth_labels);

        Console.Write("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}\n", accuracy, errorrate, bal, wracc, f1, crosscorrelation, recall, precision, specificity);

        modshogun.exit_shogun();
    }
    public static void Main(string[] argv)
    {
        modshogun.init_shogun_with_defaults();

        double[] ground_truth = Load.load_labels("../data/label_train_twoclass.dat");
        Random RandomNumber = new Random();
        double[] predicted = new double[ground_truth.Length];
        for (int i = 0; i < ground_truth.Length; i++) {
            predicted[i] = RandomNumber.NextDouble();
        }

        BinaryLabels ground_truth_labels = new BinaryLabels(ground_truth);
        BinaryLabels predicted_labels = new BinaryLabels(predicted);

        ContingencyTableEvaluation base_evaluator = new ContingencyTableEvaluation();
        base_evaluator.evaluate(predicted_labels,ground_truth_labels);

        AccuracyMeasure evaluator1 = new AccuracyMeasure();
        double accuracy = evaluator1.evaluate(predicted_labels,ground_truth_labels);

        ErrorRateMeasure evaluator2 = new ErrorRateMeasure();
        double errorrate = evaluator2.evaluate(predicted_labels,ground_truth_labels);

        BALMeasure evaluator3 = new BALMeasure();
        double bal = evaluator3.evaluate(predicted_labels,ground_truth_labels);

        WRACCMeasure evaluator4 = new WRACCMeasure();
        double wracc = evaluator4.evaluate(predicted_labels,ground_truth_labels);

        F1Measure evaluator5 = new F1Measure();
        double f1 = evaluator5.evaluate(predicted_labels,ground_truth_labels);

        CrossCorrelationMeasure evaluator6 = new CrossCorrelationMeasure();
        double crosscorrelation = evaluator6.evaluate(predicted_labels,ground_truth_labels);

        RecallMeasure evaluator7 = new RecallMeasure();
        double recall = evaluator7.evaluate(predicted_labels,ground_truth_labels);

        PrecisionMeasure evaluator8 = new PrecisionMeasure();
        double precision = evaluator8.evaluate(predicted_labels,ground_truth_labels);

        SpecificityMeasure evaluator9 = new SpecificityMeasure();
        double specificity = evaluator9.evaluate(predicted_labels,ground_truth_labels);

        Console.Write("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}\n", accuracy, errorrate, bal, wracc, f1, crosscorrelation, recall, precision, specificity);

        modshogun.exit_shogun();
    }
Exemplo n.º 18
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 = BinaryLabels.obtain_from_generic(lda.apply()).get_labels();

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

        modshogun.exit_shogun();
    }
Exemplo n.º 19
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);
        BinaryLabels.obtain_from_generic(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 = BinaryLabels.obtain_from_generic(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();
    }