當前位置: 首頁>>代碼示例>>Java>>正文


Java NewtonRaphson2D類代碼示例

本文整理匯總了Java中de.linearbits.newtonraphson.NewtonRaphson2D的典型用法代碼示例。如果您正苦於以下問題:Java NewtonRaphson2D類的具體用法?Java NewtonRaphson2D怎麽用?Java NewtonRaphson2D使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NewtonRaphson2D類屬於de.linearbits.newtonraphson包,在下文中一共展示了NewtonRaphson2D類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: solve

import de.linearbits.newtonraphson.NewtonRaphson2D; //導入依賴的package包/類
/**
 * Solves and prints measures
 * @param object1
 * @param object2
 * @param solver
 */
private static void solve(Function2D object1, Function2D object2, NewtonRaphson2D solver, int repetitions) {
    
    Vector2D result = null;
    long start = System.currentTimeMillis();
    for (int i=0; i< repetitions; i++) {
        result = solver.solve();
    }
    
    System.out.println("\nResults");
    System.out.println("*******");
    
    DecimalFormat format = new DecimalFormat("0.000000");
    double time = (System.currentTimeMillis() - start) / (double)repetitions;
    System.out.println("Time    : " + format.format(time));
    System.out.println(solver.getMeasures());
    System.out.println("Result  : " + result);
}
 
開發者ID:prasser,項目名稱:newtonraphson,代碼行數:24,代碼來源:Tests.java

示例2: ModelSNB

import de.linearbits.newtonraphson.NewtonRaphson2D; //導入依賴的package包/類
/**
 * Creates a new instance
 * 
 * @param model
 * @param histogram
 * @param config
 * @param stop
 */
ModelSNB(final ARXPopulationModel model,
         final RiskModelHistogram histogram,
         final NewtonRaphsonConfiguration<?> config,
         final WrappedBoolean stop) {

    super(histogram, model, stop, new WrappedInteger());

    // Prepare
    int[] _histogram = super.getHistogram().getHistogram();
    double c1 = super.getNumClassesOfSize(1);
    double c2 = super.getNumClassesOfSize(2);
    double k = estimateNonEmptyEquivalenceClasses(_histogram, super.getNumClasses(),
                                                  c1, super.getSamplingFraction());
    double f = getSamplingFraction();

    // Solve the maximum likelihood estimates
    Vector2D result = new NewtonRaphson2D(getObjectFunction(k, f, c1, c2),
                                          getDerivatives(k, f, c1, c2))
                                         .configure(config)
                                         .solve();

    // Compile and store
    this.uniques = k * Math.pow(result.y, result.x);
}
 
開發者ID:arx-deidentifier,項目名稱:arx,代碼行數:33,代碼來源:ModelSNB.java

示例3: main

import de.linearbits.newtonraphson.NewtonRaphson2D; //導入依賴的package包/類
/**
 * Entry point
 * @param args
 */
public static void main(String[] args) {
    
    // First object function : 3 * x^2 + 2 * y^2 - 35 = 0
    // Second object function: 4 * x^2 - 3 * y^2 - 24 = 0
    //
    // This system has four solutions: (+-3, +-2)
    
    /* ****************************
     *  Solve without derivatives *
     ******************************/

    Function2D object1 = getObjectFunction1();
    Function2D object2 = getObjectFunction2();
    
    NewtonRaphson2D solver = new NewtonRaphson2D(object1, object2)
                                                 .accuracy(1e-6)
                                                 .iterationsPerTry(1000)
                                                 .iterationsTotal(100000);
    
    solve(object1, object2, solver, 1000000);

    /* *************************************************
     *  Solve without derivatives but with constraints *
     ***************************************************/

    // We want a solution in the negative range
    Constraint2D constraint = new Constraint2D(){ 
        public Boolean evaluate(Vector2D input) { 
            return input.x < 0 && input.y < 0; 
        }
    };
    
    solver = new NewtonRaphson2D(object1, object2, constraint)
                                 .accuracy(1e-6)
                                 .iterationsPerTry(1000)
                                 .iterationsTotal(100000);
    
    solve(object1, object2, solver, 1000000);
    
    /* *************************
     *  Solve with derivatives *
     ***************************/
    
    Function2D derivative11 = getDerivativeFunction11();
    Function2D derivative12 = getDerivativeFunction12();
    Function2D derivative21 = getDerivativeFunction21();
    Function2D derivative22 = getDerivativeFunction22();

    solver = new NewtonRaphson2D(object1, object2, 
                                 derivative11, derivative12,
                                 derivative21, derivative22)
                                 .accuracy(1e-6)
                                 .iterationsPerTry(1000)
                                 .iterationsTotal(100000);
    
    Function2DUtil util = new Function2DUtil();
    System.out.println("\nChecking derivatives:");
    System.out.println("Is derivative: " + util.isDerivativeFunction1(object1, derivative11, 0.01, 100, 0.001, 0.1d, 0.01d));
    System.out.println("Is derivative: " + util.isDerivativeFunction2(object1, derivative12, 0.01, 100, 0.001, 0.1d, 0.01d));
    System.out.println("Is derivative: " + util.isDerivativeFunction1(object2, derivative21, 0.01, 100, 0.001, 0.1d, 0.01d));
    System.out.println("Is derivative: " + util.isDerivativeFunction2(object2, derivative22, 0.01, 100, 0.001, 0.1d, 0.01d));
    
    solve(object1, object2, solver, 1000000);
    
    /* *****************************
     *  Solve with master function *
     *******************************/
    
    Function<Vector2D, Pair<Vector2D, SquareMatrix2D>> master = getMasterFunction();
    solver = new NewtonRaphson2D(master)
                                 .accuracy(1e-6)
                                 .iterationsPerTry(1000)
                                 .iterationsTotal(100000);
    
    solve(object1, object2, solver, 1000000);
}
 
開發者ID:prasser,項目名稱:newtonraphson,代碼行數:81,代碼來源:Tests.java

示例4: ModelPitman

import de.linearbits.newtonraphson.NewtonRaphson2D; //導入依賴的package包/類
/**
 * Creates a new instance
 * 
 * @param model
 * @param histogram
 * @param sampleSize
 * @param config
 * @param stop
 */
ModelPitman(final ARXPopulationModel model,
            final RiskModelHistogram histogram,
            final int sampleSize,
            final NewtonRaphsonConfiguration<?> config,
            final WrappedBoolean stop) {
    
    super(histogram, model, sampleSize, stop, new WrappedInteger());

    // Init
    double c1 = getNumClassesOfSize(1);
    double c2 = getNumClassesOfSize(2);
    double u = getNumClasses();
    double p = getPopulationSize();
    double n = sampleSize;

    // Initial guess
    c2 = c2 != 0 ? c2 : 1; // Overestimate
    double c = (c1 * (c1 - 1)) / c2;
    double t = ((n * u * c) - (c1 * (n - 1) * ((2 * u) + c))) /
               (((2 * c1 * u) + (c1 * c)) - (n * c));
    double a = ((t * (c1 - n)) + ((n - 1) * c1)) / (n * u);

    // Prepare
    NewtonRaphson2D solver = null;
    Vector2D result = new Vector2D(Double.NaN, Double.NaN);

    // Solve the Maximum Likelihood Estimates with Polygamma functions
    if (usePolygamma) {
        solver = new NewtonRaphson2D(getMasterFunctionClosed(histogram.getHistogram(), u, n)).configure(config);
        result = solver.solve(new Vector2D(t, a));
    }

    // If no result found, use iterative implementation
    if (Double.isNaN(result.x) || Double.isNaN(result.y)) {

        solver = new NewtonRaphson2D(getMasterFunctionIterative(histogram.getHistogram(), u, n)).configure(config);
        result = solver.solve(new Vector2D(t, a));

        // Else check the result against the iterative implementation
    } else {

        // Run test
        Vector2D test = getObjectFunctionsIterative(histogram.getHistogram(), u, n).evaluate(result);

        // Check result of test
        if (Double.isNaN(test.x) || Double.isNaN(test.y) ||
            Math.abs(test.x) > config.getAccuracy() ||
            Math.abs(test.y) > config.getAccuracy()) {

            // Use iterative implementation
            solver = new NewtonRaphson2D(getMasterFunctionIterative(histogram.getHistogram(),
                                                                    u,
                                                                    n)).configure(config);
            result = solver.solve(new Vector2D(t, a));
        }
    }

    // Compile the result
    this.numUniques = getResult(result, p);
}
 
開發者ID:arx-deidentifier,項目名稱:risk-benchmark,代碼行數:70,代碼來源:ModelPitman.java

示例5: ModelPitman

import de.linearbits.newtonraphson.NewtonRaphson2D; //導入依賴的package包/類
/**
 * Creates a new instance
 * 
 * @param model
 * @param histogram
 * @param config
 * @param stop
 */
ModelPitman(final ARXPopulationModel model,
            final RiskModelHistogram histogram,
            final NewtonRaphsonConfiguration<?> config,
            final WrappedBoolean stop) {

    super(histogram, model, stop, new WrappedInteger());

    // Init
    double c1 = getNumClassesOfSize(1);
    double c2 = getNumClassesOfSize(2);
    double u = getNumClasses();
    double p = getPopulationSize();
    double n = super.getSampleSize();

    // Initial guess
    c2 = c2 != 0 ? c2 : 1; // Overestimate
    double c = (c1 * (c1 - 1)) / c2;
    double t = ((n * u * c) - (c1 * (n - 1) * ((2 * u) + c))) /
               (((2 * c1 * u) + (c1 * c)) - (n * c));
    double a = ((t * (c1 - n)) + ((n - 1) * c1)) / (n * u);

    // Solve the Maximum Likelihood Estimates with Polygamma functions
    NewtonRaphson2D solver = new NewtonRaphson2D(getMasterFunctionClosed(histogram.getHistogram(), u, n),
                                                 getConstraint()).configure(config);
    Vector2D result = solver.solve(new Vector2D(t, a));

    // If no result found, use iterative implementation
    if (Double.isNaN(result.x) || Double.isNaN(result.y)) {

        solver = new NewtonRaphson2D(getMasterFunctionIterative(histogram.getHistogram(), u, n),
                                     getConstraint()).configure(config);
        result = solver.solve(new Vector2D(t, a));

        // Else check the result against the iterative implementation
    } else {

        // Run test
        Vector2D test = getObjectFunctionsIterative(histogram.getHistogram(), u, n).evaluate(result);

        // Check result of test
        if (Double.isNaN(test.x) || Double.isNaN(test.y) ||
            Math.abs(test.x) > config.getAccuracy() ||
            Math.abs(test.y) > config.getAccuracy()) {

            // Use iterative implementation
            solver = new NewtonRaphson2D(getMasterFunctionIterative(histogram.getHistogram(), u, n),
                                                                    getConstraint()).configure(config);
            result = solver.solve(new Vector2D(t, a));
        }
    }

    // Compile the result
    this.numUniques = getResult(result, p);
}
 
開發者ID:arx-deidentifier,項目名稱:arx,代碼行數:63,代碼來源:ModelPitman.java


注:本文中的de.linearbits.newtonraphson.NewtonRaphson2D類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。