Examples of Centroid


Examples of eu.stratosphere.example.java.clustering.KMeans.Centroid

public class KMeansData {

  public static DataSet<Centroid> getDefaultCentroidDataSet(ExecutionEnvironment env) {
   
    return env.fromElements(
        new Centroid(1, -31.85, -44.77),
        new Centroid(2, 35.16, 17.46),
        new Centroid(3, -5.16, 21.93),
        new Centroid(4, -24.06, 6.81)
        );
  }
View Full Code Here

Examples of fuzzy4j.flc.defuzzify.Centroid

                .when().var(room).is(cold).then().var(effort).is(high)
                .when().var(room).is(ok).then().var(effort).is(medi)
                .when().var(room).is(hot).then().var(effort).is(low)
                .activationFunction(AlgebraicProduct.INSTANCE)
                .accumulationFunction(AlgebraicSum.INSTANCE)
                .defuzzifier(new Centroid())
                .create();

        InputInstance instance = new InputInstance().is(room, 60);

        System.out.println("fuzzy = " + impl.applyFuzzy(instance));
View Full Code Here

Examples of fuzzy4j.flc.defuzzify.Centroid

        FLC impl = ControllerBuilder.newBuilder()
                .when().var(service).is(poor).or().var(food).is(rancid).then().var(tip).is(cheap)
                .when().var(service).is(good).then().var(tip).is(average)
                .when().var(service).is(excellent).then().var(tip).is(generous)
                .defuzzifier(new Centroid())
                .create();

        Map<Variable, Double> map=new HashMap<Variable, Double>();
        map.put(service, (double) 9);
        map.put(food, (double) 3);
View Full Code Here

Examples of fuzzy4j.flc.defuzzify.Centroid

        FLC impl = ControllerBuilder.newBuilder()
                .when().var(service).is(poor).and().var(food).is(rancid).then().var(tip).is(cheap)
                .activationFunction(AlgebraicProduct.INSTANCE)
                .accumulationFunction(AlgebraicSum.INSTANCE)
                .defuzzifier(new Centroid())
                .create();

        Map<Variable, Double> map=new HashMap<Variable, Double>();
        map.put(service, (double) 0);
        map.put(food, (double) 0);
View Full Code Here

Examples of fuzzy4j.flc.defuzzify.Centroid

        Variable paracetamol = output("paracetamol", none, moderate);

        FLC impl = ControllerBuilder.newBuilder()
                .when().var(temp).is(not(high)).then().var(paracetamol).is(none)
                .when().var(temp).is(high).then().var(paracetamol).is(moderate)
                .defuzzifier(new Centroid())
                .create();

        InputInstance instance = new InputInstance().is(temp, 37.0);

        System.out.println("normal.fuzzy = " + impl.applyFuzzy(instance));
View Full Code Here

Examples of org.apache.flink.examples.java.clustering.KMeans.Centroid

  public static DataSet<Centroid> getDefaultCentroidDataSet(ExecutionEnvironment env) {
    List<Centroid> centroidList = new LinkedList<Centroid>();
    for (Object[] centroid : CENTROIDS) {
      centroidList.add(
          new Centroid((Integer) centroid[0], (Double) centroid[1], (Double) centroid[2]));
    }
    return env.fromCollection(centroidList);
  }
View Full Code Here

Examples of org.apache.mahout.math.Centroid

