List of usage examples for org.apache.commons.math3.util ResizableDoubleArray getElements
public synchronized double[] getElements()
ResizableArray
. From source file:com.itemanalysis.jmetrik.stats.ranking.RankingAnalysis.java
public String compute() throws SQLException { Statement stmt = null;/*from w w w .ja va 2 s.co m*/ 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); } }