Examples of FeatureTransformer


Examples of org.apache.hama.ml.util.FeatureTransformer

    String costFunctionName = "SquaredError";
    int[] layerSizeArray = new int[] { 3, 2, 2, 3 };
    MultiLayerPerceptron mlp = new SmallMultiLayerPerceptron(learningRate,
        regularization, momentum, squashingFunctionName, costFunctionName,
        layerSizeArray);
    FeatureTransformer transformer = new DefaultFeatureTransformer();
    mlp.setFeatureTransformer(transformer);
    try {
      mlp.writeModelToFile(modelPath);
    } catch (IOException e) {
      e.printStackTrace();
    }

    try {
      // read the meta-data
      Configuration conf = new Configuration();
      FileSystem fs = FileSystem.get(conf);
      mlp = new SmallMultiLayerPerceptron(modelPath);
      assertEquals(mlp.getClass().getName(), mlp.getMLPType());
      assertEquals(learningRate, mlp.getLearningRate(), 0.001);
      assertEquals(regularization, mlp.isRegularization(), 0.001);
      assertEquals(layerSizeArray.length, mlp.getNumberOfLayers());
      assertEquals(momentum, mlp.getMomentum(), 0.001);
      assertEquals(squashingFunctionName, mlp.getSquashingFunctionName());
      assertEquals(costFunctionName, mlp.getCostFunctionName());
      assertArrayEquals(layerSizeArray, mlp.getLayerSizeArray());
      assertEquals(transformer.getClass().getName(), mlp.getFeatureTransformer().getClass().getName());
      // delete test file
      fs.delete(new Path(modelPath), true);
    } catch (IOException e) {
      e.printStackTrace();
    }
View Full Code Here

Examples of org.apache.hama.ml.util.FeatureTransformer

      for (DoubleMatrix mat : matrices) {
        MatrixWritable.write(mat, output);
      }

      // serialize the feature transformer
      FeatureTransformer transformer = new DefaultFeatureTransformer();
      Class<? extends FeatureTransformer> featureTransformerCls = transformer.getClass();
      byte[] featureTransformerBytes = SerializationUtils.serialize(featureTransformerCls);
      output.writeInt(featureTransformerBytes.length);
      output.write(featureTransformerBytes);
     
      output.close();
View Full Code Here

