List of usage examples for org.apache.commons.math.analysis UnivariateRealFunction value
double value(double x) throws FunctionEvaluationException;
From source file:com.opengamma.analytics.math.util.wrapper.CommonsMathWrapperTest.java
@Test public void test1DFunction() throws FunctionEvaluationException { final UnivariateRealFunction commons = CommonsMathWrapper.wrapUnivariate(OG_FUNCTION_1D); for (int i = 0; i < 100; i++) { assertEquals(OG_FUNCTION_1D.evaluate((double) i), commons.value(i), 1e-15); }/* w ww . j a v a 2 s . c o m*/ }
From source file:com.golemgame.util.TransformationFunction.java
protected double transformValue(double x, UnivariateRealFunction function) throws FunctionEvaluationException { double tempY = scaleY; if (tempY == 0)//avoid division by zero. tempY = Double.MIN_VALUE; return (function.value((x - translateX) * scaleX) / scaleY + translateY); }
From source file:com.golemgame.properties.fengGUI.GLFunctionPane.java
/** * Draw the function, between (in the functions coordinates) minX, minY, and maxX and maxY. Draw it so that there is a point for every step'th pixel (so step is in screen coordinates). * @param g//from w w w.j a v a 2 s . co m * @param function * @param minX * @param maxX * @param minY * @param maxY * @param step */ private void drawFunction(Graphics g, UnivariateRealFunction function, float minX, float maxX, float minY, float maxY, float step) { //use quad strips instead // float fStep; fStep = step * (maxX - minX) / (this.getAppearance().getContentWidth()); int number = (int) ((maxX - minX) / fStep); if ((maxX - minX) % fStep > 0) number++;//there will be one extra end position number += 3;//the corners float[] xValues = new float[number]; float[] yValues = new float[number]; xValues[0] = 0; yValues[0] = 0; float x = minX; try { for (int i = 1; i < number - 1; i++) { if (x > maxX) x = maxX; float y = (float) function.value(x); xValues[i] = getScaleX(x); yValues[i] = getScaleY(y); x += fStep; //System.out.println(xValues[i] + "\t" + yValues[i] + "\t" + this.getWidth()+ "\t" + this.getHeight()); } xValues[number - 1] = this.getAppearance().getContentWidth(); yValues[number - 1] = 0; } catch (FunctionEvaluationException e) { StateManager.logError(e); return; } drawQuadStripFunction(g, xValues, yValues, getScaleX(minX), getScaleY(minY), Color.BLUE, Color.DARK_BLUE); }
From source file:playground.johannes.studies.coopsim.AdditiveDistribution.java
@Override public double value(double x) throws FunctionEvaluationException { double r = 0; for (UnivariateRealFunction func : components) r += func.value(x); return r;//w ww.ja v a 2s . c o m }
From source file:playground.johannes.studies.coopsim.Simulator.java
private static Map<SocialVertex, Double> initDurations(Map<SocialVertex, Double> arrivals, UnivariateRealFunction arrDur, double var, double lin, Random random) { Map<SocialVertex, Double> durations = new HashMap<SocialVertex, Double>(); for (SocialVertex v : graph.getVertices()) { double t_arr = arrivals.get(v); double dur_mean; try {// ww w . j a v a 2s . co m dur_mean = arrDur.value(t_arr); if (dur_mean > 0) { double sigma_2 = Math.log(1 + (var / Math.pow(dur_mean, 2))); double mu = Math.log(dur_mean) - (sigma_2 / 2.0); TimeSampler sampler = new TimeSampler(new LogNormalDistribution(Math.sqrt(sigma_2), mu, lin), 86400, random); double dur = sampler.nextSample(); durations.put(v, dur); } else { throw new RuntimeException("Zeor duration."); } } catch (FunctionEvaluationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return durations; }
From source file:playground.johannes.studies.coopsim.TimeSampler.java
public TimeSampler(UnivariateRealFunction pdf, int max, Random random) { this.random = random; max = max / resolution;//from ww w . jav a2 s. com try { y = new double[max]; y[0] = 0;//pdf.value(0); FIXME int i = 1; for (int t = resolution; t < max * resolution; t += resolution) { y[i] = pdf.value(t) + y[i - 1]; i++; } for (i = 0; i < max; i++) { y[i] = y[i] / y[max - 1]; } // System.out.println("last index = " + y[max-1]); } catch (FunctionEvaluationException e) { e.printStackTrace(); } }
From source file:sk.stuba.fiit.kvasnicka.qsimsimulation.helpers.DelayHelper.java
/** * processing delay is a variable delay calculated depending in number of packets being processed by CPU right now * before simulation started, user entered minimum and maximum value for processing delay and maximum number of packets being simultaneously processed * <p/>/*from w w w . j av a 2s .co m*/ * processing delay is interpolated according these values * * @param networkNode * @return */ public static double calculateProcessingDelay(NetworkNode networkNode) { UnivariateRealFunction function = null; try { function = interpolator.interpolate(new double[] { 0.0, networkNode.getMaxProcessingPackets() }, new double[] { networkNode.getMinProcessingDelay(), networkNode.getMaxProcessingDelay() }); double interpolationX = networkNode.getPacketsInProcessing().size(); return function.value(interpolationX); } catch (MathException e) { logg.error(e); return MIN_PROCESSING_DELAY; } }