本文整理汇总了Java中org.apache.commons.math.analysis.UnivariateRealFunction类的典型用法代码示例。如果您正苦于以下问题:Java UnivariateRealFunction类的具体用法?Java UnivariateRealFunction怎么用?Java UnivariateRealFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UnivariateRealFunction类属于org.apache.commons.math.analysis包,在下文中一共展示了UnivariateRealFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: set
import org.apache.commons.math.analysis.UnivariateRealFunction; //导入依赖的package包/类
public Vec set(final Random random, final double noise, final Constants.TypeAdd type)
{
try {
counts.mapToSelf(new UnivariateRealFunction() {
@Override
public double value(double d) throws FunctionEvaluationException
{
return (type == TypeAdd.RANDOM) ? Math.pow(1 + random.nextDouble(), noise) :
random.nextDouble() * noise;
}
});
}
catch (FunctionEvaluationException ex) {
LogInfo.error(ex);
}
return computeSum();
}
示例2: wrapDifferentiable
import org.apache.commons.math.analysis.UnivariateRealFunction; //导入依赖的package包/类
/**
* @param f An OG 1-D function mapping doubles to doubles, not null
* @return A Commons differentiable univariate real function
*/
public static DifferentiableUnivariateRealFunction wrapDifferentiable(final DoubleFunction1D f) {
Validate.notNull(f);
return new DifferentiableUnivariateRealFunction() {
@Override
public double value(final double x) throws FunctionEvaluationException {
return f.evaluate(x);
}
@Override
public UnivariateRealFunction derivative() {
return wrapUnivariate(f.derivative());
}
};
}
示例3: set
import org.apache.commons.math.analysis.UnivariateRealFunction; //导入依赖的package包/类
public Vec set(final Random random, final double noise, final TypeAdd type)
{
try {
counts.mapToSelf(new UnivariateRealFunction() {
@Override
public double value(double d) throws FunctionEvaluationException
{
return (type == TypeAdd.RANDOM) ? Math.pow(1 + random.nextDouble(), noise) :
random.nextDouble() * noise;
}
});
}
catch (FunctionEvaluationException ex) {
LogInfo.error(ex);
}
return computeSum();
}
示例4: getFunction
import org.apache.commons.math.analysis.UnivariateRealFunction; //导入依赖的package包/类
@Override
public UnivariateRealFunction getFunction() {
CollectionType coefficients = interpreter.getCoefficients();
int i =0;
double[] co = new double[coefficients.getValues().size()];
for (DataType data:coefficients.getValues())
{
if (data.getType() == DataType.Type.DOUBLE)
{
co[i] = ((DoubleType)data).getValue();
}
i++;
}
if (co.length <= 0)
co = new double[]{0};
return new PolynomialFunction(co);
}
示例5: getFunction
import org.apache.commons.math.analysis.UnivariateRealFunction; //导入依赖的package包/类
@Override
public UnivariateRealFunction getFunction() {
CollectionType xKnots = interpreter.getXKnots();
CollectionType yKnots = interpreter.getYKnots();
int size = Math.min(xKnots.getValues().size(),yKnots.getValues().size());
double[] xs = new double[size];
double[] ys = new double[size];
for (int i = 0; i < size;i++)
{
DataType x = xKnots.getElement(i);
DataType y = yKnots.getElement(i);
if(y.getType() == DataType.Type.DOUBLE && x.getType() == DataType.Type.DOUBLE)
{
xs[i] = ((DoubleType)x).getValue();
ys[i] = ((DoubleType)y).getValue();
}else
xs[i] = Double.NEGATIVE_INFINITY;
}
return LinearInterpolator.getInstance().interpolate(xs, ys);
}
示例6: getFunction
import org.apache.commons.math.analysis.UnivariateRealFunction; //导入依赖的package包/类
@Override
public UnivariateRealFunction getFunction() {
CombinedTransformationFunction f = new CombinedTransformationFunction();
f.setScale(interpreter.getLocalScaleX(),interpreter.getLocalScaleY());
f.setTranslate(interpreter.getTranslateX(), interpreter.getTranslateY());
f.setBaseFunction(FunctionViewFactory.createFunctionView( interpreter.getFunction1()).getFunction());
UnivariateRealFunction function2 =FunctionViewFactory.createFunctionView( interpreter.getFunction2()).getFunction();
if(function2 instanceof LinearInterpolationFunction)//incase its null
f.setKnottedFunction((LinearInterpolationFunction)function2);
else
{
f.setKnottedFunction(LinearInterpolator.getInstance().interpolate(new double[0], new double[0]));
}
f.setLeft(interpreter.getLeft());
f.setRight(interpreter.getRight());
f.setBottom(interpreter.getBottom());
f.setTop(interpreter.getTop());
return f;
}
示例7: setFunction
import org.apache.commons.math.analysis.UnivariateRealFunction; //导入依赖的package包/类
public void setFunction(UnivariateRealFunction function, FunctionSettings f)
{
if (knots == null)
knots = new ArrayList<Knot>();
clearKnots();
if (function instanceof CombinedTransformationFunction)
{
this.transformFunction = (CombinedTransformationFunction) function;
this.baseFunction = transformFunction.getBaseFunction();
this.interpolatedFunction = transformFunction.getKnottedFunction();
buildKnots(interpolatedFunction);
}else
{
this.baseFunction = function;
this.interpolatedFunction = LinearInterpolator.getInstance().interpolate(null, null);
this.transformFunction = new CombinedTransformationFunction(interpolatedFunction,baseFunction,f.getMinX(),f.getMaxX(), f.getMaxY(), f.getMinY());
}
super.setFunction(transformFunction,f);
}
示例8: buildStandardFunction
import org.apache.commons.math.analysis.UnivariateRealFunction; //导入依赖的package包/类
private PropertyStore buildStandardFunction(UnivariateRealFunction f,String name, boolean zeroBased)
{
CombinedTransformationFunction fun = new CombinedTransformationFunction();
fun.setBaseFunction(f);
if (zeroBased)
{
fun.setScaleX(2f);
fun.setTranslateX(0.5f);
}
PropertyStore fStore = invertView(new PropertyStore(), fun);
FunctionSettingsInterpreter interp = new FunctionSettingsInterpreter(new PropertyStore());
interp.setFunction(fStore);
interp.setFunctionName(name);
return interp.getStore();
}
示例9: testInterpolateLinearDegenerateTwoSegment
import org.apache.commons.math.analysis.UnivariateRealFunction; //导入依赖的package包/类
public void testInterpolateLinearDegenerateTwoSegment()
throws Exception {
double x[] = { 0.0, 0.5, 1.0 };
double y[] = { 0.0, 0.5, 1.0 };
UnivariateRealInterpolator i = new SplineInterpolator();
UnivariateRealFunction f = i.interpolate(x, y);
verifyInterpolation(f, x, y);
verifyConsistency((PolynomialSplineFunction) f, x);
// Verify coefficients using analytical values
PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials();
double target[] = {y[0], 1d};
TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance);
target = new double[]{y[1], 1d};
TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance);
// Check interpolation
assertEquals(0.0,f.value(0.0), interpolationTolerance);
assertEquals(0.4,f.value(0.4), interpolationTolerance);
assertEquals(1.0,f.value(1.0), interpolationTolerance);
}
示例10: testQuinticFunction
import org.apache.commons.math.analysis.UnivariateRealFunction; //导入依赖的package包/类
/**
* Test of integrator for the quintic function.
*/
@Test
public void testQuinticFunction() throws MathException {
UnivariateRealFunction f = new QuinticFunction();
UnivariateRealIntegrator integrator = new RombergIntegrator();
double min, max, expected, result, tolerance;
min = 0; max = 1; expected = -1.0/48;
tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
Assert.assertEquals(expected, result, tolerance);
min = 0; max = 0.5; expected = 11.0/768;
tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
Assert.assertEquals(expected, result, tolerance);
min = -1; max = 4; expected = 2048/3.0 - 78 + 1.0/48;
tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
Assert.assertEquals(expected, result, tolerance);
}
示例11: testSinFunction
import org.apache.commons.math.analysis.UnivariateRealFunction; //导入依赖的package包/类
/**
* Test of integrator for the sine function.
*/
@Test
public void testSinFunction() throws MathException {
UnivariateRealFunction f = new SinFunction();
UnivariateRealIntegrator integrator = new TrapezoidIntegrator();
double min, max, expected, result, tolerance;
min = 0; max = FastMath.PI; expected = 2;
tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
Assert.assertEquals(expected, result, tolerance);
min = -FastMath.PI/3; max = 0; expected = -0.5;
tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
Assert.assertEquals(expected, result, tolerance);
}
示例12: testExpm1Function2
import org.apache.commons.math.analysis.UnivariateRealFunction; //导入依赖的package包/类
/**
* Test of solver for the exponential function using solve2().
* <p>
* It takes 25 to 50 iterations for the last two tests to converge.
*/
public void testExpm1Function2() throws MathException {
UnivariateRealFunction f = new Expm1Function();
MullerSolver solver = new MullerSolver();
double min, max, expected, result, tolerance;
min = -1.0; max = 2.0; expected = 0.0;
tolerance = Math.max(solver.getAbsoluteAccuracy(),
Math.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve2(f, min, max);
assertEquals(expected, result, tolerance);
min = -20.0; max = 10.0; expected = 0.0;
tolerance = Math.max(solver.getAbsoluteAccuracy(),
Math.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve2(f, min, max);
assertEquals(expected, result, tolerance);
min = -50.0; max = 100.0; expected = 0.0;
tolerance = Math.max(solver.getAbsoluteAccuracy(),
Math.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve2(f, min, max);
assertEquals(expected, result, tolerance);
}
示例13: derivative
import org.apache.commons.math.analysis.UnivariateRealFunction; //导入依赖的package包/类
/** {@inheritDoc} */
public UnivariateRealFunction derivative() {
return new UnivariateRealFunction() {
/** {@inheritDoc} */
public double value(double x) {
final double diff = x - mean;
final double g = Gaussian.value(diff, norm, i2s2);
if (g == 0) {
// Avoid returning NaN in case of overflow.
return 0;
} else {
return -2 * diff * i2s2 * g;
}
}
};
}
示例14: stage
import org.apache.commons.math.analysis.UnivariateRealFunction; //导入依赖的package包/类
/**
* Compute the n-th stage integral.
* @param f the integrand function
* @param min the lower bound for the interval
* @param max the upper bound for the interval
* @param n number of steps
* @return the value of n-th stage integral
* @throws FunctionEvaluationException if an error occurs evaluating the
* function
*/
private double stage(final UnivariateRealFunction f,
final double min, final double max, final int n)
throws FunctionEvaluationException {
// set up the step for the current stage
final double step = (max - min) / n;
final double halfStep = step / 2.0;
// integrate over all elementary steps
double midPoint = min + halfStep;
double sum = 0.0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < abscissas.length; ++j) {
sum += weights[j] * f.value(midPoint + halfStep * abscissas[j]);
}
midPoint += step;
}
return halfStep * sum;
}
示例15: testSinFunction
import org.apache.commons.math.analysis.UnivariateRealFunction; //导入依赖的package包/类
/**
* Test of integrator for the sine function.
*/
public void testSinFunction() throws MathException {
UnivariateRealFunction f = new SinFunction();
UnivariateRealIntegrator integrator = new RombergIntegrator();
double min, max, expected, result, tolerance;
min = 0; max = Math.PI; expected = 2;
tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
assertEquals(expected, result, tolerance);
min = -Math.PI/3; max = 0; expected = -0.5;
tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
assertEquals(expected, result, tolerance);
}