• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java UnivariateDifferentiableFunction类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction的典型用法代码示例。如果您正苦于以下问题:Java UnivariateDifferentiableFunction类的具体用法?Java UnivariateDifferentiableFunction怎么用?Java UnivariateDifferentiableFunction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



UnivariateDifferentiableFunction类属于org.apache.commons.math3.analysis.differentiation包,在下文中一共展示了UnivariateDifferentiableFunction类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testMath832

import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; //导入依赖的package包/类
@Test
public void testMath832() {
    final UnivariateFunction f = new UnivariateFunction() {
            private final UnivariateDifferentiableFunction sqrt = new Sqrt();
            private final UnivariateDifferentiableFunction inv = new Inverse();
            private final UnivariateDifferentiableFunction func
                = FunctionUtils.add(FunctionUtils.multiply(new Constant(1e2), sqrt),
                                    FunctionUtils.multiply(new Constant(1e6), inv),
                                    FunctionUtils.multiply(new Constant(1e4),
                                                           FunctionUtils.compose(inv, sqrt)));

            public double value(double x) {
                return func.value(new DerivativeStructure(1, 1, 0, x)).getPartialDerivative(1);
            }

        };

    BrentSolver solver = new BrentSolver();
    final double result = solver.solve(99, f, 1, 1e30, 1 + 1e-10);
    Assert.assertEquals(804.93558250, result, 1e-8);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:22,代码来源:BrentSolverTest.java


示例2: testMultiplyDifferentiable

import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; //导入依赖的package包/类
@Test
public void testMultiplyDifferentiable() {
    UnivariateDifferentiableFunction c = new Constant(4);
    UnivariateDifferentiableFunction id = new Identity();
    final double a = 1.2345678;
    Assert.assertEquals(8 * a, FunctionUtils.multiply(c, id, id).value(new DerivativeStructure(1, 1, 0, a)).getPartialDerivative(1), EPS);

    UnivariateDifferentiableFunction inv = new Inverse();
    UnivariateDifferentiableFunction pow = new Power(2.5);
    UnivariateDifferentiableFunction cos = new Cos();
    Assert.assertEquals(1.5 * FastMath.sqrt(a) * FastMath.cos(a) - FastMath.pow(a, 1.5) * FastMath.sin(a),
                        FunctionUtils.multiply(inv, pow, cos).value(new DerivativeStructure(1, 1, 0, a)).getPartialDerivative(1), EPS);

    UnivariateDifferentiableFunction cosh = new Cosh();
    Assert.assertEquals(1.5 * FastMath.sqrt(a) * FastMath.cosh(a) + FastMath.pow(a, 1.5) * FastMath.sinh(a),
                        FunctionUtils.multiply(inv, pow, cosh).value(new DerivativeStructure(1, 1, 0, a)).getPartialDerivative(1), 8 * EPS);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:18,代码来源:FunctionUtilsTest.java


示例3: toUnivariateDifferential

import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; //导入依赖的package包/类
/**
 * Convert a {@link DifferentiableUnivariateFunction} into a {@link UnivariateDifferentiableFunction}.
 * <p>
 * Note that the converted function is able to handle {@link DerivativeStructure} up to order one.
 * If the function is called with higher order, a {@link NumberIsTooLargeException} is thrown.
 * </p>
 * @param f function to convert
 * @return converted function
 * @deprecated this conversion method is temporary in version 3.1, as the {@link
 * DifferentiableUnivariateFunction} interface itself is deprecated
 */
@Deprecated
public static UnivariateDifferentiableFunction toUnivariateDifferential(final DifferentiableUnivariateFunction f) {
    return new UnivariateDifferentiableFunction() {

        /** {@inheritDoc} */
        public double value(final double x) {
            return f.value(x);
        }

        /** {@inheritDoc}
         * @exception NumberIsTooLargeException if derivation order is greater than 1
         */
        public DerivativeStructure value(final DerivativeStructure t)
            throws NumberIsTooLargeException {
            switch (t.getOrder()) {
                case 0 :
                    return new DerivativeStructure(t.getFreeParameters(), 0, f.value(t.getValue()));
                case 1 : {
                    final int parameters = t.getFreeParameters();
                    final double[] derivatives = new double[parameters + 1];
                    derivatives[0] = f.value(t.getValue());
                    final double fPrime = f.derivative().value(t.getValue());
                    int[] orders = new int[parameters];
                    for (int i = 0; i < parameters; ++i) {
                        orders[i] = 1;
                        derivatives[i + 1] = fPrime * t.getPartialDerivative(orders);
                        orders[i] = 0;
                    }
                    return new DerivativeStructure(parameters, 1, derivatives);
                }
                default :
                    throw new NumberIsTooLargeException(t.getOrder(), 1, true);
            }
        }

    };
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:49,代码来源:FunctionUtils.java


示例4: toUnivariateDifferential

import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; //导入依赖的package包/类
/** Convert a {@link DifferentiableUnivariateFunction} into a {@link UnivariateDifferentiableFunction}.
 * <p>
 * Note that the converted function is able to handle {@link DerivativeStructure} up to order one.
 * If the function is called with higher order, a {@link NumberIsTooLargeException} will be thrown.
 * </p>
 * @param f function to convert
 * @return converted function
 * @deprecated this conversion method is temporary in version 3.1, as the {@link
 * DifferentiableUnivariateFunction} interface itself is deprecated
 */
@Deprecated
public static UnivariateDifferentiableFunction toUnivariateDifferential(final DifferentiableUnivariateFunction f) {
    return new UnivariateDifferentiableFunction() {

        /** {@inheritDoc} */
        public double value(final double x) {
            return f.value(x);
        }

        /** {@inheritDoc}
         * @exception NumberIsTooLargeException if derivation order is greater than 1
         */
        public DerivativeStructure value(final DerivativeStructure t)
            throws NumberIsTooLargeException {
            switch (t.getOrder()) {
                case 0 :
                    return new DerivativeStructure(t.getFreeParameters(), 0, f.value(t.getValue()));
                case 1 : {
                    final int parameters = t.getFreeParameters();
                    final double[] derivatives = new double[parameters + 1];
                    derivatives[0] = f.value(t.getValue());
                    final double fPrime = f.derivative().value(t.getValue());
                    int[] orders = new int[parameters];
                    for (int i = 0; i < parameters; ++i) {
                        orders[i] = 1;
                        derivatives[i + 1] = fPrime * t.getPartialDerivative(orders);
                        orders[i] = 0;
                    }
                    return new DerivativeStructure(parameters, 1, derivatives);
                }
                default :
                    throw new NumberIsTooLargeException(t.getOrder(), 1, true);
            }
        }

    };
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:48,代码来源:FunctionUtils.java


示例5: testValueWithInverseFunction

import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; //导入依赖的package包/类
@Test
public void testValueWithInverseFunction() {
    final double lo = 2;
    final double hi = 3;
    final Logit f = new Logit(lo, hi);
    final Sigmoid g = new Sigmoid(lo, hi);
    RandomGenerator random = new Well1024a(0x49914cdd9f0b8db5l);
    final UnivariateDifferentiableFunction id = FunctionUtils.compose((UnivariateDifferentiableFunction) g,
                                                            (UnivariateDifferentiableFunction) f);

    for (int i = 0; i < 10; i++) {
        final double x = lo + random.nextDouble() * (hi - lo);
        Assert.assertEquals(x, id.value(new DerivativeStructure(1, 1, 0, x)).getValue(), EPS);
    }

    Assert.assertEquals(lo, id.value(new DerivativeStructure(1, 1, 0, lo)).getValue(), EPS);
    Assert.assertEquals(hi, id.value(new DerivativeStructure(1, 1, 0, hi)).getValue(), EPS);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:19,代码来源:LogitTest.java


示例6: testComposeDifferentiable

import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; //导入依赖的package包/类
@Test
public void testComposeDifferentiable() {
    UnivariateDifferentiableFunction id = new Identity();
    Assert.assertEquals(1, FunctionUtils.compose(id, id, id).value(new DerivativeStructure(1, 1, 0, 3)).getPartialDerivative(1), EPS);

    UnivariateDifferentiableFunction c = new Constant(4);
    Assert.assertEquals(0, FunctionUtils.compose(id, c).value(new DerivativeStructure(1, 1, 0, 3)).getPartialDerivative(1), EPS);
    Assert.assertEquals(0, FunctionUtils.compose(c, id).value(new DerivativeStructure(1, 1, 0, 3)).getPartialDerivative(1), EPS);

    UnivariateDifferentiableFunction m = new Minus();
    Assert.assertEquals(-1, FunctionUtils.compose(m).value(new DerivativeStructure(1, 1, 0, 3)).getPartialDerivative(1), EPS);
    Assert.assertEquals(1, FunctionUtils.compose(m, m).value(new DerivativeStructure(1, 1, 0, 3)).getPartialDerivative(1), EPS);

    UnivariateDifferentiableFunction inv = new Inverse();
    Assert.assertEquals(0.25, FunctionUtils.compose(inv, m, id).value(new DerivativeStructure(1, 1, 0, 2)).getPartialDerivative(1), EPS);

    UnivariateDifferentiableFunction pow = new Power(2);
    Assert.assertEquals(108, FunctionUtils.compose(pow, pow).value(new DerivativeStructure(1, 1, 0, 3)).getPartialDerivative(1), EPS);

    UnivariateDifferentiableFunction log = new Log();
    double a = 9876.54321;
    Assert.assertEquals(pow.value(new DerivativeStructure(1, 1, 0, a)).getPartialDerivative(1) / pow.value(a),
                        FunctionUtils.compose(log, pow).value(new DerivativeStructure(1, 1, 0, a)).getPartialDerivative(1), EPS);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:25,代码来源:FunctionUtilsTest.java


示例7: testToUnivariateDifferential

import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; //导入依赖的package包/类
@Test
@Deprecated
public void testToUnivariateDifferential() {

    // Sin implements both UnivariateDifferentiableFunction and DifferentiableUnivariateFunction
    Sin sin = new Sin();
    UnivariateDifferentiableFunction converted = FunctionUtils.toUnivariateDifferential(sin);
    for (double x = 0.1; x < 0.5; x += 0.01) {
        DerivativeStructure t = new DerivativeStructure(2, 1, x, 1.0, 2.0);
        Assert.assertEquals(sin.value(t).getValue(), converted.value(t).getValue(), 1.0e-10);
        Assert.assertEquals(sin.value(t).getPartialDerivative(1, 0),
                            converted.value(t).getPartialDerivative(1, 0),
                            1.0e-10);
        Assert.assertEquals(sin.value(t).getPartialDerivative(0, 1),
                            converted.value(t).getPartialDerivative(0, 1),
                            1.0e-10);
    }

}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:20,代码来源:FunctionUtilsTest.java


示例8: testMultiplyDifferentiable

import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; //导入依赖的package包/类
@Test
public void testMultiplyDifferentiable() {
    UnivariateDifferentiableFunction c = new Constant(4);
    UnivariateDifferentiableFunction id = new Identity();
    final double a = 1.2345678;
    Assert.assertEquals(8 * a, FunctionUtils.multiply(c, id, id).value(new DerivativeStructure(1, 1, 0, a)).getPartialDerivative(1), EPS);

    UnivariateDifferentiableFunction inv = new Inverse();
    UnivariateDifferentiableFunction pow = new Power(2.5);
    UnivariateDifferentiableFunction cos = new Cos();
    Assert.assertEquals(1.5 * Math.sqrt(a) * Math.cos(a) - Math.pow(a, 1.5) * Math.sin(a),
                        FunctionUtils.multiply(inv, pow, cos).value(new DerivativeStructure(1, 1, 0, a)).getPartialDerivative(1), EPS);

    UnivariateDifferentiableFunction cosh = new Cosh();
    Assert.assertEquals(1.5 * Math.sqrt(a) * Math.cosh(a) + Math.pow(a, 1.5) * Math.sinh(a),
                        FunctionUtils.multiply(inv, pow, cosh).value(new DerivativeStructure(1, 1, 0, a)).getPartialDerivative(1), 8 * EPS);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:18,代码来源:FunctionUtilsTest.java


示例9: log

import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; //导入依赖的package包/类
public Variable log(Transform transform, Variable numericVariable, Map<String, TransformOption> options) throws Exception {

        double[] rawData = numericVariable.getData();// check of <= 0
        if (numericVariable.calculateUnivariateStats().get(UnivariateStat.getStats().get("min")).get(0)[0] <= 0) {
            Transform scaleTransform = new Transform("scale", null, numericVariable, getStatLib());
            numericVariable = scaleTransform.transform();
            VariableDAO.getInstance().createVariableRow(numericVariable);
        }

        UnivariateDifferentiableFunction function = new Log();
        double[] logData = new double[rawData.length];
        for (int i = 0; i < rawData.length; i++) {
            logData[i] = function.value(rawData[i]);
        }

        Instances weka = new Util().createWekaData(logData, transform.toString());

        return new Variable(numericVariable, transform, transform.toString(), numericVariable.getLab(), logData, weka, numericVariable.getDateFormat(), VariableType.NUMERIC);
    }
 
开发者ID:williamClanton,项目名称:jbossBA,代码行数:20,代码来源:WekaApacheEngine.java


示例10: inverse

import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; //导入依赖的package包/类
public Variable inverse(Transform transform, Variable numericVariable, Map<String, TransformOption> options) throws Exception {

        if (numericVariable.calculateUnivariateStats().get("min").get(0)[0] <= 0) {
            Transform scaleTransform = new Transform("scale", null, numericVariable, getStatLib());
            numericVariable = scaleTransform.transform();
            VariableDAO.getInstance().createVariableRow(numericVariable);
        }
        UnivariateDifferentiableFunction function = new Inverse();
        double[] origData = numericVariable.getData();
        double[] newData = new double[origData.length];
        for (int i = 0; i < origData.length; i++) {
            newData[i] = function.value(origData[i]);
        }

        Instances weka = new Util().createWekaData(newData, transform.toString());
        return new Variable(numericVariable, transform, transform.toString(), numericVariable.getLab(), newData, weka, numericVariable.getDateFormat(), VariableType.NUMERIC);
    }
 
开发者ID:williamClanton,项目名称:jbossBA,代码行数:18,代码来源:WekaApacheEngine.java


示例11: setup

import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
protected void setup(int maxEval, UnivariateDifferentiableFunction f,
                     double min, double max, double startValue) {
    super.setup(maxEval, f, min, max, startValue);
    function = f;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:10,代码来源:AbstractUnivariateDifferentiableSolver.java


示例12: testSinZero

import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; //导入依赖的package包/类
/**
 *
 */
@Test
public void testSinZero() {
    UnivariateDifferentiableFunction f = new Sin();
    double result;

    NewtonRaphsonSolver solver = new NewtonRaphsonSolver();
    result = solver.solve(100, f, 3, 4);
    Assert.assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());

    result = solver.solve(100, f, 1, 4);
    Assert.assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());

    Assert.assertTrue(solver.getEvaluations() > 0);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:18,代码来源:NewtonRaphsonSolverTest.java


示例13: testQuinticZero

import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; //导入依赖的package包/类
/**
 *
 */
@Test
public void testQuinticZero() {
    final UnivariateDifferentiableFunction f = new QuinticFunction();
    double result;

    NewtonRaphsonSolver solver = new NewtonRaphsonSolver();
    result = solver.solve(100, f, -0.2, 0.2);
    Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());

    result = solver.solve(100, f, -0.1, 0.3);
    Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());

    result = solver.solve(100, f, -0.3, 0.45);
    Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());

    result = solver.solve(100, f, 0.3, 0.7);
    Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());

    result = solver.solve(100, f, 0.2, 0.6);
    Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());

    result = solver.solve(100, f, 0.05, 0.95);
    Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());

    result = solver.solve(100, f, 0.85, 1.25);
    Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());

    result = solver.solve(100, f, 0.8, 1.2);
    Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());

    result = solver.solve(100, f, 0.85, 1.75);
    Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());

    result = solver.solve(100, f, 0.55, 1.45);
    Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());

    result = solver.solve(100, f, 0.85, 5);
    Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:43,代码来源:NewtonRaphsonSolverTest.java


