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


Java DistanceMeasure.compute方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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


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