List of usage examples for org.apache.commons.math3.analysis.polynomials PolynomialSplineFunction getKnots
public double[] getKnots()
From source file:eu.tango.energymodeller.energypredictor.CpuOnlySplinePolynomialEnergyPredictor.java
/** * This ensures the CPU usage provided to the model is in the acceptable * range./*from w w w. j a v a2s . c o m*/ * * @param model The model to get the cpu usage for * @param usageCPU The amount of CPU load placed on the host * @return The cpu usage that is within the acceptable range. */ private double getCpuUsageValue(PolynomialSplineFunction model, double usageCPU) { /** * Interpolation is the process of fitting a line of best fit directly * to the datapoints gathered. The lowest value possible value to * predict from is therefore not likely to be 0. */ if (usageCPU < model.getKnots()[0]) { return model.getKnots()[0]; } if (usageCPU > model.getKnots()[model.getKnots().length - 1]) { return model.getKnots()[model.getKnots().length - 1]; } return usageCPU; }
From source file:malware_classification.Malware_Classification.java
private ArrayList<double[]> interpolate_data(ArrayList<double[]> data_orig, ArrayList<double[]> timestamp_orig, int bin_size, int num_bins) { ArrayList<double[]> interp_data = new ArrayList<>(); int num_points_orig = data_orig.size(); // TODO: change some of the num_points_orig to num_bins double[] x = new double[num_points_orig]; double[] y = new double[num_points_orig]; int num_cols = data_orig.get(0).length; for (int i = 0; i < num_bins; i++) { interp_data.add(new double[num_cols]); }//from ww w. j a v a2 s . com for (int col = 0; col < num_cols; col++) { // To use LinearInterpolator, first need arrays for (int j = 0; j < num_points_orig; j++) { x[j] = timestamp_orig.get(j)[col]; y[j] = data_orig.get(j)[col]; } LinearInterpolator lin_interp = new LinearInterpolator(); PolynomialSplineFunction interp_func = lin_interp.interpolate(x, y); for (int j = 0; j < num_bins; j++) { double curr_bin = bin_size * j; double[] knots = interp_func.getKnots(); // logger.info() if (interp_func.isValidPoint(curr_bin)) { interp_data.get(j)[col] = interp_func.value(curr_bin); } else if (knots[0] > curr_bin) //bin is too small { interp_data.get(j)[col] = y[0]; } else if (knots[knots.length - 1] < curr_bin) // bin is larger than data { interp_data.get(j)[col] = y[y.length - 1]; } else { logger.warning("Cannot interpolate at bin starting at " + curr_bin); } } } return interp_data; }
From source file:org.micromanager.plugins.magellan.acq.AcqDurationEstimator.java
private double interpolateOrExtrapolate(double[] x, double[] y, double xVal) { if (x.length == 1) { return y[0]; }/*from w w w.ja va2 s.c om*/ LinearInterpolator interpolator = new LinearInterpolator(); PolynomialSplineFunction interpolant = interpolator.interpolate(x, y); if (xVal < interpolant.getKnots()[0]) { return interpolant.getKnots()[0]; } else if (xVal > interpolant.getKnots()[interpolant.getN() - 1]) { return interpolant.getKnots()[interpolant.getN() - 1]; } else { return interpolant.value(xVal); } }