本文整理汇总了Java中de.linearbits.newtonraphson.Vector2D类的典型用法代码示例。如果您正苦于以下问题:Java Vector2D类的具体用法?Java Vector2D怎么用?Java Vector2D使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Vector2D类属于de.linearbits.newtonraphson包,在下文中一共展示了Vector2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: solve
import de.linearbits.newtonraphson.Vector2D; //导入依赖的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);
}
示例2: ModelSNB
import de.linearbits.newtonraphson.Vector2D; //导入依赖的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);
}
示例3: getObjectFunction
import de.linearbits.newtonraphson.Vector2D; //导入依赖的package包/类
/**
* Returns the object function
*
* @param k
* @param f
* @param c1
* @param c2
* @return
*/
private Function<Vector2D, Vector2D> getObjectFunction(final double k,
final double f,
final double c1,
final double c2) {
return new Function<Vector2D, Vector2D>() {
public Vector2D evaluate(Vector2D input) {
// The derivatives of the following formulas have been obtained using Matlab
final double a = input.x;
final double b = input.y;
final double dividend = (1 - f) * (1 - b);
// Original equations to determine the value of the parameters alpha and beta in the SNB Model
Vector2D result = new Vector2D();
result.x = k * f * Math.pow(b / (1 - dividend), a) *
(((a * dividend) / (1 - dividend)) + 1) - c1;
result.y = k * a * Math.pow(b, a) * (f * f) * (1 - b) / 2 *
Math.pow(1 - dividend, a + 2) *
(2 - (1 - a) * dividend) - c2;
return result;
}
};
}
示例4: getDerivativeFunction11
import de.linearbits.newtonraphson.Vector2D; //导入依赖的package包/类
/**
* Returns an implementation of the first derivative of the first object function:<br>
* 6 * x
* @return
*/
private static Function2D getDerivativeFunction11() {
return new Function2D() {
public Double evaluate(Vector2D input) {
return 6d * input.x;
}
};
}
示例5: getDerivativeFunction12
import de.linearbits.newtonraphson.Vector2D; //导入依赖的package包/类
/**
* Returns an implementation of the second derivative of the first object function:<br>
* 4 * y
* @return
*/
private static Function2D getDerivativeFunction12() {
return new Function2D() {
public Double evaluate(Vector2D input) {
return 4d * input.y;
}
};
}
示例6: getDerivativeFunction21
import de.linearbits.newtonraphson.Vector2D; //导入依赖的package包/类
/**
* Returns an implementation of the first derivative of the second object function:<br>
* 8 * x
* @return
*/
private static Function2D getDerivativeFunction21() {
return new Function2D() {
public Double evaluate(Vector2D input) {
return 8d * input.x;
}
};
}
示例7: getDerivativeFunction22
import de.linearbits.newtonraphson.Vector2D; //导入依赖的package包/类
/**
* Returns an implementation of the second derivative of the second object function:<br>
* - 6 * y
* @return
*/
private static Function2D getDerivativeFunction22() {
return new Function2D() {
public Double evaluate(Vector2D input) {
return - 6d * input.y;
}
};
}
示例8: getMasterFunction
import de.linearbits.newtonraphson.Vector2D; //导入依赖的package包/类
/**
* Returns the master function
* @return
*/
private static Function<Vector2D, Pair<Vector2D, SquareMatrix2D>> getMasterFunction() {
// Return function
return new Function<Vector2D, Pair<Vector2D, SquareMatrix2D>>() {
private final SquareMatrix2D derivatives = new SquareMatrix2D();
// Prepare result objects
private final Vector2D object = new Vector2D();
private final Pair<Vector2D, SquareMatrix2D> result = new Pair<Vector2D, SquareMatrix2D>(object, derivatives);
/**
* Eval
* @param input
* @return
*/
public Pair<Vector2D, SquareMatrix2D> evaluate(Vector2D input) {
// Prepare
double xSquare = input.x * input.x;
double ySquare = input.y * input.y;
// Compute
object.x = 3d * xSquare + 2d * ySquare - 35d;
object.y = 4d * xSquare - 3d * ySquare - 24d;
derivatives.x1 = + 6d * input.x;
derivatives.x2 = + 4d * input.y;
derivatives.y1 = + 8d * input.x;
derivatives.y2 = - 6d * input.y;
// Return
return result;
}
};
}
示例9: getObjectFunction1
import de.linearbits.newtonraphson.Vector2D; //导入依赖的package包/类
/**
* Returns an implementation of the first object function:<br>
* 3 * x^2 + 2 * y^2 - 35 = 0
* @return
*/
private static Function2D getObjectFunction1() {
return new Function2D() {
public Double evaluate(Vector2D input) {
return 3d * input.x * input.x + 2d * input.y * input.y - 35d;
}
};
}
示例10: getObjectFunction2
import de.linearbits.newtonraphson.Vector2D; //导入依赖的package包/类
/**
* Returns an implementation of the second object function:<br>
* 4 * x^2 - 3 * y^2 - 24 = 0
* @return
*/
private static Function2D getObjectFunction2() {
return new Function2D() {
public Double evaluate(Vector2D input) {
return 4d * input.x * input.x - 3d * input.y * input.y - 24d;
}
};
}
示例11: getConstraint
import de.linearbits.newtonraphson.Vector2D; //导入依赖的package包/类
/**
* Returns a constraint on theta
* @return
*/
private Constraint2D getConstraint() {
return new Constraint2D() {
@Override
public Boolean evaluate(Vector2D arg0) {
return arg0.x >= 0;
}
};
}
示例12: main
import de.linearbits.newtonraphson.Vector2D; //导入依赖的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);
}
示例13: ModelPitman
import de.linearbits.newtonraphson.Vector2D; //导入依赖的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);
}
示例14: getMasterFunctionClosed
import de.linearbits.newtonraphson.Vector2D; //导入依赖的package包/类
/**
* Returns the master function including the object function and the
* derivative functions
*
* @return
*/
private Function<Vector2D, Pair<Vector2D, SquareMatrix2D>>
getMasterFunctionClosed(final int[] classes,
final double u,
final double n) {
return new Function<Vector2D, Pair<Vector2D, SquareMatrix2D>>() {
// Init
private final SquareMatrix2D derivatives = new SquareMatrix2D();
private final Vector2D object = new Vector2D();
private final Pair<Vector2D, SquareMatrix2D> result = new Pair<Vector2D, SquareMatrix2D>(object,
derivatives);
@Override
public Pair<Vector2D, SquareMatrix2D> evaluate(Vector2D input) {
// Prepare
double t = input.x; // Theta
double a = input.y; // Alpha
// These closed forms have been verified with Matlab and Mathematica
double val0 = u - 1d;
double val1 = Gamma.digamma(val0 + (t / a) + 1d);
double val2 = Gamma.trigamma((a + t + (a * val0)) / a);
double val3 = Gamma.trigamma((t / a) + 1d);
double val4 = Gamma.digamma((t / a) + 1d);
double val5 = a * a;
double d1 = (val3 - val2) / (val5);
double d5 = (((a * val1) + (t * val2)) - (a * val4) - (t * val3)) / (val5 * a);
double d3 = (((((val5 * val0) - (t * t * val2)) + (t * t * val3)) -
(2d * a * t * val1)) + (2d * a * t * val4)) / (val5 * val5);
double o1 = (val1 - val4) / a;
double o3 = ((-t * val1) + (a * val0) + (t * val4)) / (a * a);
double o2 = Gamma.digamma(n + t) - Gamma.digamma(t + 1d);
checkInterrupt();
double d2 = Gamma.trigamma(t + 1d) - Gamma.trigamma(n + t);
// For each class...
double d4 = 0;
double o4 = 0;
double val6 = Gamma.digamma(1d - a);
double val7 = Gamma.trigamma(1d - a);
for (int i = 0; i < classes.length; i += 2) {
int key = classes[i];
int value = classes[i + 1];
if (key != 1) {
d4 += value * (val7 - Gamma.trigamma(key - a));
o4 += value * (Gamma.digamma(key - a) - val6);
}
checkInterrupt();
}
// Store
derivatives.x1 = d2 - d1;
derivatives.x2 = 0d - d5;
derivatives.y1 = 0d - d5;
derivatives.y2 = 0d - d3 - d4;
object.x = o1 - o2;
object.y = o3 - o4;
// Return
return result;
}
};
}
示例15: ModelPitman
import de.linearbits.newtonraphson.Vector2D; //导入依赖的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);
}