コード例 #1
0
          @Override
          public void notify(final CentroidPairing<Object> pairing) {
            outputKeyWritable.set(pairing.getCentroid().getGroupID());
            final double extraFromItem[] = pairing.getPairedItem().getDimensionValues();
            final double extraCentroid[] = pairing.getCentroid().getDimensionValues();
            final Point p = centroidExtractor.getCentroid(pairing.getPairedItem().getWrappedItem());

            final Point centroid =
                centroidExtractor.getCentroid(pairing.getCentroid().getWrappedItem());

            // calculate error for dp
            // using identity matrix for the common covariance, therefore
            // E[(p - c)^-1 * cov * (p - c)] => (px - cx)^2 + (py - cy)^2
            double expectation = 0.0;
            for (int i = 0; i < extraCentroid.length; i++) {
              expectation += Math.pow(extraFromItem[i] - extraCentroid[i], 2);
            }
            expectation +=
                (Math.pow(p.getCoordinate().x - centroid.getCoordinate().x, 2)
                    + Math.pow(p.getCoordinate().y - centroid.getCoordinate().y, 2));
            // + Math.pow(
            // p.getCoordinate().z - centroid.getCoordinate().z,
            // 2));
            outputValWritable.set(expectation, 1);
          }
コード例 #2
0
    @Override
    public void reduce(
        final Text key,
        final Iterable<CountofDoubleWritable> values,
        final Reducer<Text, CountofDoubleWritable, Text, CountofDoubleWritable>.Context context)
        throws IOException, InterruptedException {

      double expectation = 0;
      double ptCount = 0;
      for (final CountofDoubleWritable value : values) {
        expectation += value.getValue();
        ptCount += value.getCount();
      }
      outputValue.set(expectation, ptCount);
      context.write(key, outputValue);
    }