示例14: testDerivatives

import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; //导入依赖的package包/类
@Test
public void testDerivatives() {
    final UnivariateDifferentiableFunction gaussian = new Gaussian(2.0, 0.9, 3.0);
    final DerivativeStructure dsX = new DerivativeStructure(1, 4, 0, 1.1);
    final DerivativeStructure dsY = gaussian.value(dsX);
    Assert.assertEquals( 1.9955604901712128349,   dsY.getValue(),              EPS);
    Assert.assertEquals(-0.044345788670471396332, dsY.getPartialDerivative(1), EPS);
    Assert.assertEquals(-0.22074348138190206174,  dsY.getPartialDerivative(2), EPS);
    Assert.assertEquals( 0.014760030401924800557, dsY.getPartialDerivative(3), EPS);
    Assert.assertEquals( 0.073253159785035691678, dsY.getPartialDerivative(4), EPS);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:12,代码来源:GaussianTest.java


示例15: testDerivativeComparison

import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; //导入依赖的package包/类
@Test
public void testDerivativeComparison() {
    final UnivariateDifferentiableFunction sPrime = new Sqrt();
    final UnivariateFunction f = new UnivariateFunction() {
            public double value(double x) {
                return 1 / (2 * FastMath.sqrt(x));
            }
        };

    for (double x = 1e-30; x < 1e10; x *= 2) {
        final double fX = f.value(x);
        final double sX = sPrime.value(new DerivativeStructure(1, 1, 0, x)).getPartialDerivative(1);
        Assert.assertEquals("x=" + x, fX, sX, FastMath.ulp(fX));
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:16,代码来源:SqrtTest.java


示例16: testAddDifferentiable

import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; //导入依赖的package包/类
@Test
public void testAddDifferentiable() {
    UnivariateDifferentiableFunction sin = new Sin();
    UnivariateDifferentiableFunction c = new Constant(4);
    UnivariateDifferentiableFunction m = new Minus();
    UnivariateDifferentiableFunction inv = new Inverse();

    final double a = 123.456;
    Assert.assertEquals(- 1 / (a * a) -1 + FastMath.cos(a),
                        FunctionUtils.add(inv, m, c, sin).value(new DerivativeStructure(1, 1, 0, a)).getPartialDerivative(1),
                        EPS);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:13,代码来源:FunctionUtilsTest.java



注:本文中的org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java VariableInplaceRenameHandler类代码示例发布时间:2022-05-23
下一篇:
Java FragmenterInstructions类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap