Example usage for org.apache.commons.math3.analysis.polynomials PolynomialFunction value

List of usage examples for org.apache.commons.math3.analysis.polynomials PolynomialFunction value

Introduction

In this page you can find the example usage for org.apache.commons.math3.analysis.polynomials PolynomialFunction value.

Prototype

public DerivativeStructure value(final DerivativeStructure t) throws NullArgumentException, NoDataException 

Source Link

Usage

From source file:heizung.Heizkurve.java

public static void main(String[] args) {
    PolynomialFunction f = getHeizkurve("heizkurve.ini");
    System.out.println(f.value(10));
    System.out.println(f.value(0));
}

From source file:net.liuxuan.temp.mathtest.java

public static void main(String[] args) {

    final CurveFitter fitter = new CurveFitter(new LevenbergMarquardtOptimizer());
    fitter.addObservedPoint(-1.00, 2.021170021833143);
    fitter.addObservedPoint(-0.99, 2.221135431136975);
    fitter.addObservedPoint(-0.98, 2.09985277659314);
    fitter.addObservedPoint(-0.97, 2.0211192647627025);
    // ... Lots of lines omitted ...
    fitter.addObservedPoint(0.99, -2.4345814727089854);

    // The degree of the polynomial is deduced from the length of the array containing
    // the initial guess for the coefficients of the polynomial.
    final double[] init = { 12.9, -3.4, 2.1 }; // 12.9 - 3.4 x + 2.1 x^2

    // Compute optimal coefficients.
    final double[] best = fitter.fit(new PolynomialFunction.Parametric(), init);

    // Construct the polynomial that best fits the data.
    final PolynomialFunction fitted = new PolynomialFunction(best);
    System.out.println(fitted.value(-0.995));
    ;//  w w w.  j  a va 2s.  com
    System.out.println(fitted.value(0.995));
    ;
    System.out.println(fitted.toString());
    ;
    System.out.println("=============================================================");
    PolynomialCurveFitter pcf = PolynomialCurveFitter.create(3);
    WeightedObservedPoints s;
    List<WeightedObservedPoint> points = new ArrayList<WeightedObservedPoint>();
    points.add(new WeightedObservedPoint(1, -1.00, 2.021170021833143));
    points.add(new WeightedObservedPoint(1, -0.99, 2.221135431136975));
    points.add(new WeightedObservedPoint(1, -0.98, 2.09985277659314));
    points.add(new WeightedObservedPoint(1, -0.97, 2.0211192647627025));
    points.add(new WeightedObservedPoint(1, 0.99, 2.4345814727089854));
    double a[] = pcf.fit(points);
    for (int i = 0; i < a.length; i++) {
        double d = a[i];
        System.out.println(d);
    }
    System.out.println(compute(a, -0.995));
    System.out.println(compute(a, 0.99));
    System.out.println(compute(a, 0.995));

}

From source file:heizung.Heizkurve.java

public static PolynomialFunction getHeizkurve(String inifile) {
    PolynomialFunction result = null;
    try {/*w ww .j  av  a2  s  . c om*/
        // lesei
        System.out.println("inidatei: " + HoraFile.getCanonicalPath(inifile));
        String standard = "[{'x':20.0,'y':20.0},{'x':10,'y':35},{'x':0.0,'y':55}]";
        String s = HoraIni.LeseIniString(inifile, "Einstellung", "param", standard, true);
        JSONArray ja = new JSONArray(s);

        System.out.println(ja);
        List<Point> list = new ArrayList<Point>();
        for (int i = 0; i < ja.length(); i++) {
            JSONObject jo = ja.getJSONObject(i);
            System.out.println(jo.getDouble("x") + ", " + jo.getDouble("y"));
            list.add(new Point(jo.getDouble("x"), jo.getDouble("y")));
        }

        //
        if (list.size() >= 3) {
            result = getHeizKurve(list);
            for (int i = 0; i <= 20; i++) {
                System.out.println("x: " + i + ",  y:" + result.value(i));
            }
            double i = 10.56;
            System.out.println("x: " + i + ",  y:" + result.value(i));
        } else {
            System.out.println("Fehler. Mindestens 3 Eichpunkte ntig.");
            System.out.println("param: " + s);
        }

    } catch (JSONException ex) {
        Logger.getLogger(Heizkurve.class.getName()).log(Level.SEVERE, null, ex);
        System.out.println("ex");
    }
    return result;
}

From source file:eu.tango.energymodeller.energypredictor.CpuOnlyPolynomialEnergyPredictor.java

/**
 * This estimates the power used by a host, given its CPU load.
 *
 * @param host The host to get the energy prediction for
 * @param usageCPU The amount of CPU load placed on the host
 * @return The predicted power usage./*  w w  w  .j a v  a2s .c o m*/
 */
@Override
public double predictPowerUsed(Host host, double usageCPU) {
    PolynomialFunction model = retrieveModel(host).getFunction();
    return model.value(usageCPU);
}

From source file:eu.tango.energymodeller.energypredictor.CpuOnlyPolynomialEnergyPredictor.java

/**
 * This predicts the total amount of energy used by a host.
 *
 * @param host The host to get the energy prediction for
 * @param usageCPU The amount of CPU load placed on the host
 * @param timePeriod The time period the prediction is for
 * @return The predicted energy usage.// w w w. j  a  v  a 2 s.c om
 */
public EnergyUsagePrediction predictTotalEnergy(Host host, double usageCPU, TimePeriod timePeriod) {
    EnergyUsagePrediction answer = new EnergyUsagePrediction(host);
    PolynomialFunction model = retrieveModel(host).getFunction();
    double powerUsed = model.value(usageCPU);
    answer.setAvgPowerUsed(powerUsed);
    answer.setTotalEnergyUsed(powerUsed * ((double) TimeUnit.SECONDS.toHours(timePeriod.getDuration())));
    answer.setDuration(timePeriod);
    return answer;
}

