List of usage examples for org.apache.commons.math3.stat.descriptive.rank Max getResult
@Override public double getResult()
From source file:com.sciaps.utils.Util.java
public static Spectrum createAverage(Collection<? extends Spectrum> shots, double sampleRate) { Min minWL = new Min(); Max maxWL = new Max(); for (Spectrum shot : shots) { minWL.increment(shot.getValidRange().getMinimumDouble()); maxWL.increment(shot.getValidRange().getMaximumDouble()); }//from w w w . j av a 2 s .co m double range = maxWL.getResult() - minWL.getResult(); int numSamples = (int) Math.floor(range * sampleRate); double[][] data = new double[2][numSamples]; Mean avgy = new Mean(); for (int i = 0; i < numSamples; i++) { double x = minWL.getResult() + i * (1 / sampleRate); avgy.clear(); for (Spectrum shot : shots) { if (shot.getValidRange().containsDouble(x)) { UnivariateFunction iv = shot.getIntensityFunction(); double y = iv.value(x); avgy.increment(y); } } data[0][i] = x; data[1][i] = avgy.getResult(); } RawDataSpectrum newSpectrum = new RawDataSpectrum(data); return newSpectrum; }
From source file:com.itemanalysis.psychometrics.histogram.Histogram.java
private void createHistogram(double[] x) { n = x.length;//from ww w .jav a2 s . c om Min min = new Min(); Max max = new Max(); Mean mean = new Mean(); StandardDeviation sd = new StandardDeviation(); for (int i = 0; i < x.length; i++) { min.increment(x[i]); max.increment(x[i]); mean.increment(x[i]); sd.increment(x[i]); } double range = max.getResult() - min.getResult(); double lowestBoundary = min.getResult() - range / 1000; double largestBoundary = max.getResult() + range / 1000; if (binCalculationType == BinCalculationType.SCOTT) { binCalc = new ScottBinCalculation(n, min.getResult(), max.getResult(), sd.getResult()); } else if (binCalculationType == BinCalculationType.FREEDMAN_DIACONIS) { Percentile percentile = new Percentile(); double q1 = percentile.evaluate(x, 25); double q3 = percentile.evaluate(x, 75); binCalc = new FreedmanDiaconisBinCalculation(n, min.getResult(), max.getResult(), q1, q3); } else if (binCalculationType == BinCalculationType.STURGES) { binCalc = new SturgesBinCalculation(n, min.getResult(), max.getResult()); } numberOfBins = binCalc.numberOfBins(); binWidth = binCalc.binWidth(); //create bins createBins(lowestBoundary, largestBoundary); //count observations in each bin for (int i = 0; i < n; i++) { for (Bin b : bins) { b.increment(x[i]); } } }
From source file:com.itemanalysis.jmetrik.stats.transformation.LinearTransformationAnalysis.java
public String transformScore() throws SQLException { Statement stmt = null;// www . j a v a 2 s. co m ResultSet rs = null; Double constrainedScore = null; try { //add variable to db dao.addColumnToDb(conn, tableName, addedVariableInfo); conn.setAutoCommit(false);//begin transaction Table sqlTable = new Table(tableName.getNameForDatabase()); SelectQuery select = new SelectQuery(); select.addColumn(sqlTable, selectedVariable.getName().nameForDatabase()); select.addColumn(sqlTable, addedVariableInfo.getName().nameForDatabase()); stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); rs = stmt.executeQuery(select.toString()); this.firePropertyChange("message", "", "Transforming scores..."); double origValue = 0.0; double transValue = 0.0; double z = 0.0; StandardDeviation sd = new StandardDeviation(); Mean mean = new Mean(); Min min = new Min(); Max max = new Max(); while (rs.next()) { origValue = rs.getDouble(selectedVariable.getName().nameForDatabase()); if (!rs.wasNull()) { sd.increment(origValue); mean.increment(origValue); min.increment(origValue); max.increment(origValue); } updateProgress(); } double meanValue = mean.getResult(); double sdValue = sd.getResult(); double minValue = min.getResult(); double maxValue = max.getResult(); double A = 1.0; double B = 0.0; rs.beforeFirst(); while (rs.next()) { origValue = rs.getDouble(selectedVariable.getName().nameForDatabase()); if (!rs.wasNull()) { if (type1) { z = (origValue - meanValue) / sdValue; transValue = scaleSd * z + scaleMean; transValue = checkConstraints(transValue); } else { A = (maxPossibleScore - minPossibleScore) / (maxValue - minValue); B = minPossibleScore - minValue * A; transValue = origValue * A + B; transValue = checkConstraints(transValue); } descriptiveStatistics.increment(transValue); rs.updateDouble(addedVariableInfo.getName().nameForDatabase(), transValue); rs.updateRow(); } updateProgress(); } conn.commit(); conn.setAutoCommit(true); //create output DefaultLinearTransformation linearTransformation = new DefaultLinearTransformation(); linearTransformation.setScale(A); linearTransformation.setIntercept(B); StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); f.format(publishHeader()); f.format(descriptiveStatistics.toString()); f.format(linearTransformation.toString()); f.format("%n"); f.format("%n"); return f.toString(); } catch (SQLException ex) { conn.rollback(); conn.setAutoCommit(true); throw ex; } finally { if (rs != null) rs.close(); if (stmt != null) stmt.close(); } }
From source file:com.itemanalysis.psychometrics.polycor.MixedCorrelationMatrix.java
public String printPolychoricThresholds() { PolychoricML ml = null;//w w w . j av a 2 s.co m PolychoricTwoStepOLD ts = null; int nPolychoric = 0; for (int i = 0; i < corTypes.length; i++) { if (corTypes[i][i] == CorrelationType.POLYCHORIC) nPolychoric++; } double[][] t = new double[nPolychoric][]; double[][] se = new double[nPolychoric][]; String[] names = new String[nPolychoric]; Object o = null; Max max = new Max(); int index = 0; int pIndex = 0; for (VariableAttributes v : variables) { o = matrix[index][index]; if (corTypes[index][index] == CorrelationType.POLYCHORIC) { if (maximumLikelihood) { ml = (PolychoricML) o; max.increment(ml.getNumberOfValidRowThresholds()); t[pIndex] = ml.getValidRowThresholds(); se[pIndex] = ml.getValidRowThresholdStandardErrors(); } else { ts = (PolychoricTwoStepOLD) o; max.increment(ts.getNumberOfValidRowThresholds()); t[pIndex] = ts.getValidRowThresholds(); } names[pIndex] = v.getName().toString(); pIndex++; } index++; } TextTable table = new TextTable(); int nCol = (int) max.getResult(); if (maximumLikelihood) nCol *= 2; TextTableColumnFormat[] cformats = new TextTableColumnFormat[nCol + 1]; cformats[0] = new TextTableColumnFormat(); cformats[0].setStringFormat(10, OutputAlignment.LEFT); for (int i = 0; i < nCol; i++) { cformats[i + 1] = new TextTableColumnFormat(); cformats[i + 1].setDoubleFormat(8, 4, OutputAlignment.RIGHT); } table.addAllColumnFormats(cformats, nPolychoric + 5); table.setAllCellPadding(2); table.getRowAt(0).addHeader(0, nCol + 1, "POLYCHORIC THRESHOLD", TextTablePosition.LEFT); table.getRowAt(1).addHorizontalRule(0, nCol + 1, "="); table.getRowAt(2).addHeader(0, 1, "Name", TextTablePosition.LEFT); for (int i = 0; i < (int) max.getResult(); i++) { String tName = "Thr." + (i + 1); table.getRowAt(2).addHeader(i + 1, 1, tName, TextTablePosition.RIGHT); if (maximumLikelihood) { String seName = "S.E." + (i + 1); table.getRowAt(2).addHeader(i + 2, 1, seName, TextTablePosition.RIGHT); } } table.getRowAt(3).addHorizontalRule(0, nCol + 1, "-"); for (int i = 0; i < nPolychoric; i++) { table.getRowAt(i + 4).addStringAt(0, names[i]); for (int j = 0; j < t[i].length; j++) { table.getRowAt(i + 4).addDoubleAt(j + 1, t[i][j]); if (maximumLikelihood) table.getRowAt(i + 4).addDoubleAt(j + 2, se[j][j]); } } table.getRowAt(nPolychoric + 4).addHorizontalRule(0, nCol + 1, "="); return table.toString(); }
From source file:com.itemanalysis.psychometrics.rasch.ScoreTable.java
public void updateScoreTable(int globalMaxIter, double globalConvergence, double adjust) { double DELTA = globalConvergence + 1.0; //LCONV Max maxDelta = new Max(); int iter = 0; //initialize raw score and extreme score arrays double maxRaw = validMRS(); int n = (int) maxRaw; int np1 = n + 1; scoreTable = new double[np1][2]; extremeScore = new boolean[np1]; stdError = new double[np1]; for (int i = 0; i < np1; i++) { scoreTable[i][0] = i;/*from www .j a v a 2 s.c o m*/ scoreTable[i][1] = scoreTableProx(scoreTable[i][0], maxRaw, adjust); stdError[i] = 0.0; if (i == 0 || i == n) { extremeScore[i] = true; } else { extremeScore[i] = false; } } double previousTheta = 0.0; //update nonextreme persons while (DELTA >= globalConvergence && iter < globalMaxIter) { //Change in person parameter is not counted toward delta. for (int i = 0; i < np1; i++) { if (!extremeScore[i]) { previousTheta = scoreTable[i][1]; scoreTable[i][1] = personUpdate(scoreTable[i][1], scoreTable[i][0], maxRaw, 0.0, DELTA); maxDelta.increment(Math.abs(previousTheta - scoreTable[i][1])); } } DELTA = maxDelta.getResult(); maxDelta.clear(); iter++; } int iter2 = 0; double DELTA2 = 1.0; double adjustedRaw = 0.0; int index = 0; //update lowest and highest (extreme) scores - convergence = 0.01 and maximum of 25 iterations while (DELTA2 >= 0.01 && iter2 < 25) { index = 0; previousTheta = scoreTable[index][1]; adjustedRaw = adjust; scoreTable[index][1] = personUpdate(scoreTable[index][1], adjustedRaw, maxRaw, 0.0, DELTA); maxDelta.increment(Math.abs(previousTheta - scoreTable[index][1])); index = n; previousTheta = scoreTable[index][1]; adjustedRaw = scoreTable[index][0] - adjust; scoreTable[index][1] = personUpdate(scoreTable[index][1], adjustedRaw, maxRaw, 0.0, DELTA); maxDelta.increment(Math.abs(previousTheta - scoreTable[index][1])); DELTA2 = maxDelta.getResult(); maxDelta.clear(); iter2++; } }
From source file:com.itemanalysis.jmetrik.stats.irt.linking.DbThetaDistribution.java
public DistributionApproximation getDistribution(Connection conn, DataTableName tableName, VariableName thetaName, VariableName weightName, boolean hasWeight) throws SQLException { points = new ArrayList<Double>(); Min min = new Min(); Max max = new Max(); Table sqlTable = new Table(tableName.getNameForDatabase()); SelectQuery query = new SelectQuery(); query.addColumn(sqlTable, thetaName.nameForDatabase()); if (hasWeight) { query.addColumn(sqlTable, weightName.nameForDatabase()); weights = new ArrayList<Double>(); }/*from ww w . jav a 2 s . co m*/ Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmt.executeQuery(query.toString()); double value = 0.0; double w = 1.0; while (rs.next()) { value = rs.getDouble(thetaName.nameForDatabase()); if (!rs.wasNull()) { if (hasWeight) { w = rs.getDouble(weightName.nameForDatabase()); if (rs.wasNull()) { w = 0.0; } points.add(value); weights.add(w); min.increment(value); max.increment(value); } else { points.add(value); min.increment(value); max.increment(value); } } } rs.close(); stmt.close(); ContinuousDistributionApproximation dist = new ContinuousDistributionApproximation(points.size(), min.getResult(), max.getResult()); if (hasWeight) { for (int i = 0; i < points.size(); i++) { dist.setPointAt(i, points.get(i)); dist.setDensityAt(i, weights.get(i)); } } else { for (int i = 0; i < points.size(); i++) { dist.setPointAt(i, points.get(i)); } } return dist; }
From source file:org.matsim.contrib.drt.util.stats.DrtVehicleOccupancyProfileCalculator.java
public DrtVehicleOccupancyProfileCalculator(Fleet fleet, int timeInterval) { this.fleet = fleet; Max maxCapacity = new Max(); Max maxTime = new Max(); for (Vehicle v : fleet.getVehicles().values()) { maxCapacity.increment(v.getCapacity()); maxTime.increment(v.getSchedule().getEndTime()); }//from w ww.j a v a 2 s. c o m int intervalCount = (int) Math.ceil((maxTime.getResult() + 1) / timeInterval); timeDiscretizer = new TimeDiscretizer(intervalCount * timeInterval, timeInterval, TimeDiscretizer.Type.ACYCLIC); int occupancyProfilesCount = (int) maxCapacity.getResult() + 1; vehicleOccupancyProfilesInSeconds = new long[occupancyProfilesCount][timeDiscretizer.getIntervalCount()]; idleVehicleProfileInSeconds = new long[timeDiscretizer.getIntervalCount()]; vehicleOccupancyProfilesRelative = new double[occupancyProfilesCount][timeDiscretizer.getIntervalCount()]; idleVehicleProfileRelative = new double[timeDiscretizer.getIntervalCount()]; }
From source file:playground.michalm.taxi.optimizer.assignment.AssignmentProblem.java
private List<VrpPathWithTravelData[]> createVrpPaths() { List<VrpPathWithTravelData[]> paths = new ArrayList<>(rData.urgentReqCount); //if only imm reqs then rMin = rData.urgentReqCount = rData.dimension //if both imm+adv then rMin should be urgentReqCount + soonUrgentReqCount int rMin = rData.urgentReqCount;//include also "soonUrgentReqCount" if "adv" reqs if (rMin < vData.dimension) { rMin = Math.min(rData.dimension, vData.dimension); }// ww w . j a v a 2s .co m Max maxArrivalTimeForRMinRequests = new Max();//heuristics for (int r = 0; r < rMin; r++) { TaxiRequest req = rData.requests[r]; VrpPathWithTravelData[] reqPaths = createVrpPathsForRequest(req); paths.add(reqPaths); for (VrpPathWithTravelData path : reqPaths) { if (path != null) { maxArrivalTimeForRMinRequests.increment(path.getArrivalTime()); } } } for (int r = rMin; r < rData.dimension; r++) { TaxiRequest req = rData.requests[r]; if (req.getT0() > maxArrivalTimeForRMinRequests.getResult()) { break; } paths.add(createVrpPathsForRequest(req)); } return paths; }