List of usage examples for org.apache.commons.math3.exception DimensionMismatchException getMessage
@Override
public String getMessage()
From source file:eu.qualimaster.monitoring.profiling.predictors.Kalman.java
/** * This method predicts the value of a time line one or multiple time step(s) ahead of the * last (via update) given value.//from w w w . ja v a 2s . co m * @param steps Number of times steps to predict. * * @return Predictions for the last time step ahead as {@link Double} or Double.MIN_VALUE if the prediction failed. */ public double predict(int steps) { double prediction = Double.MIN_VALUE; if (lastUpdated != Long.MIN_VALUE) { try { if (steps > 0) { // Gap-Handling /* * As long as the time stamp of the last update and the time step to predict * are more than an allowed gap apart from each other ... */ long oldLastUpdated = lastUpdated; double oldLastUpdate = lastUpdate; boolean gap = false; while (((System.currentTimeMillis() + (steps - 1) * 1000) - (lastUpdated * 1000)) > allowedGap) { /* * ... simulate updates using the last prediction. * If an update must be simulated and there is no predicted value * to use instead of the measurement, 'defaultMeasurenment' value is used for the update. */ update(lastUpdated + 1, prediction == Double.MIN_VALUE ? lastUpdate : defaultMeasurement); prediction = predict(0); gap = true; } // Reset values overwritten by gap handling to make predict-updates non-persistent. if (gap) { lastUpdated = oldLastUpdated; lastUpdate = oldLastUpdate; } } filter.predict(controlVector); prediction = filter.getStateEstimation()[2]; predictedSinceUpdate = true; } catch (DimensionMismatchException e) { LogManager.getLogger(Kalman.class).error(e.getMessage(), e); prediction = Double.MIN_VALUE; } } else { System.err.println("Warning: Prediction should only be called after at least one update-call!"); } return prediction; }
From source file:com.clust4j.data.BufferedMatrixReader.java
/** * Read in the data// ww w . jav a 2s. c o m * @param parallel - whether to parallelize the operation * @return the matrix * @throws MatrixParseException */ public DataSet read(boolean parallel) throws MatrixParseException { LogTimer timer = new LogTimer(); String msg; /* * Get lines... */ String[] lines = getLines(setup.stream); // Potential for truncation here... if (lines.length == GlobalState.MAX_ARRAY_SIZE) warn("only " + lines.length + " rows read from data, " + "as this is the max clust4j allows"); else info((lines.length - setup.header_offset) + " record" + (lines.length == 1 ? "" : "s") + " (" + setup.stream.length + " byte" + (setup.stream.length == 1 ? "" : "s") + ") read from file"); /* * Do double parsing... */ double[][] res = null; if (!parallel) { // Let any exceptions propagate res = parseSerial(lines); } else { boolean throwing_exception = true; try { res = ParallelChunkParser.doAll(lines, setup); } catch (NumberFormatException n) { error(new MatrixParseException("caught NumberFormatException: " + n.getLocalizedMessage())); } catch (DimensionMismatchException d) { error(new MatrixParseException("caught row of unexpected dimensions: " + d.getMessage())); } catch (RejectedExecutionException r) { throwing_exception = false; warn("unable to schedule parallel job; falling back to serial parse"); res = parseSerial(lines); } catch (Exception e) { msg = "encountered Exception in thread" + e.getMessage(); error(msg); throw e; } finally { if (null == res && !throwing_exception) throw new RuntimeException("unable to parse data"); } } sayBye(timer); return new DataSet(res, setup.headers); }