From source file:eu.tango.energymodeller.energypredictor.CpuOnlyPolynomialEnergyPredictor.java

/**
 * This estimates the power used by a host, given its CPU load. The CPU load
 * value is determined from the settings file.
 *
 * @param host The host to get the energy prediction for.
 * @return The predicted power usage.// w  w  w .j  av a  2s .c  o  m
 */
@Override
public double predictPowerUsed(Host host) {
    PolynomialFunction model = retrieveModel(host).getFunction();
    if (getDefaultAssumedCpuUsage() == -1) {
        return model.value(getCpuUtilisation(host));
    } else {
        return model.value(getDefaultAssumedCpuUsage());
    }
}

From source file:curveavg.SolverTest.java

@Test
public void testQuinticZero_NewtonRaphsonFailureCase() {

    // Solve using NewtonRaphson and count the number of results
    float c[] = { -38.764412f, 76.10117f, -56.993206f, 28.603401f, -10.2824955f, 1.0f };
    MedialAxisTransform.SolverResult res = MedialAxisTransform.solveQuinticNewtonRaphson(c[0], c[1], c[2], c[3],
            c[4], c[5]);/*from   w w w.j  a  v a2s.  c  o m*/
    int rootsNR = 0;
    for (int i = 0; i < res.im.length; i++) {
        if (Math.abs(res.im[i]) < 1e-3)
            rootsNR++;
    }
    System.out.println("# NR roots: " + rootsNR);

    // Solve using NewtonRaphson and count the number of results
    MedialAxisTransform.SolverResult res2 = MedialAxisTransform.solveQuinticLaguerre(c[0], c[1], c[2], c[3],
            c[4], c[5]);
    int rootsL = 0;
    for (int i = 0; i < res.im.length; i++) {
        if (Math.abs(res2.im[i]) < 1e-3)
            rootsL++;
    }
    System.out.println("# L roots: " + rootsL);

    // Solve using Laguerre
    double dt = 0.01;
    double coefficients[] = new double[6];
    for (int i = 0; i < 6; i++)
        coefficients[i] = c[5 - i];
    PolynomialFunction f = new PolynomialFunction(coefficients);
    LaguerreSolver solver = new LaguerreSolver();
    for (double t = 0; t <= (1.0 - dt); t += dt) {

        // Check if there is a sign-crossing between the two times
        double t2 = t + dt;
        double f1 = f.value(t);
        double f2 = f.value(t2);
        if (Math.signum(f1) == Math.signum(f2))
            continue;

        // Compute using Laguerre
        double result = solver.solve(100, f, t, t2);
        System.out.println("Result: " + result);
    }

}

From source file:eu.tango.energymodeller.energypredictor.CpuAndAcceleratorEnergyPredictor.java

/**
 * This estimates the power used by a host, given its CPU load.
 *
 * @param host The host to get the energy prediction for
 * @param usageCPU The amount of CPU load placed on the host
 * @return The predicted power usage./*from w w  w .j ava 2  s .c  o m*/
 */
@Override
public double predictPowerUsed(Host host, double usageCPU) {
    PolynomialFunction model = retrieveCpuModel(host).getFunction();
    return model.value(usageCPU);
}

From source file:jurbano.melodyshape.comparison.bspline.Laguerre.java

/**
 * Computes the area between two {@link PolynomialFunction}s' first
 * derivatives, knowing the set of roots of their derivatives' difference.
 * /*from www.  j a  v  a2s . c  om*/
 * @param p1
 *            the first polynomial.
 * @param p2
 *            the second polynomial.
 * @param roots
 *            the known list of roots of the difference.
 * @return the area between the polynomials.
 */
public double computeAreaBetweenDerivatives(PolynomialFunction p1, PolynomialFunction p2,
        ArrayList<Double> roots) {
    double area = 0;
    for (int i = 1; i < roots.size(); i++) {
        area += Math.abs((p1.value(roots.get(i)) - p1.value(roots.get(i - 1)))
                - (p2.value(roots.get(i)) - p2.value(roots.get(i - 1))));
    }
    return area;
}

From source file:eu.tango.energymodeller.energypredictor.CpuAndAcceleratorEnergyPredictor.java

/**
 * This predicts the total amount of energy used by a host.
 *
 * @param host The host to get the energy prediction for
 * @param usageCPU The amount of CPU load placed on the host
 * @param accUsage The representation of the accelerators workload
 * @param timePeriod The time period the prediction is for
 * @return The predicted energy usage./*ww w  .ja v a 2  s  .c  o m*/
 */
public EnergyUsagePrediction predictTotalEnergy(Host host, double usageCPU,
        HashMap<Accelerator, HashMap<String, Double>> accUsage, TimePeriod timePeriod) {
    EnergyUsagePrediction answer = new EnergyUsagePrediction(host);
    PolynomialFunction cpuModel = retrieveCpuModel(host).getFunction();
    double powerUsed = cpuModel.value(usageCPU);
    //TODO fix the accelerator usage to mutliple accelerator mapping issue.
    for (Accelerator accelerator : host.getAccelerators()) {
        NeuralNetFunction acceleratorModel = retrieveAcceleratorModel(host, accelerator.getName())
                .getFunction();
        powerUsed = powerUsed + acceleratorModel.value(accUsage.get(accelerator));
    }
    answer.setAvgPowerUsed(powerUsed);
    answer.setTotalEnergyUsed(powerUsed * ((double) TimeUnit.SECONDS.toHours(timePeriod.getDuration())));
    answer.setDuration(timePeriod);
    return answer;
}