当前位置: 首页>>代码示例>>Java>>正文


Java DistanceMeasure类代码示例

本文整理汇总了Java中org.apache.commons.math3.ml.distance.DistanceMeasure的典型用法代码示例。如果您正苦于以下问题:Java DistanceMeasure类的具体用法?Java DistanceMeasure怎么用?Java DistanceMeasure使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DistanceMeasure类属于org.apache.commons.math3.ml.distance包,在下文中一共展示了DistanceMeasure类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: FuzzyKMeansClusterer

import org.apache.commons.math3.ml.distance.DistanceMeasure; //导入依赖的package包/类
/**
 * Creates a new instance of a FuzzyKMeansClusterer.
 *
 * @param k the number of clusters to split the data into
 * @param fuzziness the fuzziness factor, must be > 1.0
 * @param maxIterations the maximum number of iterations to run the algorithm for.
 *   If negative, no maximum will be used.
 * @param measure the distance measure to use
 * @param epsilon the convergence criteria (default is 1e-3)
 * @param random random generator to use for choosing initial centers
 * @throws NumberIsTooSmallException if {@code fuzziness <= 1.0}
 */
public FuzzyKMeansClusterer(final int k, final double fuzziness,
                            final int maxIterations, final DistanceMeasure measure,
                            final double epsilon, final RandomGenerator random)
        throws NumberIsTooSmallException {

    super(measure);

    if (fuzziness <= 1.0d) {
        throw new NumberIsTooSmallException(fuzziness, 1.0, false);
    }
    this.k = k;
    this.fuzziness = fuzziness;
    this.maxIterations = maxIterations;
    this.epsilon = epsilon;
    this.random = random;

    this.membershipMatrix = null;
    this.points = null;
    this.clusters = null;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:33,代码来源:FuzzyKMeansClusterer.java

示例2: findBest

import org.apache.commons.math3.ml.distance.DistanceMeasure; //导入依赖的package包/类
/**
 * Finds the neuron that best matches the given features.
 *
 * @param features Data.
 * @param neurons List of neurons to scan. If the list is empty
 * {@code null} will be returned.
 * @param distance Distance function. The neuron's features are
 * passed as the first argument to {@link DistanceMeasure#compute(double[],double[])}.
 * @return the neuron whose features are closest to the given data.
 * @throws org.apache.commons.math3.exception.DimensionMismatchException
 * if the size of the input is not compatible with the neurons features
 * size.
 */
public static Neuron findBest(double[] features,
                              Iterable<Neuron> neurons,
                              DistanceMeasure distance) {
    Neuron best = null;
    double min = Double.POSITIVE_INFINITY;
    for (final Neuron n : neurons) {
        final double d = distance.compute(n.getFeatures(), features);
        if (d < min) {
            min = d;
            best = n;
        }
    }

    return best;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:29,代码来源:MapUtils.java

示例3: findBestAndSecondBest

import org.apache.commons.math3.ml.distance.DistanceMeasure; //导入依赖的package包/类
/**
 * Finds the two neurons that best match the given features.
 *
 * @param features Data.
 * @param neurons List of neurons to scan. If the list is empty
 * {@code null} will be returned.
 * @param distance Distance function. The neuron's features are
 * passed as the first argument to {@link DistanceMeasure#compute(double[],double[])}.
 * @return the two neurons whose features are closest to the given data.
 * @throws org.apache.commons.math3.exception.DimensionMismatchException
 * if the size of the input is not compatible with the neurons features
 * size.
 */
public static Pair<Neuron, Neuron> findBestAndSecondBest(double[] features,
                                                         Iterable<Neuron> neurons,
                                                         DistanceMeasure distance) {
    Neuron[] best = { null, null };
    double[] min = { Double.POSITIVE_INFINITY,
                     Double.POSITIVE_INFINITY };
    for (final Neuron n : neurons) {
        final double d = distance.compute(n.getFeatures(), features);
        if (d < min[0]) {
            // Replace second best with old best.
            min[1] = min[0];
            best[1] = best[0];

            // Store current as new best.
            min[0] = d;
            best[0] = n;
        } else if (d < min[1]) {
            // Replace old second best with current.
            min[1] = d;
            best[1] = n;
        }
    }

    return new Pair<Neuron, Neuron>(best[0], best[1]);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:39,代码来源:MapUtils.java

示例4: sort

import org.apache.commons.math3.ml.distance.DistanceMeasure; //导入依赖的package包/类
/**
 * Creates a list of neurons sorted in increased order of the distance
 * to the given {@code features}.
 *
 * @param features Data.
 * @param neurons List of neurons to scan. If it is empty, an empty array
 * will be returned.
 * @param distance Distance function.
 * @return the neurons, sorted in increasing order of distance in data
 * space.
 * @throws org.apache.commons.math3.exception.DimensionMismatchException
 * if the size of the input is not compatible with the neurons features
 * size.
 *
 * @see #findBest(double[],Iterable,DistanceMeasure)
 * @see #findBestAndSecondBest(double[],Iterable,DistanceMeasure)
 *
 * @since 3.6
 */
public static Neuron[] sort(double[] features,
                            Iterable<Neuron> neurons,
                            DistanceMeasure distance) {
    final List<PairNeuronDouble> list = new ArrayList<PairNeuronDouble>();

    for (final Neuron n : neurons) {
        final double d = distance.compute(n.getFeatures(), features);
        list.add(new PairNeuronDouble(n, d));
    }

    Collections.sort(list, PairNeuronDouble.COMPARATOR);

    final int len = list.size();
    final Neuron[] sorted = new Neuron[len];

    for (int i = 0; i < len; i++) {
        sorted[i] = list.get(i).getNeuron();
    }
    return sorted;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:40,代码来源:MapUtils.java

示例5: computeQuantizationError

import org.apache.commons.math3.ml.distance.DistanceMeasure; //导入依赖的package包/类
/**
 * Computes the quantization error.
 * The quantization error is the average distance between a feature vector
 * and its "best matching unit" (closest neuron).
 *
 * @param data Feature vectors.
 * @param neurons List of neurons to scan.
 * @param distance Distance function.
 * @return the error.
 * @throws NoDataException if {@code data} is empty.
 */
public static double computeQuantizationError(Iterable<double[]> data,
                                              Iterable<Neuron> neurons,
                                              DistanceMeasure distance) {
    double d = 0;
    int count = 0;
    for (double[] f : data) {
        ++count;
        d += distance.compute(f, findBest(f, neurons, distance).getFeatures());
    }

    if (count == 0) {
        throw new NoDataException();
    }

    return d / count;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:28,代码来源:MapUtils.java

示例6: computeTopographicError

import org.apache.commons.math3.ml.distance.DistanceMeasure; //导入依赖的package包/类
/**
 * Computes the topographic error.
 * The topographic error is the proportion of data for which first and
 * second best matching units are not adjacent in the map.
 *
 * @param data Feature vectors.
 * @param net Network.
 * @param distance Distance function.
 * @return the error.
 * @throws NoDataException if {@code data} is empty.
 */
public static double computeTopographicError(Iterable<double[]> data,
                                             Network net,
                                             DistanceMeasure distance) {
    int notAdjacentCount = 0;
    int count = 0;
    for (double[] f : data) {
        ++count;
        final Pair<Neuron, Neuron> p = findBestAndSecondBest(f, net, distance);
        if (!net.getNeighbours(p.getFirst()).contains(p.getSecond())) {
            // Increment count if first and second best matching units
            // are not neighbours.
            ++notAdjacentCount;
        }
    }

    if (count == 0) {
        throw new NoDataException();
    }

    return ((double) notAdjacentCount) / count;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:33,代码来源:MapUtils.java

示例7: withDistanceMeasure

import org.apache.commons.math3.ml.distance.DistanceMeasure; //导入依赖的package包/类
public DistanceTester withDistanceMeasure(final DistanceMeasure distance) {
    this.distance = new GenericDistanceMeasure<double[]>() {
        private static final long serialVersionUID = -7065467026544814688L;

        @Override
        public double compute(double[] a, double[] b) {
            return distance.compute(a, b);
        }

        @Override
        public double compute(double[] a, double[] b, double cutOffValue) {
            return distance.compute(a, b);
        }
    };
    return this;
}
 
开发者ID:octavian-h,项目名称:time-series-math,代码行数:17,代码来源:DistanceTester.java

示例8: DBSCANClusterer

import org.apache.commons.math3.ml.distance.DistanceMeasure; //导入依赖的package包/类
/**
 * Creates a new instance of a DBSCANClusterer.
 *
 * @param eps maximum radius of the neighborhood to be considered
 * @param minPts minimum number of points needed for a cluster
 * @param measure the distance measure to use
 * @throws NotPositiveException if {@code eps < 0.0} or {@code minPts < 0}
 */
public DBSCANClusterer(final double eps, final int minPts, final DistanceMeasure measure)
    throws NotPositiveException {
    super(measure);

    if (eps < 0.0d) {
        throw new NotPositiveException(eps);
    }
    if (minPts < 0) {
        throw new NotPositiveException(minPts);
    }
    this.eps = eps;
    this.minPts = minPts;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:22,代码来源:DBSCANClusterer.java

示例9: KMeansPlusPlusClusterer

import org.apache.commons.math3.ml.distance.DistanceMeasure; //导入依赖的package包/类
/** Build a clusterer.
 *
 * @param k the number of clusters to split the data into
 * @param maxIterations the maximum number of iterations to run the algorithm for.
 *   If negative, no maximum will be used.
 * @param measure the distance measure to use
 * @param random random generator to use for choosing initial centers
 * @param emptyStrategy strategy to use for handling empty clusters that
 * may appear during algorithm iterations
 */
public KMeansPlusPlusClusterer(final int k, final int maxIterations,
                               final DistanceMeasure measure,
                               final RandomGenerator random,
                               final EmptyClusterStrategy emptyStrategy) {
    super(measure);
    this.k             = k;
    this.maxIterations = maxIterations;
    this.random        = random;
    this.emptyStrategy = emptyStrategy;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:21,代码来源:KMeansPlusPlusClusterer.java

示例10: KohonenUpdateAction

import org.apache.commons.math3.ml.distance.DistanceMeasure; //导入依赖的package包/类
/**
 * @param distance Distance function.
 * @param learningFactor Learning factor update function.
 * @param neighbourhoodSize Neighbourhood size update function.
 */
public KohonenUpdateAction(DistanceMeasure distance,
                           LearningFactorFunction learningFactor,
                           NeighbourhoodSizeFunction neighbourhoodSize) {
    this.distance = distance;
    this.learningFactor = learningFactor;
    this.neighbourhoodSize = neighbourhoodSize;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:13,代码来源:KohonenUpdateAction.java

示例11: computeU

import org.apache.commons.math3.ml.distance.DistanceMeasure; //导入依赖的package包/类
/**
 * Computes the <a href="http://en.wikipedia.org/wiki/U-Matrix">
 *  U-matrix</a> of a two-dimensional map.
 *
 * @param map Network.
 * @param distance Function to use for computing the average
 * distance from a neuron to its neighbours.
 * @return the matrix of average distances.
 */
public static double[][] computeU(NeuronSquareMesh2D map,
                                  DistanceMeasure distance) {
    final int numRows = map.getNumberOfRows();
    final int numCols = map.getNumberOfColumns();
    final double[][] uMatrix = new double[numRows][numCols];

    final Network net = map.getNetwork();

    for (int i = 0; i < numRows; i++) {
        for (int j = 0; j < numCols; j++) {
            final Neuron neuron = map.getNeuron(i, j);
            final Collection<Neuron> neighbours = net.getNeighbours(neuron);
            final double[] features = neuron.getFeatures();

            double d = 0;
            int count = 0;
            for (Neuron n : neighbours) {
                ++count;
                d += distance.compute(features, n.getFeatures());
            }

            uMatrix[i][j] = d / count;
        }
    }

    return uMatrix;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:37,代码来源:MapUtils.java

示例12: SmoothedDataHistogram

import org.apache.commons.math3.ml.distance.DistanceMeasure; //导入依赖的package包/类
/**
 * @param smoothingBins Number of bins.
 * @param distance Distance.
 */
public SmoothedDataHistogram(int smoothingBins,
                             DistanceMeasure distance) {
    this.smoothingBins = smoothingBins;
    this.distance = distance;

    double sum = 0;
    for (int i = 0; i < smoothingBins; i++) {
        sum += smoothingBins - i;
    }

    this.membershipNormalization = 1d / sum;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:17,代码来源:SmoothedDataHistogram.java

示例13: testGetters

import org.apache.commons.math3.ml.distance.DistanceMeasure; //导入依赖的package包/类
@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());
    Assert.assertEquals(2.0, clusterer.getFuzziness(), 1e-6);
    Assert.assertEquals(100, clusterer.getMaxIterations());
    Assert.assertEquals(1e-6, clusterer.getEpsilon(), 1e-12);
    Assert.assertThat(clusterer.getDistanceMeasure(), CoreMatchers.is(measure));
    Assert.assertThat(clusterer.getRandomGenerator(), CoreMatchers.is(random));
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:15,代码来源:FuzzyKMeansClustererTest.java


注:本文中的org.apache.commons.math3.ml.distance.DistanceMeasure类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。