Examples of org.apache.hama.ml.util.FeatureTransformer

    int[] layerSizeArray = new int[] { 1, 5, 1 };
    SmallMultiLayerPerceptron mlp = new SmallMultiLayerPerceptron(learningRate,
        regularization, momentum, squashingFunctionName, costFunctionName,
        layerSizeArray);
   
    mlp.setFeatureTransformer(new FeatureTransformer() {

      @Override
      public DoubleVector transform(DoubleVector originalFeatures) {
        return originalFeatures.sliceUnsafe(originalFeatures.getDimension() / 2);
      }
View Full Code Here

Examples of org.apache.hama.ml.util.FeatureTransformer

    matrices[0] = new DenseDoubleMatrix(5, 3, 0.2);
    matrices[1] = new DenseDoubleMatrix(1, 6, 0.8);
    ann.setWeightMatrices(matrices);
    ann.setLearningStyle(LearningStyle.UNSUPERVISED);
   
    FeatureTransformer defaultFeatureTransformer = new DefaultFeatureTransformer();
    ann.setFeatureTransformer(defaultFeatureTransformer);
   

    // write to file
    String modelPath = "/tmp/testSmallLayeredNeuralNetworkReadWrite";
    ann.setModelPath(modelPath);
    try {
      ann.writeModelToFile();
    } catch (IOException e) {
      e.printStackTrace();
    }

    // read from file
    SmallLayeredNeuralNetwork annCopy = new SmallLayeredNeuralNetwork(modelPath);
    assertEquals(annCopy.getClass().getSimpleName(), annCopy.getModelType());
    assertEquals(modelPath, annCopy.getModelPath());
    assertEquals(learningRate, annCopy.getLearningRate(), 0.000001);
    assertEquals(momentumWeight, annCopy.getMomemtumWeight(), 0.000001);
    assertEquals(regularizationWeight, annCopy.getRegularizationWeight(),
        0.000001);
    assertEquals(TrainingMethod.GRADIENT_DESCENT, annCopy.getTrainingMethod());
    assertEquals(LearningStyle.UNSUPERVISED, annCopy.getLearningStyle());

    // compare weights
    DoubleMatrix[] weightsMatrices = annCopy.getWeightMatrices();
    for (int i = 0; i < weightsMatrices.length; ++i) {
      DoubleMatrix expectMat = matrices[i];
      DoubleMatrix actualMat = weightsMatrices[i];
      for (int j = 0; j < expectMat.getRowCount(); ++j) {
        for (int k = 0; k < expectMat.getColumnCount(); ++k) {
          assertEquals(expectMat.get(j, k), actualMat.get(j, k), 0.000001);
        }
      }
    }
   
    FeatureTransformer copyTransformer = annCopy.getFeatureTransformer();
    assertEquals(defaultFeatureTransformer.getClass().getName(), copyTransformer.getClass().getName());
  }
View Full Code Here

Examples of org.apache.hama.ml.util.FeatureTransformer

    ann.addLayer(1, true, FunctionFactory.createDoubleFunction("Sigmoid"));
    ann.setCostFunction(FunctionFactory
        .createDoubleDoubleFunction("CrossEntropy"));
    ann.setModelPath(modelPath);
   
    FeatureTransformer featureTransformer = new DefaultFeatureTransformer();
   
    ann.setFeatureTransformer(featureTransformer);

    long start = new Date().getTime();
    Map<String, String> trainingParameters = new HashMap<String, String>();
    trainingParameters.put("tasks", "5");
    trainingParameters.put("training.max.iterations", "2000");
    trainingParameters.put("training.batch.size", "300");
    trainingParameters.put("convergence.check.interval", "1000");
    ann.train(tmpDatasetPath, trainingParameters);
   

    long end = new Date().getTime();

    // validate results
    double errorRate = 0;
    // calculate the error on test instance
    for (double[] testInstance : testInstances) {
      DoubleVector instance = new DenseDoubleVector(testInstance);
      double expected = instance.get(instance.getDimension() - 1);
      instance = instance.slice(instance.getDimension() - 1);
      instance = featureTransformer.transform(instance);
      double actual = ann.getOutput(instance).get(0);
      if (actual < 0.5 && expected >= 0.5 || actual >= 0.5 && expected < 0.5) {
        ++errorRate;
      }
    }
View Full Code Here

Examples of org.geotools.gml.producer.FeatureTransformer

        public void javaToNative(Object object, TransferData transferData) {
            SimpleFeature feature = (SimpleFeature) object;
            DefaultFeatureCollection collection = new DefaultFeatureCollection();
            collection.add(feature);
            FeatureTransformer transformer = new FeatureTransformer();
            transformer.setIndentation(4);
            try {
                TextTransfer.getInstance().javaToNative(transformer.transform(collection),
                        transferData);
            } catch (TransformerException e) {
                throw (RuntimeException) new RuntimeException().initCause(e);
            }
        }
View Full Code Here

Examples of org.geotools.gml.producer.FeatureTransformer

        this.compressOutput = formatNameCompressed.equalsIgnoreCase(outputFormat);
        this.results = results;

        GetNearestRequest request = results.getRequest();
        GeoServer config = request.getWFS().getGeoServer();
        transformer = new FeatureTransformer();

        FeatureTypeNamespaces ftNames = transformer.getFeatureTypeNamespaces();
        int maxFeatures = 999;
        int serverMaxFeatures = config.getMaxFeatures();
View Full Code Here

Examples of org.geotools.gml.producer.FeatureTransformer

        OutputStream os = null;
        try {
            os = new FileOutputStream(outFile);

            // let's invoke the transformer
            FeatureTransformer ft = new FeatureTransformer();
            ft.setNumDecimals(16);
            ft.setNamespaceDeclarationEnabled(false);
            ft.getFeatureNamespaces().declarePrefix("topp",
                    curCollection.getSchema().getName().getNamespaceURI());
            ft.transform(curCollection, os);
        } finally {
            os.close();
        }

        return outFile;
View Full Code Here

Examples of org.geotools.gml.producer.FeatureTransformer

        prepare(request.getOutputFormat(), featureCollection, request);
        encode(output, featureCollection, request );
    }

    protected FeatureTransformer createTransformer() {
        return new FeatureTransformer();
    }
View Full Code Here

Examples of org.geotools.gml.producer.FeatureTransformer

            start("InlineFeature");
            try {
                final String ftName = featureType.getTypeName();
                final SimpleFeatureSource fs = dataStore.getFeatureSource(ftName);
                final SimpleFeatureCollection fc = fs.getFeatures();
                final FeatureTransformer ftrax = new FeatureTransformer();
                ftrax.setCollectionNamespace(null);
                ftrax.setCollectionPrefix(null);
                ftrax.setGmlPrefixing(true);
                ftrax.setIndentation(2);
                final CoordinateReferenceSystem crs = featureType.getGeometryDescriptor()
                        .getCoordinateReferenceSystem();
                String srsName = null;
                if (crs == null) {
                    LOGGER.warning("Null CRS in feature type named [" + ftName + "]. Ignore CRS");
                } else {
                    srsName = CRS.toSRS(crs, true); // single implementation of toSRS
                    if (srsName == null) {
                        // fallback on origional code
                        // assume the first named identifier of this CRS is its
                        // fully
                        // qualified code; e.g. authoriy and SRID
                        Set<ReferenceIdentifier> ids = crs.getIdentifiers();
                        if (ids == null || ids.isEmpty()) {
                            LOGGER.warning("Null or empty set of named identifiers " + "in CRS ["
                                    + crs + "] of feature type named [" + ftName + "]. Ignore CRS");
                        } else {
                            for (ReferenceIdentifier id : ids) {
                                if (id != null) {
                                    srsName = String.valueOf(id);
                                    break;
                                }
                            }
                        }
                    }
                    if (srsName != null) {
                        // Some Server implementations using older versions of this
                        // library barf on a fully qualified CRS name with messages
                        // like : "couldnt decode SRS - EPSG:EPSG:4326. currently
                        // only supporting EPSG #"; looks like they only needs the
                        // SRID. adjust
                        final int ndx = srsName.indexOf(':');
                        if (ndx > 0) {
                            LOGGER.info("Reducing CRS name [" + srsName + "] to its SRID");
                            srsName = srsName.substring(ndx + 1).trim();
                        }
                    }
                }
                if (srsName != null) {
                    ftrax.setSrsName(srsName);
                }
               
                final String defaultNS = this.getDefaultNamespace();
                ftrax.getFeatureTypeNamespaces().declareDefaultNamespace("", defaultNS);
                final String ns = featureType.getName().getNamespaceURI();
                if (ns == null) {
                    LOGGER.info("Null namespace URI in feature type named [" + ftName
                            + "]. Ignore namespace in features");
                } else {
                    // find the URI's prefix mapping in this namespace support
                    // delegate and use it; otherwise ignore it
                    final String prefix = this.nsSupport.getPrefix(ns);
                    if (prefix != null)
                        ftrax.getFeatureTypeNamespaces().declareNamespace(featureType, prefix, ns);
                }
                final Translator t = ftrax
                        .createTranslator(this.contentHandler);
                t.encode(fc);
            } catch (IOException ignored) {
            }
            end("InlineFeature");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.