• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java NaNStrategy类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: correlation

import org.apache.commons.math3.stat.ranking.NaNStrategy; //导入依赖的package包/类
/**
 * Computes the Spearman's rank correlation coefficient between the two arrays.
 *
 * @param xArray first data array
 * @param yArray second data array
 * @return Returns Spearman's rank correlation coefficient for the two arrays
 * @throws DimensionMismatchException if the arrays lengths do not match
 * @throws MathIllegalArgumentException if the array length is less than 2
 */
public double correlation(final double[] xArray, final double[] yArray) {
    if (xArray.length != yArray.length) {
        throw new DimensionMismatchException(xArray.length, yArray.length);
    } else if (xArray.length < 2) {
        throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_DIMENSION,
                                               xArray.length, 2);
    } else {
        double[] x = xArray;
        double[] y = yArray;
        if (rankingAlgorithm instanceof NaturalRanking &&
            NaNStrategy.REMOVED == ((NaturalRanking) rankingAlgorithm).getNanStrategy()) {
            final Set<Integer> nanPositions = new HashSet<Integer>();

            nanPositions.addAll(getNaNPositions(xArray));
            nanPositions.addAll(getNaNPositions(yArray));

            x = removeValues(xArray, nanPositions);
            y = removeValues(yArray, nanPositions);
        }
        return new PearsonsCorrelation().correlation(rankingAlgorithm.rank(x), rankingAlgorithm.rank(y));
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:32,代码来源:SpearmansCorrelation.java


示例2: testNanStrategySpecific

import org.apache.commons.math3.stat.ranking.NaNStrategy; //导入依赖的package包/类
@Test
public void testNanStrategySpecific() {
    double[] specialValues = new double[] { 0d, 1d, 2d, 3d, 4d, Double.NaN };
    Assert.assertTrue(Double.isNaN(new Percentile(50d).withEstimationType(Percentile.EstimationType.LEGACY).withNaNStrategy(NaNStrategy.MAXIMAL).evaluate(specialValues, 3, 3)));
    Assert.assertEquals(2d,new Percentile(50d).withEstimationType(Percentile.EstimationType.R_1).withNaNStrategy(NaNStrategy.REMOVED).evaluate(specialValues),0d);
    Assert.assertEquals(Double.NaN,new Percentile(50d).withEstimationType(Percentile.EstimationType.R_5).withNaNStrategy(NaNStrategy.REMOVED).evaluate(new double[] {Double.NaN,Double.NaN,Double.NaN}),0d);
    Assert.assertEquals(50d,new Percentile(50d).withEstimationType(Percentile.EstimationType.R_7).withNaNStrategy(NaNStrategy.MINIMAL).evaluate(new double[] {50d,50d,50d},1,2),0d);
    
    specialValues = new double[] { 0d, 1d, 2d, 3d, 4d, Double.NaN, Double.NaN };
    Assert.assertEquals(3.5,new Percentile().evaluate(specialValues, 3, 4),0d);
    Assert.assertEquals(4d,new Percentile().evaluate(specialValues, 4, 3),0d);
    Assert.assertTrue(Double.isNaN(new Percentile().evaluate(specialValues, 5, 2)));
    
    specialValues = new double[] { 0d, 1d, 2d, 3d, 4d, Double.NaN, Double.NaN, 5d, 6d };
    Assert.assertEquals(4.5,new Percentile().evaluate(specialValues, 3, 6),0d);
    Assert.assertEquals(5d,new Percentile().evaluate(specialValues, 4, 5),0d);
    Assert.assertTrue(Double.isNaN(new Percentile().evaluate(specialValues, 5, 2)));
    Assert.assertTrue(Double.isNaN(new Percentile().evaluate(specialValues, 5, 1)));
    Assert.assertEquals(5.5,new Percentile().evaluate(specialValues, 5, 4),0d);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:21,代码来源:PercentileTest.java


示例3: testMath891Matrix

import org.apache.commons.math3.stat.ranking.NaNStrategy; //导入依赖的package包/类
@Test
public void testMath891Matrix() {
    final double[] xArray = new double[] { Double.NaN, 1.9, 2, 100, 3 };
    final double[] yArray = new double[] { 10, 2, 10, Double.NaN, 4 };

    RealMatrix matrix = MatrixUtils.createRealMatrix(xArray.length, 2);
    for (int i = 0; i < xArray.length; i++) {
        matrix.addToEntry(i, 0, xArray[i]);
        matrix.addToEntry(i, 1, yArray[i]);
    }

    // compute correlation
    NaturalRanking ranking = new NaturalRanking(NaNStrategy.REMOVED);
    SpearmansCorrelation spearman = new SpearmansCorrelation(matrix, ranking);
    
    Assert.assertEquals(0.5, spearman.getCorrelationMatrix().getEntry(0, 1), Double.MIN_VALUE);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:18,代码来源:SpearmansRankCorrelationTest.java


示例4: getPercentile

import org.apache.commons.math3.stat.ranking.NaNStrategy; //导入依赖的package包/类
/**
 * Get the percentile value of the data
 * 
 * @param percentile
 *            The percentile
 * @return the percentile value
 */
public float getPercentile(double percentile)
{
	// Check the input
	if (percentile <= 0)
		percentile = Double.MIN_NORMAL;
	if (percentile > 100)
		percentile = 100;
	
	// The data should not have NaN so we ignore them for speed.
	final Percentile p = new Percentile(percentile).withNaNStrategy(NaNStrategy.FIXED);
	final int size = width * height;
	final double[] values = new double[size];
	for (int i = 0; i < size; i++)
		values[i] = data[i];
	return (float) p.evaluate(values);
}
 
开发者ID:aherbert,项目名称:GDSC-SMLM,代码行数:24,代码来源:DataEstimator.java


示例5: getValue

import org.apache.commons.math3.stat.ranking.NaNStrategy; //导入依赖的package包/类
@Override
public double getValue() {
    return new org.apache.commons.math3.stat.descriptive.rank.Percentile(nth * 100)
        .withEstimationType(org.apache.commons.math3.stat.descriptive.rank.Percentile.EstimationType.R_7)
        .withNaNStrategy(NaNStrategy.FIXED)
        .evaluate(values, 0, n);
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:8,代码来源:Percentile.java


示例6: rank

import org.apache.commons.math3.stat.ranking.NaNStrategy; //导入依赖的package包/类
/**
 * Returns the rank array for the values specified
 * @param values    the values to rank
 * @return          the ranks of input array
 */
static double[] rank(double[] values) {
    final NaNStrategy nanStrategy = (NaNStrategy)optionsMap.get(NaNStrategy.class).get(DataFrameOptions.getNanStrategy());
    final TiesStrategy tieStrategy = (TiesStrategy)optionsMap.get(TiesStrategy.class).get(DataFrameOptions.getTieStrategy());
    if (nanStrategy == null) throw new DataFrameException("Unsupported NaN strategy specified: " + DataFrameOptions.getNanStrategy());
    if (tieStrategy == null) throw new DataFrameException("Unsupported tie strategy specified: " + DataFrameOptions.getTieStrategy());
    final NaturalRanking ranking = new NaturalRanking(nanStrategy, tieStrategy);
    return ranking.rank(values);
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:14,代码来源:XDataFrameRank.java


示例7: Percentile

import org.apache.commons.math3.stat.ranking.NaNStrategy; //导入依赖的package包/类
/**
 * Constructs a Percentile with the specific quantile value,
 * {@link EstimationType}, {@link NaNStrategy} and {@link KthSelector}.
 *
 * @param quantile the quantile to be computed
 * @param estimationType one of the percentile {@link EstimationType  estimation types}
 * @param nanStrategy one of {@link NaNStrategy} to handle with NaNs
 * @param kthSelector a {@link KthSelector} to use for pivoting during search
 * @throws MathIllegalArgumentException if p is not within (0,100]
 * @throws NullArgumentException if type or NaNStrategy passed is null
 */
protected Percentile(final double quantile,
                     final EstimationType estimationType,
                     final NaNStrategy nanStrategy,
                     final KthSelector kthSelector)
    throws MathIllegalArgumentException {
    setQuantile(quantile);
    cachedPivots = null;
    MathUtils.checkNotNull(estimationType);
    MathUtils.checkNotNull(nanStrategy);
    MathUtils.checkNotNull(kthSelector);
    this.estimationType = estimationType;
    this.nanStrategy = nanStrategy;
    this.kthSelector = kthSelector;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:26,代码来源:Percentile.java


示例8: before

import org.apache.commons.math3.stat.ranking.NaNStrategy; //导入依赖的package包/类
/**
 * Before method to ensure defaults retained
 */
@Before
public void before() {
    quantile         = 95.0;
    type             = Percentile.EstimationType.LEGACY;
    nanStrategy      = NaNStrategy.REMOVED;
    kthSelector      = new KthSelector(new MedianOf3PivotingStrategy());
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:11,代码来源:PercentileTest.java


示例9: testReplaceNanInRange

import org.apache.commons.math3.stat.ranking.NaNStrategy; //导入依赖的package包/类
@Test
public void testReplaceNanInRange() {
    final double[] specialValues =
            new double[] { 0d, 1d, 2d, 3d, 4d, Double.NaN, Double.NaN, 5d,
            7d, Double.NaN, 8d};
    Assert.assertEquals(/*Double.NaN*/3.5,new Percentile(50d).evaluate(specialValues),0d);
    reset (50, Percentile.EstimationType.R_1);
    Assert.assertEquals(3d, getUnivariateStatistic().evaluate(specialValues),0d);
    reset (50, Percentile.EstimationType.R_2);
    Assert.assertEquals(3.5d, getUnivariateStatistic().evaluate(specialValues),0d);
    Assert.assertEquals(Double.POSITIVE_INFINITY,new Percentile(70)
                                    .withNaNStrategy(NaNStrategy.MAXIMAL)
                                    .evaluate(specialValues),0d);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:15,代码来源:PercentileTest.java


示例10: testPercentileCopy

import org.apache.commons.math3.stat.ranking.NaNStrategy; //导入依赖的package包/类
@Test
public void testPercentileCopy() {
   reset(50d, Percentile.EstimationType.LEGACY);
   final Percentile original = getUnivariateStatistic();
   final Percentile copy = new Percentile(original);
   Assert.assertEquals(original.getNaNStrategy(),copy.getNaNStrategy());
   Assert.assertEquals(original.getQuantile(), copy.getQuantile(),0d);
   Assert.assertEquals(original.getEstimationType(),copy.getEstimationType());
   Assert.assertEquals(NaNStrategy.FIXED, original.getNaNStrategy());
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:11,代码来源:PercentileTest.java


示例11: testNanStrategyFailed

import org.apache.commons.math3.stat.ranking.NaNStrategy; //导入依赖的package包/类
@Test(expected=NotANumberException.class)
public void testNanStrategyFailed() {
    double[] specialValues =
            new double[] { 0d, 1d, 2d, 3d, 4d, Double.NaN };
    new Percentile(50d).
    withEstimationType(Percentile.EstimationType.R_9).
    withNaNStrategy(NaNStrategy.FAILED).
    evaluate(specialValues);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:10,代码来源:PercentileTest.java


示例12: testAllTechniquesSpecialValuesWithNaNStrategy

import org.apache.commons.math3.stat.ranking.NaNStrategy; //导入依赖的package包/类
@Test
public void testAllTechniquesSpecialValuesWithNaNStrategy() {
    double[] specialValues =
            new double[] { 0d, 1d, 2d, 3d, 4d, Double.NaN };
    try {
        new Percentile(50d).withEstimationType(Percentile.EstimationType.LEGACY).withNaNStrategy(null);
        Assert.fail("Expecting NullArgumentArgumentException "
                + "for null Nan Strategy");
    } catch (NullArgumentException ex) {
        // expected
    }
    //This is as per each type's default NaNStrategy
    testAssertMappedValues(specialValues, new Object[][] {
            { Percentile.EstimationType.LEGACY, 2.5d }, { Percentile.EstimationType.R_1, 2.0 }, { Percentile.EstimationType.R_2, 2.0 }, { Percentile.EstimationType.R_3, 1.0 },
            { Percentile.EstimationType.R_4, 1.5 }, { Percentile.EstimationType.R_5, 2.0 }, { Percentile.EstimationType.R_6, 2.0 },
            { Percentile.EstimationType.R_7, 2.0 }, { Percentile.EstimationType.R_8, 2.0 }, { Percentile.EstimationType.R_9, 2.0 }}, 50d, 0d);

    //This is as per MAXIMAL and hence the values tend a +0.5 upward
    testAssertMappedValues(specialValues, new Object[][] {
            { Percentile.EstimationType.LEGACY, 2.5d }, { Percentile.EstimationType.R_1, 2.0 }, { Percentile.EstimationType.R_2, 2.5 }, { Percentile.EstimationType.R_3, 2.0 },
            { Percentile.EstimationType.R_4, 2.0 }, { Percentile.EstimationType.R_5, 2.5 }, { Percentile.EstimationType.R_6, 2.5 },
            { Percentile.EstimationType.R_7, 2.5 }, { Percentile.EstimationType.R_8, 2.5 }, { Percentile.EstimationType.R_9, 2.5 }}, 50d, 0d,
            NaNStrategy.MAXIMAL);

    //This is as per MINIMAL and hence the values tend a -0.5 downward
    testAssertMappedValues(specialValues, new Object[][] {
            { Percentile.EstimationType.LEGACY, 1.5d }, { Percentile.EstimationType.R_1, 1.0 }, { Percentile.EstimationType.R_2, 1.5 }, { Percentile.EstimationType.R_3, 1.0 },
            { Percentile.EstimationType.R_4, 1.0 }, { Percentile.EstimationType.R_5, 1.5 }, { Percentile.EstimationType.R_6, 1.5 },
            { Percentile.EstimationType.R_7, 1.5 }, { Percentile.EstimationType.R_8, 1.5 }, { Percentile.EstimationType.R_9, 1.5 }}, 50d, 0d,
            NaNStrategy.MINIMAL);

    //This is as per REMOVED as here Percentile.Type.CM changed its value from default
    //while rest of Estimation types were anyways defaulted to REMOVED
    testAssertMappedValues(specialValues, new Object[][] {
            { Percentile.EstimationType.LEGACY, 2.0 }, { Percentile.EstimationType.R_1, 2.0 }, { Percentile.EstimationType.R_2, 2.0 }, { Percentile.EstimationType.R_3, 1.0 },
            { Percentile.EstimationType.R_4, 1.5 }, { Percentile.EstimationType.R_5, 2.0 }, { Percentile.EstimationType.R_6, 2.0 },
            { Percentile.EstimationType.R_7, 2.0 }, { Percentile.EstimationType.R_8, 2.0 }, { Percentile.EstimationType.R_9, 2.0 }}, 50d, 0d,
            NaNStrategy.REMOVED);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:40,代码来源:PercentileTest.java


示例13: testAssertMappedValues

import org.apache.commons.math3.stat.ranking.NaNStrategy; //导入依赖的package包/类
/**
 * Simple test assertion utility method
 *
 * @param data input data
 * @param map of expected result against a {@link EstimationType}
 * @param p the quantile to compute for
 * @param tolerance the tolerance of difference allowed
 * @param nanStrategy NaNStrategy to be passed
 */
protected void testAssertMappedValues(double[] data, Object[][] map,
                                      Double p, Double tolerance, NaNStrategy nanStrategy) {
    for (Object[] o : map) {
        Percentile.EstimationType e = (Percentile.EstimationType) o[0];
        double expected = (Double) o[1];
        try {
            double result = new Percentile(p).withEstimationType(e).withNaNStrategy(nanStrategy).evaluate(data);
            Assert.assertEquals("expected[" + e + "] = " + expected + " but was = " + result,
                                expected, result, tolerance);
        } catch(Exception ex) {
            Assert.fail("Exception occured for estimation type " + e + ":" + ex.getLocalizedMessage());
        }
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:24,代码来源:PercentileTest.java


示例14: testMath891Array

import org.apache.commons.math3.stat.ranking.NaNStrategy; //导入依赖的package包/类
@Test
public void testMath891Array() {
    final double[] xArray = new double[] { Double.NaN, 1.9, 2, 100, 3 };
    final double[] yArray = new double[] { 10, 2, 10, Double.NaN, 4 };

    NaturalRanking ranking = new NaturalRanking(NaNStrategy.REMOVED);
    SpearmansCorrelation spearman = new SpearmansCorrelation(ranking);
    
    Assert.assertEquals(0.5, spearman.correlation(xArray, yArray), Double.MIN_VALUE);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:11,代码来源:SpearmansRankCorrelationTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PreparedQueryNotFoundException类代码示例发布时间:2022-05-22
下一篇:
Java NewtFactory类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap