Search in sources :

Example 11 with RadialBasisFunction

use of smile.math.rbf.RadialBasisFunction in project smile by haifengl.

the class RBFNetworkTest method testUSPS.

/**
     * Test of learn method, of class RBFNetwork.
     */
@Test
public void testUSPS() {
    System.out.println("USPS");
    DelimitedTextParser parser = new DelimitedTextParser();
    parser.setResponseIndex(new NominalAttribute("class"), 0);
    try {
        AttributeDataset train = parser.parse("USPS Train", smile.data.parser.IOUtils.getTestDataFile("usps/zip.train"));
        AttributeDataset test = parser.parse("USPS Test", smile.data.parser.IOUtils.getTestDataFile("usps/zip.test"));
        double[][] x = train.toArray(new double[train.size()][]);
        int[] y = train.toArray(new int[train.size()]);
        double[][] testx = test.toArray(new double[test.size()][]);
        int[] testy = test.toArray(new int[test.size()]);
        double[][] centers = new double[200][];
        RadialBasisFunction basis = SmileUtils.learnGaussianRadialBasis(x, centers);
        RBFNetwork<double[]> rbf = new RBFNetwork<>(x, y, new EuclideanDistance(), new GaussianRadialBasis(8.0), centers);
        int error = 0;
        for (int i = 0; i < testx.length; i++) {
            if (rbf.predict(testx[i]) != testy[i]) {
                error++;
            }
        }
        System.out.format("USPS error rate = %.2f%%%n", 100.0 * error / testx.length);
        assertTrue(error <= 150);
    } catch (Exception ex) {
        System.err.println(ex);
    }
}
Also used : DelimitedTextParser(smile.data.parser.DelimitedTextParser) RadialBasisFunction(smile.math.rbf.RadialBasisFunction) EuclideanDistance(smile.math.distance.EuclideanDistance) AttributeDataset(smile.data.AttributeDataset) NominalAttribute(smile.data.NominalAttribute) GaussianRadialBasis(smile.math.rbf.GaussianRadialBasis) Test(org.junit.Test)

Aggregations

EuclideanDistance (smile.math.distance.EuclideanDistance)11 RadialBasisFunction (smile.math.rbf.RadialBasisFunction)11 Test (org.junit.Test)10 AttributeDataset (smile.data.AttributeDataset)9 ArffParser (smile.data.parser.ArffParser)8 CrossValidation (smile.validation.CrossValidation)4 RBFNetwork (smile.regression.RBFNetwork)2 LOOCV (smile.validation.LOOCV)2 RBFNetwork (smile.classification.RBFNetwork)1 NominalAttribute (smile.data.NominalAttribute)1 DelimitedTextParser (smile.data.parser.DelimitedTextParser)1 GaussianRadialBasis (smile.math.rbf.GaussianRadialBasis)1