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


Java NaNStrategy.REMOVED属性代码示例

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


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

示例1: correlation

/**
 * 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,代码行数:31,代码来源:SpearmansCorrelation.java

示例2: testMath891Matrix

@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,代码行数:17,代码来源:SpearmansRankCorrelationTest.java

示例3: before

/**
 * 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,代码行数:10,代码来源:PercentileTest.java

示例4: testMath891Array

@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,代码行数:10,代码来源:SpearmansRankCorrelationTest.java

示例5: rankTransform

/**
 * Applies rank transform to each of the columns of <code>matrix</code>
 * using the current <code>rankingAlgorithm</code>.
 *
 * @param matrix matrix to transform
 * @return a rank-transformed matrix
 */
private RealMatrix rankTransform(final RealMatrix matrix) {
    RealMatrix transformed = null;

    if (rankingAlgorithm instanceof NaturalRanking &&
            ((NaturalRanking) rankingAlgorithm).getNanStrategy() == NaNStrategy.REMOVED) {
        final Set<Integer> nanPositions = new HashSet<Integer>();
        for (int i = 0; i < matrix.getColumnDimension(); i++) {
            nanPositions.addAll(getNaNPositions(matrix.getColumn(i)));
        }

        // if we have found NaN values, we have to update the matrix size
        if (!nanPositions.isEmpty()) {
            transformed = new BlockRealMatrix(matrix.getRowDimension() - nanPositions.size(),
                                              matrix.getColumnDimension());
            for (int i = 0; i < transformed.getColumnDimension(); i++) {
                transformed.setColumn(i, removeValues(matrix.getColumn(i), nanPositions));
            }
        }
    }

    if (transformed == null) {
        transformed = matrix.copy();
    }

    for (int i = 0; i < transformed.getColumnDimension(); i++) {
        transformed.setColumn(i, rankingAlgorithm.rank(transformed.getColumn(i)));
    }

    return transformed;
}
 
开发者ID:happyjack27,项目名称:autoredistrict,代码行数:37,代码来源:SpearmansCorrelation.java

示例6: getTestMedian

private Median getTestMedian(EstimationType type) {
    NaNStrategy strategy = (type == LEGACY) ? NaNStrategy.FIXED : NaNStrategy.REMOVED;
    return new Median().withEstimationType(type).withNaNStrategy(strategy);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:4,代码来源:MedianTest.java

示例7: reset

private void reset(final double p, final Percentile.EstimationType type) {
    this.quantile = p;
    this.type     = type;
    nanStrategy   = (type == Percentile.EstimationType.LEGACY) ? NaNStrategy.FIXED : NaNStrategy.REMOVED;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:5,代码来源:PercentileTest.java

示例8: compute

public String compute()throws SQLException{
    Statement stmt = null;
    ResultSet rs = null;

    try{
        //get data
        ResizableDoubleArray data = getData();

        //create columns - dao uses its own transaction
        int numberOfColumns = dao.getColumnCount(conn, tableName);
        int columnNumber = numberOfColumns+1;
        String newVariableLabel = "Rank";
        if(blom) newVariableLabel = "Blom Normal Score";
        if(tukey) newVariableLabel = "Tukey Normal Score";
        if(vdw) newVariableLabel = "van der Waerden Normal Score";
        if(ntiles) newVariableLabel = "Quantiles: " + numGroups + " groups";
        newVariable = new VariableAttributes(newVariableName, newVariableLabel, ItemType.NOT_ITEM, DataType.DOUBLE, columnNumber++, "");

        dao.addColumnToDb(conn, tableName, newVariable);

        //compute ranks
        NaturalRanking ranking = new NaturalRanking(NaNStrategy.REMOVED, tiesStrategy);
        double[] ranks = ranking.rank(data.getElements());

        //begin transaction
        conn.setAutoCommit(false);

        //connect to table and update values
        SelectQuery select = new SelectQuery();
        Table sqlTable = new Table(tableName.getNameForDatabase());
        select.addColumn(sqlTable, newVariable.getName().nameForDatabase());
        stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        rs=stmt.executeQuery(select.toString());

        int nRanks = ranks.length;
        int rankIndex = 0;//array index for ranks (missing values not included)
        int dbIndex = 0;//db row position for case (missing values included)
        double r = Double.NaN;
        boolean missing = false;
        String tempName = "";
        while(rs.next()){
            missing = missingIndex.contains(dbIndex);
            if(missing){
                rs.updateNull(newVariable.getName().nameForDatabase());
            }else{
                r = ranks[rankIndex];
                if(blom){
                    rs.updateDouble(newVariable.getName().nameForDatabase(), normScore.blom(r, (double)nRanks));
                }else if (tukey){
                    rs.updateDouble(newVariable.getName().nameForDatabase(), normScore.tukey(r, (double)nRanks));
                }else if(vdw){
                    rs.updateDouble(newVariable.getName().nameForDatabase(), normScore.vanderWaerden(r, (double)nRanks));
                }else if(ntiles){
                    rs.updateDouble(newVariable.getName().nameForDatabase(), getGroup(r, (double)nRanks, (double)numGroups));
                }else{
                    rs.updateDouble(newVariable.getName().nameForDatabase(), r);
                }
                rankIndex++;
            }
            rs.updateRow();
            updateProgress();
            dbIndex++;
        }
        conn.commit();
        return "Ranks computed";
    }catch(SQLException ex){
        conn.rollback();
        throw ex;
    }finally{
        if(rs!=null) rs.close();
        if(stmt!=null) stmt.close();
        conn.setAutoCommit(true);
    }

}
 
开发者ID:meyerjp3,项目名称:jmetrik,代码行数:75,代码来源:RankingAnalysis.java

示例9: Percentile

/**
 * Constructs a Percentile with the specific quantile value and the following
 * <ul>
 *   <li>default method type: {@link EstimationType#LEGACY}</li>
 *   <li>default NaN strategy: {@link NaNStrategy#REMOVED}</li>
 *   <li>a Kth Selector : {@link KthSelector}</li>
 * </ul>
 * @param quantile the quantile
 * @throws MathIllegalArgumentException  if p is not greater than 0 and less
 * than or equal to 100
 */
public Percentile(final double quantile) throws MathIllegalArgumentException {
    this(quantile, EstimationType.LEGACY, NaNStrategy.REMOVED,
         new KthSelector(new MedianOf3PivotingStrategy()));
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:15,代码来源:Percentile.java


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