Examples of DistanceMeasure


Examples of com.aamend.hadoop.clustering.distance.DistanceMeasure

            throw new IllegalArgumentException(
                    "Distance measure is empty. " +
                            "It should be specified from Hadoop configuration"
            );
        }
        DistanceMeasure measure;
        try {
            Class<?> clazz = Class.forName(className);
            Object obj = clazz.newInstance();
            measure = (DistanceMeasure) obj;
        } catch (ClassNotFoundException e) {
            throw new IOException(e);
        } catch (InstantiationException e) {
            throw new IOException(e);
        } catch (IllegalAccessException e) {
            throw new IOException(e);
        }

        // Configure distance measure
        measure.configure(conf);
        return measure;
    }
View Full Code Here

Examples of org.apache.commons.math3.ml.distance.DistanceMeasure

        clusterer.cluster(null);
    }

    @Test
    public void testGetters() {
        final DistanceMeasure measure = new CanberraDistance();
        final RandomGenerator random = new JDKRandomGenerator();
        final FuzzyKMeansClusterer<DoublePoint> clusterer =
                new FuzzyKMeansClusterer<DoublePoint>(3, 2.0, 100, measure, 1e-6, random);

        Assert.assertEquals(3, clusterer.getK());
View Full Code Here

Examples of org.apache.commons.math3.ml.distance.DistanceMeasure

            = new OffsetFeatureInitializer(FeatureInitializerFactory.uniform(0, 0.1));
        final FeatureInitializer[] initArray = { init };

        final int netSize = 3;
        final Network net = new NeuronString(netSize, false, initArray).getNetwork();
        final DistanceMeasure dist = new EuclideanDistance();
        final LearningFactorFunction learning
            = LearningFactorFunctionFactory.exponentialDecay(1, 0.1, 100);
        final NeighbourhoodSizeFunction neighbourhood
            = NeighbourhoodSizeFunctionFactory.exponentialDecay(3, 1, 100);
        final UpdateAction update = new KohonenUpdateAction(dist, learning, neighbourhood);

        // The following test ensures that, after one "update",
        // 1. when the initial learning rate equal to 1, the best matching
        //    neuron's features are mapped to the input's features,
        // 2. when the initial neighbourhood is larger than the network's size,
        //    all neuron's features get closer to the input's features.

        final double[] features = new double[] { 0.3 };
        final double[] distancesBefore = new double[netSize];
        int count = 0;
        for (Neuron n : net) {
            distancesBefore[count++] = dist.compute(n.getFeatures(), features);
        }
        final Neuron bestBefore = MapUtils.findBest(features, net, dist);

        // Initial distance from the best match is larger than zero.
        Assert.assertTrue(dist.compute(bestBefore.getFeatures(), features) >= 0.2);

        update.update(net, features);

        final double[] distancesAfter = new double[netSize];
        count = 0;
        for (Neuron n : net) {
            distancesAfter[count++] = dist.compute(n.getFeatures(), features);
        }
        final Neuron bestAfter = MapUtils.findBest(features, net, dist);

        Assert.assertEquals(bestBefore, bestAfter);
        // Distance is now zero.
        Assert.assertEquals(0, dist.compute(bestAfter.getFeatures(), features), 0d);

        for (int i = 0; i < netSize; i++) {
            // All distances have decreased.
            Assert.assertTrue(distancesAfter[i] < distancesBefore[i]);
        }
View Full Code Here

Examples of org.apache.commons.math3.ml.distance.DistanceMeasure

        clusterer.cluster(null);
    }

    @Test
    public void testGetters() {
        final DistanceMeasure measure = new CanberraDistance();
        final RandomGenerator random = new JDKRandomGenerator();
        final FuzzyKMeansClusterer<DoublePoint> clusterer =
                new FuzzyKMeansClusterer<DoublePoint>(3, 2.0, 100, measure, 1e-6, random);

        Assert.assertEquals(3, clusterer.getK());
View Full Code Here

Examples of org.apache.commons.math3.ml.distance.DistanceMeasure

        final FeatureInitializer init
            = new OffsetFeatureInitializer(FeatureInitializerFactory.uniform(-0.1, 0.1));
        final FeatureInitializer[] initArray = { init };

        final Network net = new NeuronString(3, false, initArray).getNetwork();
        final DistanceMeasure dist = new EuclideanDistance();

        final Set<Neuron> allBest = new HashSet<Neuron>();
        final Set<Neuron> best = new HashSet<Neuron>();
        double[][] features;
View Full Code Here

Examples of org.apache.mahout.common.distance.DistanceMeasure

  @Test
  public void testEpsilon() {
    final int dataSize = 10000;
    final int querySize = 30;
    final DistanceMeasure metric = new EuclideanDistanceMeasure();

    // these determine the dimension for the test. Each scale is multiplied by each multiplier
    final List<Integer> scales = ImmutableList.of(10);
    final List<Integer> multipliers = ImmutableList.of(1, 2, 3, 5);
View Full Code Here

Examples of org.apache.mahout.common.distance.DistanceMeasure

      clusters.add(cluster);
      value = (Writable) reader.getValueClass()
          .newInstance();
    }
   
    DistanceMeasure measure = new CosineDistanceMeasure();
    double max = 0;
    double min = Double.MAX_VALUE;
    double sum = 0;
    int count = 0;
    for (int i = 0; i < clusters.size(); i++) {
      for (int j = i + 1; j < clusters.size(); j++) {
        double d = measure.distance(clusters.get(i)
            .getCenter(), clusters.get(j).getCenter());
        min = Math.min(d, min);
        max = Math.max(d, max);
        sum += d;
        count++;
View Full Code Here

Examples of org.apache.mahout.common.distance.DistanceMeasure

      }
      List<Vector> pointsVectors = new ArrayList<Vector>();
      for(VectorWritable point : points)
        pointsVectors.add(point.get());
     
      DistanceMeasure measure = new EuclideanDistanceMeasure();
      FuzzyKMeansClusterer clusterer = new FuzzyKMeansClusterer(measure, 0.001, 2);
      FuzzyKMeansClusterer.runFuzzyKMeansIteration(pointsVectors, reference, clusterer);
     
      for (SoftCluster key : reference) {
        String clusterId = key.getIdentifier();
View Full Code Here

Examples of org.apache.mahout.common.distance.DistanceMeasure

  }
 
  /** Story: Test the reference implementation */
  public void testReferenceImplementation() throws Exception {
    List<Vector> points = getPoints(reference);
    DistanceMeasure measure = new EuclideanDistanceMeasure();
    // try all possible values of k
    for (int k = 0; k < points.size(); k++) {
      System.out.println("Test k=" + (k + 1) + ':');
      // pick k initial cluster centers at random
      List<Cluster> clusters = new ArrayList<Cluster>();
View Full Code Here

Examples of org.apache.mahout.common.distance.DistanceMeasure

    RandomUtils.useTestSeed();
    DisplayDirichlet.generateSamples();
    List<Vector> points = new ArrayList<Vector>();
    for (VectorWritable sample : sampleData)
      points.add(sample.get());
    DistanceMeasure measure = new ManhattanDistanceMeasure();
    List<SoftCluster> initialClusters = new ArrayList<SoftCluster>();
   
    k = 3;
    int i = 0;
    for (Vector point : points) {
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.