Search in sources :

Example 1 with RBFNetwork

use of smile.regression.RBFNetwork in project smile by haifengl.

the class ValidationTest method testTest_4args_2.

/**
     * Test of test method, of class Validation.
     */
@Test
public void testTest_4args_2() {
    System.out.println("test");
    ArffParser parser = new ArffParser();
    parser.setResponseIndex(6);
    try {
        AttributeDataset data = parser.parse(smile.data.parser.IOUtils.getTestDataFile("weka/cpu.arff"));
        double[] datay = data.toArray(new double[data.size()]);
        double[][] datax = data.toArray(new double[data.size()][]);
        Math.standardize(datax);
        int n = datax.length;
        int m = 3 * n / 4;
        double[][] x = new double[m][];
        double[] y = new double[m];
        double[][] testx = new double[n - m][];
        double[] testy = new double[n - m];
        int[] index = Math.permutate(n);
        for (int i = 0; i < m; i++) {
            x[i] = datax[index[i]];
            y[i] = datay[index[i]];
        }
        for (int i = m; i < n; i++) {
            testx[i - m] = datax[index[i]];
            testy[i - m] = datay[index[i]];
        }
        double[][] centers = new double[20][];
        RadialBasisFunction[] rbf = SmileUtils.learnGaussianRadialBasis(x, centers, 2);
        RBFNetwork<double[]> rkhs = new RBFNetwork<>(x, y, new EuclideanDistance(), rbf, centers);
        RegressionMeasure[] measures = { new RMSE(), new AbsoluteDeviation() };
        double[] results = Validation.test(rkhs, testx, testy, measures);
        System.out.println("RMSE = " + results[0]);
        System.out.println("Absolute Deviation = " + results[1]);
    } catch (Exception ex) {
        System.err.println(ex);
    }
}
Also used : RadialBasisFunction(smile.math.rbf.RadialBasisFunction) AttributeDataset(smile.data.AttributeDataset) RBFNetwork(smile.regression.RBFNetwork) EuclideanDistance(smile.math.distance.EuclideanDistance) ArffParser(smile.data.parser.ArffParser) Test(org.junit.Test)

Example 2 with RBFNetwork

use of smile.regression.RBFNetwork in project smile by haifengl.

the class ValidationTest method testTest_3args_2.

/**
     * Test of test method, of class Validation.
     */
@Test
public void testTest_3args_2() {
    System.out.println("test");
    ArffParser parser = new ArffParser();
    parser.setResponseIndex(6);
    try {
        AttributeDataset data = parser.parse(smile.data.parser.IOUtils.getTestDataFile("weka/cpu.arff"));
        double[] datay = data.toArray(new double[data.size()]);
        double[][] datax = data.toArray(new double[data.size()][]);
        Math.standardize(datax);
        int n = datax.length;
        int m = 3 * n / 4;
        double[][] x = new double[m][];
        double[] y = new double[m];
        double[][] testx = new double[n - m][];
        double[] testy = new double[n - m];
        int[] index = Math.permutate(n);
        for (int i = 0; i < m; i++) {
            x[i] = datax[index[i]];
            y[i] = datay[index[i]];
        }
        for (int i = m; i < n; i++) {
            testx[i - m] = datax[index[i]];
            testy[i - m] = datay[index[i]];
        }
        double[][] centers = new double[20][];
        RadialBasisFunction[] rbf = SmileUtils.learnGaussianRadialBasis(x, centers, 2);
        RBFNetwork<double[]> rkhs = new RBFNetwork<>(x, y, new EuclideanDistance(), rbf, centers);
        double rmse = Validation.test(rkhs, testx, testy);
        System.out.println("RMSE = " + rmse);
    } catch (Exception ex) {
        System.err.println(ex);
    }
}
Also used : RadialBasisFunction(smile.math.rbf.RadialBasisFunction) AttributeDataset(smile.data.AttributeDataset) RBFNetwork(smile.regression.RBFNetwork) EuclideanDistance(smile.math.distance.EuclideanDistance) ArffParser(smile.data.parser.ArffParser) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 AttributeDataset (smile.data.AttributeDataset)2 ArffParser (smile.data.parser.ArffParser)2 EuclideanDistance (smile.math.distance.EuclideanDistance)2 RadialBasisFunction (smile.math.rbf.RadialBasisFunction)2 RBFNetwork (smile.regression.RBFNetwork)2