   */
  private void initializeSeeds(List<? extends WeightedVector> datapoints) {
    Preconditions.checkArgument(datapoints.size() > 1, "Must have at least two datapoints points to cluster " +
        "sensibly");
    // Compute the centroid of all of the datapoints.  This is then used to compute the squared radius of the datapoints.
    Centroid center = new Centroid(datapoints.iterator().next());
    for (WeightedVector row : Iterables.skip(datapoints, 1)) {
      center.update(row);
    }
    // Given the centroid, we can compute \Delta_1^2(X), the total squared distance for the datapoints
    // this accelerates seed selection.
    double radius = 0;
    DistanceMeasure l2 = new SquaredEuclideanDistanceMeasure();
    for (WeightedVector row : datapoints) {
      radius += l2.distance(row, center);
    }

    // Find the first seed c_1 (and conceptually the second, c_2) as might be done in the 2-means clustering so that
    // the probability of selecting c_1 and c_2 is proportional to || c_1 - c_2 ||^2.  This is done
    // by first selecting c_1 with probability:
    //
    // p(c_1) = sum_{c_1} || c_1 - c_2 ||^2 \over sum_{c_1, c_2} || c_1 - c_2 ||^2
    //
    // This can be simplified to:
    //
    // p(c_1) = \Delta_1^2(X) + n || c_1 - c ||^2 / (2 n \Delta_1^2(X))
    //
    // where c = \sum x / n and \Delta_1^2(X) = sum || x - c ||^2
    //
    // All subsequent seeds c_i (including c_2) can then be selected from the remaining points with probability
    // proportional to Pr(c_i == x_j) = min_{m < i} || c_m - x_j ||^2.

    // Multinomial distribution of vector indices for the selection seeds. These correspond to
    // the indices of the vectors in the original datapoints list.
    Multinomial<Integer> seedSelector = new Multinomial<Integer>();
    for (int i = 0; i < datapoints.size(); ++i) {
      double selectionProbability =
          radius + datapoints.size() * l2.distance(datapoints.get(i), center);
      seedSelector.add(i, selectionProbability);
    }

    Centroid c_1 = new Centroid((WeightedVector)datapoints.get(seedSelector.sample()).clone());
    c_1.setIndex(0);
    // Construct a set of weighted things which can be used for random selection.  Initial weights are
    // set to the squared distance from c_1
    for (int i = 0; i < datapoints.size(); ++i) {
      WeightedVector row = datapoints.get(i);
      final double w = l2.distance(c_1, row) * row.getWeight();
      seedSelector.set(i, w);
    }

    // From here, seeds are selected with probablity proportional to:
    //
    // r_i = min_{c_j} || x_i - c_j ||^2
    //
    // when we only have c_1, we have already set these distances and as we select each new
    // seed, we update the minimum distances.
    centroids.add(c_1);
    int clusterIndex = 1;
    while (centroids.size() < numClusters) {
      // Select according to weights.
      int seedIndex = seedSelector.sample();
      Centroid nextSeed = new Centroid((WeightedVector)datapoints.get(seedIndex).clone());
      nextSeed.setIndex(clusterIndex++);
      centroids.add(nextSeed);
      // Don't select this one again.
      seedSelector.set(seedIndex, 0);
      // Re-weight everything according to the minimum distance to a seed.
      for (int currSeedIndex : seedSelector) {
        WeightedVector curr = datapoints.get(currSeedIndex);
        double newWeight = nextSeed.getWeight() * l2.distance(nextSeed, curr);
        if (newWeight < seedSelector.getWeight(currSeedIndex)) {
          seedSelector.set(currSeedIndex, newWeight);
        }
      }
    }
View Full Code Here

Examples of org.apache.mahout.math.Centroid

      // Copies the current cluster centroids to newClusters and sets their weights to 0. This is
      // so we calculate the new centroids as we go through the datapoints.
      List<Centroid> newCentroids = Lists.newArrayList();
      for (Vector centroid : centroids) {
        // need a deep copy because we will mutate these values
        Centroid newCentroid = (Centroid)centroid.clone();
        newCentroid.setWeight(0);
        newCentroids.add(newCentroid);
      }

      // Pass over the datapoints computing new centroids.
      for (int j = 0; j < datapoints.size(); ++j) {
View Full Code Here

Examples of org.apache.mahout.math.Centroid

      int pow2J = 1 << (numDimensions - 1);
      for (int j = 0; j < numDimensions; ++j) {
        v.set(j, 1.0 / pow2J * (i & pow2J));
        pow2J >>= 1;
      }
      mean.add(new Centroid(i, v, 1));
      rowSamplers.add(new MultiNormal(distributionRadius, v));
    }

    // Sample the requested number of data points.
    List<Centroid> data = Lists.newArrayListWithCapacity(numDatapoints);
    for (int i = 0; i < numDatapoints; ++i) {
      data.add(new Centroid(i, rowSamplers.get(i % pow2N).sample(), 1));
    }
    return new Pair<List<Centroid>, List<Centroid>>(data, mean);
  }
View Full Code Here

Examples of org.apache.mahout.math.Centroid

  public static Centroid read(DataInput dataInput) throws IOException {
    int index = dataInput.readInt();
    double weight = dataInput.readDouble();
    Vector v = VectorWritable.readVector(dataInput);
    return new Centroid(index, v, weight);
  }
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.