commons-math3-3.6.1-org.apache.commons.math3.analysis.function-包下的类(二)-中英对照文档及源码赏析
摘要:中英对照文档、源码赏析、org.apache.commons.math3.analysis.function、Divide、Exp、Expm1、Floor、Gaussian、HarmonicOscillator、Identity、Inverse、Log、Log1p、Log10、Logistic、Logit、Max
完整中文文档、中英对照文档下载请移步:commons-math3-中文文档、中英对照文档-CSDN下载
1. 开源组件说明
jar包名称:commons-math3-3.6.1.jar
Maven 依赖:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
完整中文文档、中英对照文档下载请移步:commons-math3-中文文档、中英对照文档-CSDN下载
程序包 org.apache.commons.math3.analysis.function
function
package contains function objects that wrap the methods contained in
Math
, as well as common mathematical functions such as the gaussian and sinc functions.
函数包包含运算对象,该功能将包含在数学中包含的方法,以及诸如高斯和SINC功能的常见数学函数。
See: 说明
-
类 Summary 类 说明 Abs Absolute value function.
绝对值函数。
Acos Arc-cosine function.
arc-canine功能。
Acosh Hyperbolic arc-cosine function.
双曲线弧余弦功能。
Add Add the two operands.
添加两个操作数。
Asin Arc-sine function.
arc-sine函数。
Asinh Hyperbolic arc-sine function.
双曲线弧形函数。
Atan Arc-tangent function.
弧形功能。
Atan2 Arc-tangent function.
弧形功能。
Atanh Hyperbolic arc-tangent function.
双曲线弧形功能。
Cbrt Cube root function.
立方根函数。
Ceil ceil
function.
CEIL功能。
Constant Constant function.
常量功能。
Cos Cosine function.
余弦功能。
Cosh Hyperbolic cosine function.
双曲余弦功能。
Divide Divide the first operand by the second.
将第一个操作数划分为第二个操作数。
Exp Exponential function.
指数函数。
Expm1 ex-1
function.
前1个功能。
Floor floor
function.
地板功能。
Gaussian Gaussian.Parametric Parametric function where the input array contains the parameters of the Gaussian, ordered as follows: Norm Mean Standard deviation
参数功能,输入阵列包含高斯的参数,如下所述:标准平均标准偏差
HarmonicOscillator HarmonicOscillator.Parametric Parametric function where the input array contains the parameters of the harmonic oscillator function, ordered as follows: Amplitude Angular frequency Phase
参数功能,其中输入阵列包含谐振子功能的参数,如下所述:幅度角频率阶段
Identity Identity function.
身份函数。
Inverse Inverse function.
逆功能。
Log Natural logarithm function.
自然对数函数。
Log10 Base 10 logarithm function.
基数10对数函数。
Log1p log(1 + p)
function.
log(1 + p)函数。
Logistic Logistic.Parametric Parametric function where the input array contains the parameters of thelogistic function
, ordered as follows: k m b q a n
参数功能,输入阵列包含逻辑函数的参数,如下所述:k m b q a n
Logit Logit.Parametric Parametric function where the input array contains the parameters of the logit function, ordered as follows: Lower bound Higher bound
参数函数,其中输入阵列包含Logit函数的参数,如下所述:下限更高界限
Max Maximum function.
最大功能。
Min Minimum function.
最小功能。
Minus Minus function.
减去功能。
Multiply Multiply the two operands.
乘以两个操作数。
Pow Power function.
功率函数。
Power Power function.
功率函数。
Rint rint
function.
rint函数。
Sigmoid Sigmoid.Parametric Parametric function where the input array contains the parameters of thesigmoid function
, ordered as follows: Lower asymptote Higher asymptote
参数函数,其中输入阵列包含Sigmoid函数的参数,如下所述:较低的渐近较高的渐近渐近渐近
Signum signum
function.
signum函数。
Sin Sine function.
正弦函数。
Sinc Sinh Hyperbolic sine function.
双曲线正弦功能。
Sqrt Square-root function.
方形功能。
StepFunction Subtract Subtract the second operand from the first.
从第一个减去第二个操作数。
Tan Tangent function.
切线功能。
Tanh Hyperbolic tangent function.
双曲线切线功能。
Ulp ulp
function.
ULP功能。
程序包 org.apache.commons.math3.analysis.function 的说明
The function
package contains function objects that wrap the methods contained in Math
, as well as common mathematical functions such as the gaussian and sinc functions.
函数包包含运算对象,该功能将包含在数学中包含的方法,以及诸如高斯和SINC功能的常见数学函数。
16. 类 org.apache.commons.math3.analysis.function.Divide
16.1. Divide
中英对照文档
类 Divide
- java.lang.Object
-
- org.apache.commons.math3.analysis.function.Divide
-
-
All Implemented Interfaces:
-
BivariateFunction
生物驾驶功能
public class Divide extends Object implements BivariateFunction
Divide the first operand by the second.
将第一个操作数划分为第二个操作数。
-
从以下版本开始:
-
3.0
3.0
-
BivariateFunction
-
-
构造器详细说明
-
Divide
public Divide()
-
-
方法详细说明
-
value
public double value(double x, double y)
Compute the value for the function.
计算函数的值。
-
指定者:
-
value
in interfaceBivariateFunction
界面二手功能中的值
参数:
-
x
- Abscissa for which the function value should be computed.
应计算函数值的X - 横坐标。
-
y
- Ordinate for which the function value should be computed.
Y型纵坐标应计算函数值。
返回:
-
the value.
价值。
-
-
-
16.2. Divide
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.function;
import org.apache.commons.math3.analysis.BivariateFunction;
/**
* Divide the first operand by the second.
*
* @since 3.0
*/
public class Divide implements BivariateFunction {
/** {@inheritDoc} */
public double value(double x, double y) {
return x / y;
}
}
17. 类 org.apache.commons.math3.analysis.function.Exp
17.1. Exp
中英对照文档
类 Exp
- java.lang.Object
-
- org.apache.commons.math3.analysis.function.Exp
-
-
All Implemented Interfaces:
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
CommanileAindeUnivariatefunction,单变化性功能,单轴电功能
public class Exp extends Object implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction
Exponential function.
指数函数。
-
从以下版本开始:
-
3.0
3.0
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
-
-
构造器概要
构造器 构造器和说明 Exp()
-
方法概要
Methods 限定符和类型 方法和说明 UnivariateFunction
derivative()
Deprecated.as of 3.1, replaced byvalue(DerivativeStructure)
截至3.1,取而代之(衍生)
弃用。截至3.1,取而代之(衍生)
DerivativeStructure
value(DerivativeStructure t)
Simple mathematical function.
简单的数学函数。
double
value(double x)
Compute the value of the function.
计算函数的值。
-
-
-
构造器详细说明
-
Exp
public Exp()
-
-
方法详细说明
-
value
public double value(double x)
Compute the value of the function.
计算函数的值。
-
指定者:
-
value
in interfaceUnivariateFunction
界面非凡因子功能中的值
参数:
-
x
- Point at which the function value should be computed.
应计算函数值的X点。
返回:
-
the value of the function.
函数的值。
-
-
derivative
@Deprecated public UnivariateFunction derivative()
Deprecated. as of 3.1, replaced byvalue(DerivativeStructure)
弃用。截至3.1,取而代之(衍生)
Returns the derivative of the function
返回函数的衍生物
-
指定者:
-
derivative
in interfaceDifferentiableUnivariateFunction
界面中的衍生物不同的单位功能
返回:
-
the derivative function
衍生功能
-
-
value
public DerivativeStructure value(DerivativeStructure t)
Simple mathematical function.UnivariateDifferentiableFunction
classes compute both the value and the first derivative of the function.
简单的数学函数。单变化的功能功能计算函数的值和第一个导数。
-
指定者:
-
value
in interfaceUnivariateDifferentiableFunction
界面中的值单识别异导功能
参数:
-
t
- function input value
T - 功能输入值
返回:
-
function result
功能结果
从以下版本开始:
-
3.1
3.1
-
-
-
17.2. Exp
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.function;
import org.apache.commons.math3.analysis.FunctionUtils;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction;
import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction;
import org.apache.commons.math3.util.FastMath;
/**
* Exponential function.
*
* @since 3.0
*/
public class Exp implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction {
/** {@inheritDoc} */
public double value(double x) {
return FastMath.exp(x);
}
/** {@inheritDoc}
* @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)}
*/
@Deprecated
public UnivariateFunction derivative() {
return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative();
}
/** {@inheritDoc}
* @since 3.1
*/
public DerivativeStructure value(final DerivativeStructure t) {
return t.exp();
}
}
18. 类 org.apache.commons.math3.analysis.function.Expm1
18.1. Expm1
中英对照文档
类 Expm1
- java.lang.Object
-
- org.apache.commons.math3.analysis.function.Expm1
-
-
All Implemented Interfaces:
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
CommanileAindeUnivariatefunction,单变化性功能,单轴电功能
public class Expm1 extends Object implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction
ex-1
function.
前1个功能。
-
从以下版本开始:
-
3.0
3.0
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
-
-
构造器概要
构造器 构造器和说明 Expm1()
-
方法概要
Methods 限定符和类型 方法和说明 UnivariateFunction
derivative()
Deprecated.as of 3.1, replaced byvalue(DerivativeStructure)
截至3.1,取而代之(衍生)
弃用。截至3.1,取而代之(衍生)
DerivativeStructure
value(DerivativeStructure t)
Simple mathematical function.
简单的数学函数。
double
value(double x)
Compute the value of the function.
计算函数的值。
-
-
-
构造器详细说明
-
Expm1
public Expm1()
-
-
方法详细说明
-
value
public double value(double x)
Compute the value of the function.
计算函数的值。
-
指定者:
-
value
in interfaceUnivariateFunction
界面非凡因子功能中的值
参数:
-
x
- Point at which the function value should be computed.
应计算函数值的X点。
返回:
-
the value of the function.
函数的值。
-
-
derivative
@Deprecated public UnivariateFunction derivative()
Deprecated. as of 3.1, replaced byvalue(DerivativeStructure)
弃用。截至3.1,取而代之(衍生)
Returns the derivative of the function
返回函数的衍生物
-
指定者:
-
derivative
in interfaceDifferentiableUnivariateFunction
界面中的衍生物不同的单位功能
返回:
-
the derivative function
衍生功能
-
-
value
public DerivativeStructure value(DerivativeStructure t)
Simple mathematical function.UnivariateDifferentiableFunction
classes compute both the value and the first derivative of the function.
简单的数学函数。单变化的功能功能计算函数的值和第一个导数。
-
指定者:
-
value
in interfaceUnivariateDifferentiableFunction
界面中的值单识别异导功能
参数:
-
t
- function input value
T - 功能输入值
返回:
-
function result
功能结果
从以下版本开始:
-
3.1
3.1
-
-
-
18.2. Expm1
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.function;
import org.apache.commons.math3.analysis.FunctionUtils;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction;
import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction;
import org.apache.commons.math3.util.FastMath;
/**
* <code>e<sup>x</sup>-1</code> function.
*
* @since 3.0
*/
public class Expm1 implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction {
/** {@inheritDoc} */
public double value(double x) {
return FastMath.expm1(x);
}
/** {@inheritDoc}
* @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)}
*/
@Deprecated
public UnivariateFunction derivative() {
return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative();
}
/** {@inheritDoc}
* @since 3.1
*/
public DerivativeStructure value(final DerivativeStructure t) {
return t.expm1();
}
}
19. 类 org.apache.commons.math3.analysis.function.Floor
19.1. Floor
中英对照文档
类 Floor
- java.lang.Object
-
- org.apache.commons.math3.analysis.function.Floor
-
-
All Implemented Interfaces:
-
UnivariateFunction
非凡透明
public class Floor extends Object implements UnivariateFunction
floor
function.
地板功能。
-
从以下版本开始:
-
3.0
3.0
-
UnivariateFunction
-
-
构造器详细说明
-
Floor
public Floor()
-
-
方法详细说明
-
value
public double value(double x)
Compute the value of the function.
计算函数的值。
-
指定者:
-
value
in interfaceUnivariateFunction
界面非凡因子功能中的值
参数:
-
x
- Point at which the function value should be computed.
应计算函数值的X点。
返回:
-
the value of the function.
函数的值。
-
-
-
19.2. Floor
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.function;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.util.FastMath;
/**
* {@code floor} function.
*
* @since 3.0
*/
public class Floor implements UnivariateFunction {
/** {@inheritDoc} */
public double value(double x) {
return FastMath.floor(x);
}
}
20. 类 org.apache.commons.math3.analysis.function.Gaussian
20.1. Gaussian
中英对照文档
类 Gaussian
- java.lang.Object
-
- org.apache.commons.math3.analysis.function.Gaussian
-
-
All Implemented Interfaces:
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
CommanileAindeUnivariatefunction,单变化性功能,单轴电功能
public class Gaussian extends Object implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction
-
从以下版本开始:
-
3.0
3.0
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
-
-
Nested Class Summary
Nested Classes 限定符和类型 类 and 的说明 static class
Gaussian.Parametric
Parametric function where the input array contains the parameters of the Gaussian, ordered as follows: Norm Mean Standard deviation
参数功能,输入阵列包含高斯的参数,如下所述:标准平均标准偏差
-
构造器概要
构造器 构造器和说明 Gaussian()
Normalized gaussian with zero mean and unit standard deviation.
标准化高斯具有零平均值和单位标准偏差。
Gaussian(double mean, double sigma)
Normalized gaussian with given mean and standard deviation.
标准化高斯具有含义和标准偏差。
Gaussian(double norm, double mean, double sigma)
Gaussian with given normalization factor, mean and standard deviation.
高斯具有给定归一化因子,平均值和标准偏差。
-
方法概要
Methods 限定符和类型 方法和说明 UnivariateFunction
derivative()
Deprecated.as of 3.1, replaced byvalue(DerivativeStructure)
截至3.1,取而代之(衍生)
弃用。截至3.1,取而代之(衍生)
DerivativeStructure
value(DerivativeStructure t)
Simple mathematical function.
简单的数学函数。
double
value(double x)
Compute the value of the function.
计算函数的值。
-
-
-
构造器详细说明
-
Gaussian
public Gaussian(double norm, double mean, double sigma) throws NotStrictlyPositiveException
Gaussian with given normalization factor, mean and standard deviation.
高斯具有给定归一化因子,平均值和标准偏差。
-
参数:
-
norm
- Normalization factor.
规范 - 归一化因子。
-
mean
- Mean.
意思 - 意思。
-
sigma
- Standard deviation.
Sigma - 标准偏差。
抛出:
-
NotStrictlyPositiveException
- ifsigma <= 0
.
notstrictypositiveexception - 如果sigma <= 0。
-
-
Gaussian
public Gaussian(double mean, double sigma) throws NotStrictlyPositiveException
Normalized gaussian with given mean and standard deviation.
标准化高斯具有含义和标准偏差。
-
参数:
-
mean
- Mean.
意思 - 意思。
-
sigma
- Standard deviation.
Sigma - 标准偏差。
抛出:
-
NotStrictlyPositiveException
- ifsigma <= 0
.
notstrictypositiveexception - 如果sigma <= 0。
-
-
Gaussian
public Gaussian()
Normalized gaussian with zero mean and unit standard deviation.
标准化高斯具有零平均值和单位标准偏差。
-
-
方法详细说明
-
value
public double value(double x)
Compute the value of the function.
计算函数的值。
-
指定者:
-
value
in interfaceUnivariateFunction
界面非凡因子功能中的值
参数:
-
x
- Point at which the function value should be computed.
应计算函数值的X点。
返回:
-
the value of the function.
函数的值。
-
-
derivative
@Deprecated public UnivariateFunction derivative()
Deprecated. as of 3.1, replaced byvalue(DerivativeStructure)
弃用。截至3.1,取而代之(衍生)
Returns the derivative of the function
返回函数的衍生物
-
指定者:
-
derivative
in interfaceDifferentiableUnivariateFunction
界面中的衍生物不同的单位功能
返回:
-
the derivative function
衍生功能
-
-
value
public DerivativeStructure value(DerivativeStructure t) throws DimensionMismatchException
Simple mathematical function.UnivariateDifferentiableFunction
classes compute both the value and the first derivative of the function.
简单的数学函数。单变化的功能功能计算函数的值和第一个导数。
-
指定者:
-
value
in interfaceUnivariateDifferentiableFunction
界面中的值单识别异导功能
参数:
-
t
- function input value
T - 功能输入值
返回:
-
function result
功能结果
抛出:
-
DimensionMismatchException
- if t is inconsistent with the function's free parameters or order
DimensionMismatchException - 如果T与函数的免费参数或订单不一致
从以下版本开始:
-
3.1
3.1
-
-
-
20.2. Gaussian
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.function;
import java.util.Arrays;
import org.apache.commons.math3.analysis.FunctionUtils;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction;
import org.apache.commons.math3.analysis.ParametricUnivariateFunction;
import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction;
import org.apache.commons.math3.exception.NotStrictlyPositiveException;
import org.apache.commons.math3.exception.NullArgumentException;
import org.apache.commons.math3.exception.DimensionMismatchException;
import org.apache.commons.math3.util.FastMath;
import org.apache.commons.math3.util.Precision;
/**
* <a href="http://en.wikipedia.org/wiki/Gaussian_function">
* Gaussian</a> function.
*
* @since 3.0
*/
public class Gaussian implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction {
/** Mean. */
private final double mean;
/** Inverse of the standard deviation. */
private final double is;
/** Inverse of twice the square of the standard deviation. */
private final double i2s2;
/** Normalization factor. */
private final double norm;
/**
* Gaussian with given normalization factor, mean and standard deviation.
*
* @param norm Normalization factor.
* @param mean Mean.
* @param sigma Standard deviation.
* @throws NotStrictlyPositiveException if {@code sigma <= 0}.
*/
public Gaussian(double norm,
double mean,
double sigma)
throws NotStrictlyPositiveException {
if (sigma <= 0) {
throw new NotStrictlyPositiveException(sigma);
}
this.norm = norm;
this.mean = mean;
this.is = 1 / sigma;
this.i2s2 = 0.5 * is * is;
}
/**
* Normalized gaussian with given mean and standard deviation.
*
* @param mean Mean.
* @param sigma Standard deviation.
* @throws NotStrictlyPositiveException if {@code sigma <= 0}.
*/
public Gaussian(double mean,
double sigma)
throws NotStrictlyPositiveException {
this(1 / (sigma * FastMath.sqrt(2 * Math.PI)), mean, sigma);
}
/**
* Normalized gaussian with zero mean and unit standard deviation.
*/
public Gaussian() {
this(0, 1);
}
/** {@inheritDoc} */
public double value(double x) {
return value(x - mean, norm, i2s2);
}
/** {@inheritDoc}
* @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)}
*/
@Deprecated
public UnivariateFunction derivative() {
return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative();
}
/**
* Parametric function where the input array contains the parameters of
* the Gaussian, ordered as follows:
* <ul>
* <li>Norm</li>
* <li>Mean</li>
* <li>Standard deviation</li>
* </ul>
*/
public static class Parametric implements ParametricUnivariateFunction {
/**
* Computes the value of the Gaussian at {@code x}.
*
* @param x Value for which the function must be computed.
* @param param Values of norm, mean and standard deviation.
* @return the value of the function.
* @throws NullArgumentException if {@code param} is {@code null}.
* @throws DimensionMismatchException if the size of {@code param} is
* not 3.
* @throws NotStrictlyPositiveException if {@code param[2]} is negative.
*/
public double value(double x, double ... param)
throws NullArgumentException,
DimensionMismatchException,
NotStrictlyPositiveException {
validateParameters(param);
final double diff = x - param[1];
final double i2s2 = 1 / (2 * param[2] * param[2]);
return Gaussian.value(diff, param[0], i2s2);
}
/**
* Computes the value of the gradient at {@code x}.
* The components of the gradient vector are the partial
* derivatives of the function with respect to each of the
* <em>parameters</em> (norm, mean and standard deviation).
*
* @param x Value at which the gradient must be computed.
* @param param Values of norm, mean and standard deviation.
* @return the gradient vector at {@code x}.
* @throws NullArgumentException if {@code param} is {@code null}.
* @throws DimensionMismatchException if the size of {@code param} is
* not 3.
* @throws NotStrictlyPositiveException if {@code param[2]} is negative.
*/
public double[] gradient(double x, double ... param)
throws NullArgumentException,
DimensionMismatchException,
NotStrictlyPositiveException {
validateParameters(param);
final double norm = param[0];
final double diff = x - param[1];
final double sigma = param[2];
final double i2s2 = 1 / (2 * sigma * sigma);
final double n = Gaussian.value(diff, 1, i2s2);
final double m = norm * n * 2 * i2s2 * diff;
final double s = m * diff / sigma;
return new double[] { n, m, s };
}
/**
* Validates parameters to ensure they are appropriate for the evaluation of
* the {@link #value(double,double[])} and {@link #gradient(double,double[])}
* methods.
*
* @param param Values of norm, mean and standard deviation.
* @throws NullArgumentException if {@code param} is {@code null}.
* @throws DimensionMismatchException if the size of {@code param} is
* not 3.
* @throws NotStrictlyPositiveException if {@code param[2]} is negative.
*/
private void validateParameters(double[] param)
throws NullArgumentException,
DimensionMismatchException,
NotStrictlyPositiveException {
if (param == null) {
throw new NullArgumentException();
}
if (param.length != 3) {
throw new DimensionMismatchException(param.length, 3);
}
if (param[2] <= 0) {
throw new NotStrictlyPositiveException(param[2]);
}
}
}
/**
* @param xMinusMean {@code x - mean}.
* @param norm Normalization factor.
* @param i2s2 Inverse of twice the square of the standard deviation.
* @return the value of the Gaussian at {@code x}.
*/
private static double value(double xMinusMean,
double norm,
double i2s2) {
return norm * FastMath.exp(-xMinusMean * xMinusMean * i2s2);
}
/** {@inheritDoc}
* @since 3.1
*/
public DerivativeStructure value(final DerivativeStructure t)
throws DimensionMismatchException {
final double u = is * (t.getValue() - mean);
double[] f = new double[t.getOrder() + 1];
// the nth order derivative of the Gaussian has the form:
// dn(g(x)/dxn = (norm / s^n) P_n(u) exp(-u^2/2) with u=(x-m)/s
// where P_n(u) is a degree n polynomial with same parity as n
// P_0(u) = 1, P_1(u) = -u, P_2(u) = u^2 - 1, P_3(u) = -u^3 + 3 u...
// the general recurrence relation for P_n is:
// P_n(u) = P_(n-1)'(u) - u P_(n-1)(u)
// as per polynomial parity, we can store coefficients of both P_(n-1) and P_n in the same array
final double[] p = new double[f.length];
p[0] = 1;
final double u2 = u * u;
double coeff = norm * FastMath.exp(-0.5 * u2);
if (coeff <= Precision.SAFE_MIN) {
Arrays.fill(f, 0.0);
} else {
f[0] = coeff;
for (int n = 1; n < f.length; ++n) {
// update and evaluate polynomial P_n(x)
double v = 0;
p[n] = -p[n - 1];
for (int k = n; k >= 0; k -= 2) {
v = v * u2 + p[k];
if (k > 2) {
p[k - 2] = (k - 1) * p[k - 1] - p[k - 3];
} else if (k == 2) {
p[0] = p[1];
}
}
if ((n & 0x1) == 1) {
v *= u;
}
coeff *= is;
f[n] = coeff * v;
}
}
return t.compose(f);
}
}
21. 类 org.apache.commons.math3.analysis.function.HarmonicOscillator
21.1. HarmonicOscillator
中英对照文档
类 HarmonicOscillator
- java.lang.Object
-
- org.apache.commons.math3.analysis.function.HarmonicOscillator
-
-
All Implemented Interfaces:
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
CommanileAindeUnivariatefunction,单变化性功能,单轴电功能
public class HarmonicOscillator extends Object implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction
-
从以下版本开始:
-
3.0
3.0
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
-
-
Nested Class Summary
Nested Classes 限定符和类型 类 and 的说明 static class
HarmonicOscillator.Parametric
Parametric function where the input array contains the parameters of the harmonic oscillator function, ordered as follows: Amplitude Angular frequency Phase
参数功能,其中输入阵列包含谐振子功能的参数,如下所述:幅度角频率阶段
-
构造器概要
构造器 构造器和说明 HarmonicOscillator(double amplitude, double omega, double phase)
Harmonic oscillator function.
谐振子功能。
-
方法概要
Methods 限定符和类型 方法和说明 UnivariateFunction
derivative()
Deprecated.as of 3.1, replaced byvalue(DerivativeStructure)
截至3.1,取而代之(衍生)
弃用。截至3.1,取而代之(衍生)
DerivativeStructure
value(DerivativeStructure t)
Simple mathematical function.
简单的数学函数。
double
value(double x)
Compute the value of the function.
计算函数的值。
-
-
-
构造器详细说明
-
HarmonicOscillator
public HarmonicOscillator(double amplitude, double omega, double phase)
Harmonic oscillator function.
谐振子功能。
-
参数:
-
amplitude
- Amplitude.
幅度幅度。
-
omega
- Angular frequency.
Omega - 角频率。
-
phase
- Phase.
相位阶段。
-
-
-
方法详细说明
-
value
public double value(double x)
Compute the value of the function.
计算函数的值。
-
指定者:
-
value
in interfaceUnivariateFunction
界面非凡因子功能中的值
参数:
-
x
- Point at which the function value should be computed.
应计算函数值的X点。
返回:
-
the value of the function.
函数的值。
-
-
derivative
@Deprecated public UnivariateFunction derivative()
Deprecated. as of 3.1, replaced byvalue(DerivativeStructure)
弃用。截至3.1,取而代之(衍生)
Returns the derivative of the function
返回函数的衍生物
-
指定者:
-
derivative
in interfaceDifferentiableUnivariateFunction
界面中的衍生物不同的单位功能
返回:
-
the derivative function
衍生功能
-
-
value
public DerivativeStructure value(DerivativeStructure t) throws DimensionMismatchException
Simple mathematical function.UnivariateDifferentiableFunction
classes compute both the value and the first derivative of the function.
简单的数学函数。单变化的功能功能计算函数的值和第一个导数。
-
指定者:
-
value
in interfaceUnivariateDifferentiableFunction
界面中的值单识别异导功能
参数:
-
t
- function input value
T - 功能输入值
返回:
-
function result
功能结果
抛出:
-
DimensionMismatchException
- if t is inconsistent with the function's free parameters or order
DimensionMismatchException - 如果T与函数的免费参数或订单不一致
从以下版本开始:
-
3.1
3.1
-
-
-
21.2. HarmonicOscillator
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.function;
import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction;
import org.apache.commons.math3.analysis.FunctionUtils;
import org.apache.commons.math3.analysis.ParametricUnivariateFunction;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction;
import org.apache.commons.math3.exception.DimensionMismatchException;
import org.apache.commons.math3.exception.NullArgumentException;
import org.apache.commons.math3.util.FastMath;
/**
* <a href="http://en.wikipedia.org/wiki/Harmonic_oscillator">
* simple harmonic oscillator</a> function.
*
* @since 3.0
*/
public class HarmonicOscillator implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction {
/** Amplitude. */
private final double amplitude;
/** Angular frequency. */
private final double omega;
/** Phase. */
private final double phase;
/**
* Harmonic oscillator function.
*
* @param amplitude Amplitude.
* @param omega Angular frequency.
* @param phase Phase.
*/
public HarmonicOscillator(double amplitude,
double omega,
double phase) {
this.amplitude = amplitude;
this.omega = omega;
this.phase = phase;
}
/** {@inheritDoc} */
public double value(double x) {
return value(omega * x + phase, amplitude);
}
/** {@inheritDoc}
* @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)}
*/
@Deprecated
public UnivariateFunction derivative() {
return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative();
}
/**
* Parametric function where the input array contains the parameters of
* the harmonic oscillator function, ordered as follows:
* <ul>
* <li>Amplitude</li>
* <li>Angular frequency</li>
* <li>Phase</li>
* </ul>
*/
public static class Parametric implements ParametricUnivariateFunction {
/**
* Computes the value of the harmonic oscillator at {@code x}.
*
* @param x Value for which the function must be computed.
* @param param Values of norm, mean and standard deviation.
* @return the value of the function.
* @throws NullArgumentException if {@code param} is {@code null}.
* @throws DimensionMismatchException if the size of {@code param} is
* not 3.
*/
public double value(double x, double ... param)
throws NullArgumentException,
DimensionMismatchException {
validateParameters(param);
return HarmonicOscillator.value(x * param[1] + param[2], param[0]);
}
/**
* Computes the value of the gradient at {@code x}.
* The components of the gradient vector are the partial
* derivatives of the function with respect to each of the
* <em>parameters</em> (amplitude, angular frequency and phase).
*
* @param x Value at which the gradient must be computed.
* @param param Values of amplitude, angular frequency and phase.
* @return the gradient vector at {@code x}.
* @throws NullArgumentException if {@code param} is {@code null}.
* @throws DimensionMismatchException if the size of {@code param} is
* not 3.
*/
public double[] gradient(double x, double ... param)
throws NullArgumentException,
DimensionMismatchException {
validateParameters(param);
final double amplitude = param[0];
final double omega = param[1];
final double phase = param[2];
final double xTimesOmegaPlusPhase = omega * x + phase;
final double a = HarmonicOscillator.value(xTimesOmegaPlusPhase, 1);
final double p = -amplitude * FastMath.sin(xTimesOmegaPlusPhase);
final double w = p * x;
return new double[] { a, w, p };
}
/**
* Validates parameters to ensure they are appropriate for the evaluation of
* the {@link #value(double,double[])} and {@link #gradient(double,double[])}
* methods.
*
* @param param Values of norm, mean and standard deviation.
* @throws NullArgumentException if {@code param} is {@code null}.
* @throws DimensionMismatchException if the size of {@code param} is
* not 3.
*/
private void validateParameters(double[] param)
throws NullArgumentException,
DimensionMismatchException {
if (param == null) {
throw new NullArgumentException();
}
if (param.length != 3) {
throw new DimensionMismatchException(param.length, 3);
}
}
}
/**
* @param xTimesOmegaPlusPhase {@code omega * x + phase}.
* @param amplitude Amplitude.
* @return the value of the harmonic oscillator function at {@code x}.
*/
private static double value(double xTimesOmegaPlusPhase,
double amplitude) {
return amplitude * FastMath.cos(xTimesOmegaPlusPhase);
}
/** {@inheritDoc}
* @since 3.1
*/
public DerivativeStructure value(final DerivativeStructure t)
throws DimensionMismatchException {
final double x = t.getValue();
double[] f = new double[t.getOrder() + 1];
final double alpha = omega * x + phase;
f[0] = amplitude * FastMath.cos(alpha);
if (f.length > 1) {
f[1] = -amplitude * omega * FastMath.sin(alpha);
final double mo2 = - omega * omega;
for (int i = 2; i < f.length; ++i) {
f[i] = mo2 * f[i - 2];
}
}
return t.compose(f);
}
}
22. 类 org.apache.commons.math3.analysis.function.Identity
22.1. Identity
中英对照文档
类 Identity
- java.lang.Object
-
- org.apache.commons.math3.analysis.function.Identity
-
-
All Implemented Interfaces:
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
CommanileAindeUnivariatefunction,单变化性功能,单轴电功能
public class Identity extends Object implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction
Identity function.
身份函数。
-
从以下版本开始:
-
3.0
3.0
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
-
-
构造器概要
构造器 构造器和说明 Identity()
-
方法概要
Methods 限定符和类型 方法和说明 DifferentiableUnivariateFunction
derivative()
Deprecated.as of 3.1, replaced byvalue(DerivativeStructure)
截至3.1,取而代之(衍生)
弃用。截至3.1,取而代之(衍生)
DerivativeStructure
value(DerivativeStructure t)
Simple mathematical function.
简单的数学函数。
double
value(double x)
Compute the value of the function.
计算函数的值。
-
-
-
构造器详细说明
-
Identity
public Identity()
-
-
方法详细说明
-
value
public double value(double x)
Compute the value of the function.
计算函数的值。
-
指定者:
-
value
in interfaceUnivariateFunction
界面非凡因子功能中的值
参数:
-
x
- Point at which the function value should be computed.
应计算函数值的X点。
返回:
-
the value of the function.
函数的值。
-
-
derivative
@Deprecated public DifferentiableUnivariateFunction derivative()
Deprecated. as of 3.1, replaced byvalue(DerivativeStructure)
弃用。截至3.1,取而代之(衍生)
Returns the derivative of the function
返回函数的衍生物
-
指定者:
-
derivative
in interfaceDifferentiableUnivariateFunction
界面中的衍生物不同的单位功能
返回:
-
the derivative function
衍生功能
-
-
value
public DerivativeStructure value(DerivativeStructure t)
Simple mathematical function.UnivariateDifferentiableFunction
classes compute both the value and the first derivative of the function.
简单的数学函数。单变化的功能功能计算函数的值和第一个导数。
-
指定者:
-
value
in interfaceUnivariateDifferentiableFunction
界面中的值单识别异导功能
参数:
-
t
- function input value
T - 功能输入值
返回:
-
function result
功能结果
从以下版本开始:
-
3.1
3.1
-
-
-
22.2. Identity
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.function;
import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction;
import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction;
/**
* Identity function.
*
* @since 3.0
*/
public class Identity implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction {
/** {@inheritDoc} */
public double value(double x) {
return x;
}
/** {@inheritDoc}
* @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)}
*/
@Deprecated
public DifferentiableUnivariateFunction derivative() {
return new Constant(1);
}
/** {@inheritDoc}
* @since 3.1
*/
public DerivativeStructure value(final DerivativeStructure t) {
return t;
}
}
23. 类 org.apache.commons.math3.analysis.function.Inverse
23.1. Inverse
中英对照文档
类 Inverse
- java.lang.Object
-
- org.apache.commons.math3.analysis.function.Inverse
-
-
All Implemented Interfaces:
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
CommanileAindeUnivariatefunction,单变化性功能,单轴电功能
public class Inverse extends Object implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction
Inverse function.
逆功能。
-
从以下版本开始:
-
3.0
3.0
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
-
-
构造器概要
构造器 构造器和说明 Inverse()
-
方法概要
Methods 限定符和类型 方法和说明 UnivariateFunction
derivative()
Deprecated.as of 3.1, replaced byvalue(DerivativeStructure)
截至3.1,取而代之(衍生)
弃用。截至3.1,取而代之(衍生)
DerivativeStructure
value(DerivativeStructure t)
Simple mathematical function.
简单的数学函数。
double
value(double x)
Compute the value of the function.
计算函数的值。
-
-
-
构造器详细说明
-
Inverse
public Inverse()
-
-
方法详细说明
-
value
public double value(double x)
Compute the value of the function.
计算函数的值。
-
指定者:
-
value
in interfaceUnivariateFunction
界面非凡因子功能中的值
参数:
-
x
- Point at which the function value should be computed.
应计算函数值的X点。
返回:
-
the value of the function.
函数的值。
-
-
derivative
@Deprecated public UnivariateFunction derivative()
Deprecated. as of 3.1, replaced byvalue(DerivativeStructure)
弃用。截至3.1,取而代之(衍生)
Returns the derivative of the function
返回函数的衍生物
-
指定者:
-
derivative
in interfaceDifferentiableUnivariateFunction
界面中的衍生物不同的单位功能
返回:
-
the derivative function
衍生功能
-
-
value
public DerivativeStructure value(DerivativeStructure t)
Simple mathematical function.UnivariateDifferentiableFunction
classes compute both the value and the first derivative of the function.
简单的数学函数。单变化的功能功能计算函数的值和第一个导数。
-
指定者:
-
value
in interfaceUnivariateDifferentiableFunction
界面中的值单识别异导功能
参数:
-
t
- function input value
T - 功能输入值
返回:
-
function result
功能结果
从以下版本开始:
-
3.1
3.1
-
-
-
23.2. Inverse
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.function;
import org.apache.commons.math3.analysis.FunctionUtils;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction;
import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction;
/**
* Inverse function.
*
* @since 3.0
*/
public class Inverse implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction {
/** {@inheritDoc} */
public double value(double x) {
return 1 / x;
}
/** {@inheritDoc}
* @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)}
*/
@Deprecated
public UnivariateFunction derivative() {
return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative();
}
/** {@inheritDoc}
* @since 3.1
*/
public DerivativeStructure value(final DerivativeStructure t) {
return t.reciprocal();
}
}
24. 类 org.apache.commons.math3.analysis.function.Log
24.1. Log
中英对照文档
类 Log
- java.lang.Object
-
- org.apache.commons.math3.analysis.function.Log
-
-
All Implemented Interfaces:
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
CommanileAindeUnivariatefunction,单变化性功能,单轴电功能
public class Log extends Object implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction
Natural logarithm function.
自然对数函数。
-
从以下版本开始:
-
3.0
3.0
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
-
-
构造器概要
构造器 构造器和说明 Log()
-
方法概要
Methods 限定符和类型 方法和说明 UnivariateFunction
derivative()
Deprecated.as of 3.1, replaced byvalue(DerivativeStructure)
截至3.1,取而代之(衍生)
弃用。截至3.1,取而代之(衍生)
DerivativeStructure
value(DerivativeStructure t)
Simple mathematical function.
简单的数学函数。
double
value(double x)
Compute the value of the function.
计算函数的值。
-
-
-
构造器详细说明
-
Log
public Log()
-
-
方法详细说明
-
value
public double value(double x)
Compute the value of the function.
计算函数的值。
-
指定者:
-
value
in interfaceUnivariateFunction
界面非凡因子功能中的值
参数:
-
x
- Point at which the function value should be computed.
应计算函数值的X点。
返回:
-
the value of the function.
函数的值。
-
-
derivative
@Deprecated public UnivariateFunction derivative()
Deprecated. as of 3.1, replaced byvalue(DerivativeStructure)
弃用。截至3.1,取而代之(衍生)
Returns the derivative of the function
返回函数的衍生物
-
指定者:
-
derivative
in interfaceDifferentiableUnivariateFunction
界面中的衍生物不同的单位功能
返回:
-
the derivative function
衍生功能
-
-
value
public DerivativeStructure value(DerivativeStructure t)
Simple mathematical function.UnivariateDifferentiableFunction
classes compute both the value and the first derivative of the function.
简单的数学函数。单变化的功能功能计算函数的值和第一个导数。
-
指定者:
-
value
in interfaceUnivariateDifferentiableFunction
界面中的值单识别异导功能
参数:
-
t
- function input value
T - 功能输入值
返回:
-
function result
功能结果
从以下版本开始:
-
3.1
3.1
-
-
-
24.2. Log
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.function;
import org.apache.commons.math3.analysis.FunctionUtils;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction;
import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction;
import org.apache.commons.math3.util.FastMath;
/**
* Natural logarithm function.
*
* @since 3.0
*/
public class Log implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction {
/** {@inheritDoc} */
public double value(double x) {
return FastMath.log(x);
}
/** {@inheritDoc}
* @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)}
*/
@Deprecated
public UnivariateFunction derivative() {
return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative();
}
/** {@inheritDoc}
* @since 3.1
*/
public DerivativeStructure value(final DerivativeStructure t) {
return t.log();
}
}
25. 类 org.apache.commons.math3.analysis.function.Log1p
25.1. Log1p
中英对照文档
类 Log1p
- java.lang.Object
-
- org.apache.commons.math3.analysis.function.Log1p
-
-
All Implemented Interfaces:
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
CommanileAindeUnivariatefunction,单变化性功能,单轴电功能
public class Log1p extends Object implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction
log(1 + p)
function.
log(1 + p)函数。
-
从以下版本开始:
-
3.0
3.0
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
-
-
构造器概要
构造器 构造器和说明 Log1p()
-
方法概要
Methods 限定符和类型 方法和说明 UnivariateFunction
derivative()
Deprecated.as of 3.1, replaced byvalue(DerivativeStructure)
截至3.1,取而代之(衍生)
弃用。截至3.1,取而代之(衍生)
DerivativeStructure
value(DerivativeStructure t)
Simple mathematical function.
简单的数学函数。
double
value(double x)
Compute the value of the function.
计算函数的值。
-
-
-
构造器详细说明
-
Log1p
public Log1p()
-
-
方法详细说明
-
value
public double value(double x)
Compute the value of the function.
计算函数的值。
-
指定者:
-
value
in interfaceUnivariateFunction
界面非凡因子功能中的值
参数:
-
x
- Point at which the function value should be computed.
应计算函数值的X点。
返回:
-
the value of the function.
函数的值。
-
-
derivative
@Deprecated public UnivariateFunction derivative()
Deprecated. as of 3.1, replaced byvalue(DerivativeStructure)
弃用。截至3.1,取而代之(衍生)
Returns the derivative of the function
返回函数的衍生物
-
指定者:
-
derivative
in interfaceDifferentiableUnivariateFunction
界面中的衍生物不同的单位功能
返回:
-
the derivative function
衍生功能
-
-
value
public DerivativeStructure value(DerivativeStructure t)
Simple mathematical function.UnivariateDifferentiableFunction
classes compute both the value and the first derivative of the function.
简单的数学函数。单变化的功能功能计算函数的值和第一个导数。
-
指定者:
-
value
in interfaceUnivariateDifferentiableFunction
界面中的值单识别异导功能
参数:
-
t
- function input value
T - 功能输入值
返回:
-
function result
功能结果
从以下版本开始:
-
3.1
3.1
-
-
-
25.2. Log1p
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.function;
import org.apache.commons.math3.analysis.FunctionUtils;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction;
import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction;
import org.apache.commons.math3.util.FastMath;
/**
* <code>log(1 + p)</code> function.
*
* @since 3.0
*/
public class Log1p implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction {
/** {@inheritDoc} */
public double value(double x) {
return FastMath.log1p(x);
}
/** {@inheritDoc}
* @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)}
*/
@Deprecated
public UnivariateFunction derivative() {
return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative();
}
/** {@inheritDoc}
* @since 3.1
*/
public DerivativeStructure value(final DerivativeStructure t) {
return t.log1p();
}
}
26. 类 org.apache.commons.math3.analysis.function.Log10
26.1. Log10
中英对照文档
类 Log10
- java.lang.Object
-
- org.apache.commons.math3.analysis.function.Log10
-
-
All Implemented Interfaces:
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
CommanileAindeUnivariatefunction,单变化性功能,单轴电功能
public class Log10 extends Object implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction
Base 10 logarithm function.
基数10对数函数。
-
从以下版本开始:
-
3.0
3.0
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
-
-
构造器概要
构造器 构造器和说明 Log10()
-
方法概要
Methods 限定符和类型 方法和说明 UnivariateFunction
derivative()
Deprecated.as of 3.1, replaced byvalue(DerivativeStructure)
截至3.1,取而代之(衍生)
弃用。截至3.1,取而代之(衍生)
DerivativeStructure
value(DerivativeStructure t)
Simple mathematical function.
简单的数学函数。
double
value(double x)
Compute the value of the function.
计算函数的值。
-
-
-
构造器详细说明
-
Log10
public Log10()
-
-
方法详细说明
-
value
public double value(double x)
Compute the value of the function.
计算函数的值。
-
指定者:
-
value
in interfaceUnivariateFunction
界面非凡因子功能中的值
参数:
-
x
- Point at which the function value should be computed.
应计算函数值的X点。
返回:
-
the value of the function.
函数的值。
-
-
derivative
@Deprecated public UnivariateFunction derivative()
Deprecated. as of 3.1, replaced byvalue(DerivativeStructure)
弃用。截至3.1,取而代之(衍生)
Returns the derivative of the function
返回函数的衍生物
-
指定者:
-
derivative
in interfaceDifferentiableUnivariateFunction
界面中的衍生物不同的单位功能
返回:
-
the derivative function
衍生功能
-
-
value
public DerivativeStructure value(DerivativeStructure t)
Simple mathematical function.UnivariateDifferentiableFunction
classes compute both the value and the first derivative of the function.
简单的数学函数。单变化的功能功能计算函数的值和第一个导数。
-
指定者:
-
value
in interfaceUnivariateDifferentiableFunction
界面中的值单识别异导功能
参数:
-
t
- function input value
T - 功能输入值
返回:
-
function result
功能结果
从以下版本开始:
-
3.1
3.1
-
-
-
26.2. Log10
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.function;
import org.apache.commons.math3.analysis.FunctionUtils;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction;
import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction;
import org.apache.commons.math3.util.FastMath;
/**
* Base 10 logarithm function.
*
* @since 3.0
*/
public class Log10 implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction {
/** {@inheritDoc} */
public double value(double x) {
return FastMath.log10(x);
}
/** {@inheritDoc}
* @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)}
*/
@Deprecated
public UnivariateFunction derivative() {
return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative();
}
/** {@inheritDoc}
* @since 3.1
*/
public DerivativeStructure value(final DerivativeStructure t) {
return t.log10();
}
}
27. 类 org.apache.commons.math3.analysis.function.Logistic
27.1. Logistic
中英对照文档
类 Logistic
- java.lang.Object
-
- org.apache.commons.math3.analysis.function.Logistic
-
-
All Implemented Interfaces:
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
CommanileAindeUnivariatefunction,单变化性功能,单轴电功能
public class Logistic extends Object implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction
-
从以下版本开始:
-
3.0
3.0
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
-
-
Nested Class Summary
Nested Classes 限定符和类型 类 and 的说明 static class
Logistic.Parametric
Parametric function where the input array contains the parameters of thelogistic function
, ordered as follows: k m b q a n
参数功能,输入阵列包含逻辑函数的参数,如下所述:k m b q a n
-
构造器概要
构造器 构造器和说明 Logistic(double k, double m, double b, double q, double a, double n)
-
方法概要
Methods 限定符和类型 方法和说明 UnivariateFunction
derivative()
Deprecated.as of 3.1, replaced byvalue(DerivativeStructure)
截至3.1,取而代之(衍生)
弃用。截至3.1,取而代之(衍生)
DerivativeStructure
value(DerivativeStructure t)
Simple mathematical function.
简单的数学函数。
double
value(double x)
Compute the value of the function.
计算函数的值。
-
-
-
构造器详细说明
-
Logistic
public Logistic(double k, double m, double b, double q, double a, double n) throws NotStrictlyPositiveException
-
参数:
-
k
- Ifb > 0
, value of the function for x going towards +∞. Ifb < 0
, value of the function for x going towards -∞.
k - 如果b> 0,则x函数的值朝向+∞。如果b <0,则X的函数的值朝向-‖。
-
m
- Abscissa of maximum growth.
M - 最大增长的横坐标。
-
b
- Growth rate.
B - 生长速度。
-
q
- Parameter that affects the position of the curve along the ordinate axis.
Q - 影响沿纵轴曲线的位置的参数。
-
a
- Ifb > 0
, value of the function for x going towards -∞. Ifb < 0
, value of the function for x going towards +∞.
a - if b> 0,X的函数的值朝向-‖。如果b <0,则x函数的函数的值朝向+∞。
-
n
- Parameter that affects near which asymptote the maximum growth occurs.
n - 影响渐近增长的附近的参数发生。
抛出:
-
NotStrictlyPositiveException
- ifn <= 0
.
notstrictypositiveexception - 如果n <= 0。
-
-
-
方法详细说明
-
value
public double value(double x)
Compute the value of the function.
计算函数的值。
-
指定者:
-
value
in interfaceUnivariateFunction
界面非凡因子功能中的值
参数:
-
x
- Point at which the function value should be computed.
应计算函数值的X点。
返回:
-
the value of the function.
函数的值。
-
-
derivative
@Deprecated public UnivariateFunction derivative()
Deprecated. as of 3.1, replaced byvalue(DerivativeStructure)
弃用。截至3.1,取而代之(衍生)
Returns the derivative of the function
返回函数的衍生物
-
指定者:
-
derivative
in interfaceDifferentiableUnivariateFunction
界面中的衍生物不同的单位功能
返回:
-
the derivative function
衍生功能
-
-
value
public DerivativeStructure value(DerivativeStructure t)
Simple mathematical function.UnivariateDifferentiableFunction
classes compute both the value and the first derivative of the function.
简单的数学函数。单变化的功能功能计算函数的值和第一个导数。
-
指定者:
-
value
in interfaceUnivariateDifferentiableFunction
界面中的值单识别异导功能
参数:
-
t
- function input value
T - 功能输入值
返回:
-
function result
功能结果
从以下版本开始:
-
3.1
3.1
-
-
-
27.2. Logistic
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.function;
import org.apache.commons.math3.analysis.FunctionUtils;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction;
import org.apache.commons.math3.analysis.ParametricUnivariateFunction;
import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction;
import org.apache.commons.math3.exception.NotStrictlyPositiveException;
import org.apache.commons.math3.exception.NullArgumentException;
import org.apache.commons.math3.exception.DimensionMismatchException;
import org.apache.commons.math3.util.FastMath;
/**
* <a href="http://en.wikipedia.org/wiki/Generalised_logistic_function">
* Generalised logistic</a> function.
*
* @since 3.0
*/
public class Logistic implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction {
/** Lower asymptote. */
private final double a;
/** Upper asymptote. */
private final double k;
/** Growth rate. */
private final double b;
/** Parameter that affects near which asymptote maximum growth occurs. */
private final double oneOverN;
/** Parameter that affects the position of the curve along the ordinate axis. */
private final double q;
/** Abscissa of maximum growth. */
private final double m;
/**
* @param k If {@code b > 0}, value of the function for x going towards +∞.
* If {@code b < 0}, value of the function for x going towards -∞.
* @param m Abscissa of maximum growth.
* @param b Growth rate.
* @param q Parameter that affects the position of the curve along the
* ordinate axis.
* @param a If {@code b > 0}, value of the function for x going towards -∞.
* If {@code b < 0}, value of the function for x going towards +∞.
* @param n Parameter that affects near which asymptote the maximum
* growth occurs.
* @throws NotStrictlyPositiveException if {@code n <= 0}.
*/
public Logistic(double k,
double m,
double b,
double q,
double a,
double n)
throws NotStrictlyPositiveException {
if (n <= 0) {
throw new NotStrictlyPositiveException(n);
}
this.k = k;
this.m = m;
this.b = b;
this.q = q;
this.a = a;
oneOverN = 1 / n;
}
/** {@inheritDoc} */
public double value(double x) {
return value(m - x, k, b, q, a, oneOverN);
}
/** {@inheritDoc}
* @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)}
*/
@Deprecated
public UnivariateFunction derivative() {
return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative();
}
/**
* Parametric function where the input array contains the parameters of
* the {@link Logistic#Logistic(double,double,double,double,double,double)
* logistic function}, ordered as follows:
* <ul>
* <li>k</li>
* <li>m</li>
* <li>b</li>
* <li>q</li>
* <li>a</li>
* <li>n</li>
* </ul>
*/
public static class Parametric implements ParametricUnivariateFunction {
/**
* Computes the value of the sigmoid at {@code x}.
*
* @param x Value for which the function must be computed.
* @param param Values for {@code k}, {@code m}, {@code b}, {@code q},
* {@code a} and {@code n}.
* @return the value of the function.
* @throws NullArgumentException if {@code param} is {@code null}.
* @throws DimensionMismatchException if the size of {@code param} is
* not 6.
* @throws NotStrictlyPositiveException if {@code param[5] <= 0}.
*/
public double value(double x, double ... param)
throws NullArgumentException,
DimensionMismatchException,
NotStrictlyPositiveException {
validateParameters(param);
return Logistic.value(param[1] - x, param[0],
param[2], param[3],
param[4], 1 / param[5]);
}
/**
* Computes the value of the gradient at {@code x}.
* The components of the gradient vector are the partial
* derivatives of the function with respect to each of the
* <em>parameters</em>.
*
* @param x Value at which the gradient must be computed.
* @param param Values for {@code k}, {@code m}, {@code b}, {@code q},
* {@code a} and {@code n}.
* @return the gradient vector at {@code x}.
* @throws NullArgumentException if {@code param} is {@code null}.
* @throws DimensionMismatchException if the size of {@code param} is
* not 6.
* @throws NotStrictlyPositiveException if {@code param[5] <= 0}.
*/
public double[] gradient(double x, double ... param)
throws NullArgumentException,
DimensionMismatchException,
NotStrictlyPositiveException {
validateParameters(param);
final double b = param[2];
final double q = param[3];
final double mMinusX = param[1] - x;
final double oneOverN = 1 / param[5];
final double exp = FastMath.exp(b * mMinusX);
final double qExp = q * exp;
final double qExp1 = qExp + 1;
final double factor1 = (param[0] - param[4]) * oneOverN / FastMath.pow(qExp1, oneOverN);
final double factor2 = -factor1 / qExp1;
// Components of the gradient.
final double gk = Logistic.value(mMinusX, 1, b, q, 0, oneOverN);
final double gm = factor2 * b * qExp;
final double gb = factor2 * mMinusX * qExp;
final double gq = factor2 * exp;
final double ga = Logistic.value(mMinusX, 0, b, q, 1, oneOverN);
final double gn = factor1 * FastMath.log(qExp1) * oneOverN;
return new double[] { gk, gm, gb, gq, ga, gn };
}
/**
* Validates parameters to ensure they are appropriate for the evaluation of
* the {@link #value(double,double[])} and {@link #gradient(double,double[])}
* methods.
*
* @param param Values for {@code k}, {@code m}, {@code b}, {@code q},
* {@code a} and {@code n}.
* @throws NullArgumentException if {@code param} is {@code null}.
* @throws DimensionMismatchException if the size of {@code param} is
* not 6.
* @throws NotStrictlyPositiveException if {@code param[5] <= 0}.
*/
private void validateParameters(double[] param)
throws NullArgumentException,
DimensionMismatchException,
NotStrictlyPositiveException {
if (param == null) {
throw new NullArgumentException();
}
if (param.length != 6) {
throw new DimensionMismatchException(param.length, 6);
}
if (param[5] <= 0) {
throw new NotStrictlyPositiveException(param[5]);
}
}
}
/**
* @param mMinusX {@code m - x}.
* @param k {@code k}.
* @param b {@code b}.
* @param q {@code q}.
* @param a {@code a}.
* @param oneOverN {@code 1 / n}.
* @return the value of the function.
*/
private static double value(double mMinusX,
double k,
double b,
double q,
double a,
double oneOverN) {
return a + (k - a) / FastMath.pow(1 + q * FastMath.exp(b * mMinusX), oneOverN);
}
/** {@inheritDoc}
* @since 3.1
*/
public DerivativeStructure value(final DerivativeStructure t) {
return t.negate().add(m).multiply(b).exp().multiply(q).add(1).pow(oneOverN).reciprocal().multiply(k - a).add(a);
}
}
28. 类 org.apache.commons.math3.analysis.function.Logit
28.1. Logit
中英对照文档
类 Logit
- java.lang.Object
-
- org.apache.commons.math3.analysis.function.Logit
-
-
All Implemented Interfaces:
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
CommanileAindeUnivariatefunction,单变化性功能,单轴电功能
public class Logit extends Object implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction
-
从以下版本开始:
-
3.0
3.0
-
DifferentiableUnivariateFunction,
UnivariateDifferentiableFunction,
UnivariateFunction
-
-
Nested Class Summary
Nested Classes 限定符和类型 类 and 的说明 static class
Logit.Parametric
Parametric function where the input array contains the parameters of the logit function, ordered as follows: Lower bound Higher bound
参数函数,其中输入阵列包含Logit函数的参数,如下所述:下限更高界限
-
构造器概要
构造器 构造器和说明 Logit()
Usual logit function, where the lower bound is 0 and the higher bound is 1.
通常的Logit函数,其中下限为0,更高界限为1。
Logit(double lo, double hi)
Logit function.
Logit函数。
-
方法概要
Methods 限定符和类型 方法和说明 UnivariateFunction
derivative()
Deprecated.as of 3.1, replaced byvalue(DerivativeStructure)
截至3.1,取而代之(衍生)
弃用。截至3.1,取而代之(衍生)
DerivativeStructure
value(DerivativeStructure t)
Simple mathematical function.
简单的数学函数。
double
value(double x)
Compute the value of the function.
计算函数的值。
-
-
-
构造器详细说明
-
Logit
public Logit()
Usual logit function, where the lower bound is 0 and the higher bound is 1.
通常的Logit函数,其中下限为0,更高界限为1。
-
Logit
public Logit(double lo, double hi)
Logit function.
Logit函数。
-
参数:
-
lo
- Lower bound of the function domain.
LO - 函数域的下限。
-
hi
- Higher bound of the function domain.
函数域的高界限。
-
-
-
方法详细说明
-
value
public double value(double x) throws OutOfRangeException
Compute the value of the function.
计算函数的值。
-
指定者:
-
value
in interfaceUnivariateFunction
界面非凡因子功能中的值
参数:
-
x
- Point at which the function value should be computed.
应计算函数值的X点。
返回:
-
the value of the function.
函数的值。
抛出:
-
OutOfRangeException
Outofreanexception.
-
-
derivative
@Deprecated public UnivariateFunction derivative()
Deprecated. as of 3.1, replaced byvalue(DerivativeStructure)
弃用。截至3.1,取而代之(衍生)
Returns the derivative of the function
返回函数的衍生物
-
指定者:
-
derivative
in interfaceDifferentiableUnivariateFunction
界面中的衍生物不同的单位功能
返回:
-
the derivative function
衍生功能
-
-
value
public DerivativeStructure value(DerivativeStructure t) throws OutOfRangeException
Simple mathematical function.UnivariateDifferentiableFunction
classes compute both the value and the first derivative of the function.
简单的数学函数。单变化的功能功能计算函数的值和第一个导数。
-
指定者:
-
value
in interfaceUnivariateDifferentiableFunction
界面中的值单识别异导功能
参数:
-
t
- function input value
T - 功能输入值
返回:
-
function result
功能结果
抛出:
-
OutOfRangeException
- if parameter is outside of function domain
OutofRangeException - 如果参数在功能域之外
从以下版本开始:
-
3.1
3.1
-
-
-
28.2. Logit
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.function;
import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction;
import org.apache.commons.math3.analysis.FunctionUtils;
import org.apache.commons.math3.analysis.ParametricUnivariateFunction;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction;
import org.apache.commons.math3.exception.DimensionMismatchException;
import org.apache.commons.math3.exception.NullArgumentException;
import org.apache.commons.math3.exception.OutOfRangeException;
import org.apache.commons.math3.util.FastMath;
/**
* <a href="http://en.wikipedia.org/wiki/Logit">
* Logit</a> function.
* It is the inverse of the {@link Sigmoid sigmoid} function.
*
* @since 3.0
*/
public class Logit implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction {
/** Lower bound. */
private final double lo;
/** Higher bound. */
private final double hi;
/**
* Usual logit function, where the lower bound is 0 and the higher
* bound is 1.
*/
public Logit() {
this(0, 1);
}
/**
* Logit function.
*
* @param lo Lower bound of the function domain.
* @param hi Higher bound of the function domain.
*/
public Logit(double lo,
double hi) {
this.lo = lo;
this.hi = hi;
}
/** {@inheritDoc} */
public double value(double x)
throws OutOfRangeException {
return value(x, lo, hi);
}
/** {@inheritDoc}
* @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)}
*/
@Deprecated
public UnivariateFunction derivative() {
return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative();
}
/**
* Parametric function where the input array contains the parameters of
* the logit function, ordered as follows:
* <ul>
* <li>Lower bound</li>
* <li>Higher bound</li>
* </ul>
*/
public static class Parametric implements ParametricUnivariateFunction {
/**
* Computes the value of the logit at {@code x}.
*
* @param x Value for which the function must be computed.
* @param param Values of lower bound and higher bounds.
* @return the value of the function.
* @throws NullArgumentException if {@code param} is {@code null}.
* @throws DimensionMismatchException if the size of {@code param} is
* not 2.
*/
public double value(double x, double ... param)
throws NullArgumentException,
DimensionMismatchException {
validateParameters(param);
return Logit.value(x, param[0], param[1]);
}
/**
* Computes the value of the gradient at {@code x}.
* The components of the gradient vector are the partial
* derivatives of the function with respect to each of the
* <em>parameters</em> (lower bound and higher bound).
*
* @param x Value at which the gradient must be computed.
* @param param Values for lower and higher bounds.
* @return the gradient vector at {@code x}.
* @throws NullArgumentException if {@code param} is {@code null}.
* @throws DimensionMismatchException if the size of {@code param} is
* not 2.
*/
public double[] gradient(double x, double ... param)
throws NullArgumentException,
DimensionMismatchException {
validateParameters(param);
final double lo = param[0];
final double hi = param[1];
return new double[] { 1 / (lo - x), 1 / (hi - x) };
}
/**
* Validates parameters to ensure they are appropriate for the evaluation of
* the {@link #value(double,double[])} and {@link #gradient(double,double[])}
* methods.
*
* @param param Values for lower and higher bounds.
* @throws NullArgumentException if {@code param} is {@code null}.
* @throws DimensionMismatchException if the size of {@code param} is
* not 2.
*/
private void validateParameters(double[] param)
throws NullArgumentException,
DimensionMismatchException {
if (param == null) {
throw new NullArgumentException();
}
if (param.length != 2) {
throw new DimensionMismatchException(param.length, 2);
}
}
}
/**
* @param x Value at which to compute the logit.
* @param lo Lower bound.
* @param hi Higher bound.
* @return the value of the logit function at {@code x}.
* @throws OutOfRangeException if {@code x < lo} or {@code x > hi}.
*/
private static double value(double x,
double lo,
double hi)
throws OutOfRangeException {
if (x < lo || x > hi) {
throw new OutOfRangeException(x, lo, hi);
}
return FastMath.log((x - lo) / (hi - x));
}
/** {@inheritDoc}
* @since 3.1
* @exception OutOfRangeException if parameter is outside of function domain
*/
public DerivativeStructure value(final DerivativeStructure t)
throws OutOfRangeException {
final double x = t.getValue();
if (x < lo || x > hi) {
throw new OutOfRangeException(x, lo, hi);
}
double[] f = new double[t.getOrder() + 1];
// function value
f[0] = FastMath.log((x - lo) / (hi - x));
if (Double.isInfinite(f[0])) {
if (f.length > 1) {
f[1] = Double.POSITIVE_INFINITY;
}
// fill the array with infinities
// (for x close to lo the signs will flip between -inf and +inf,
// for x close to hi the signs will always be +inf)
// this is probably overkill, since the call to compose at the end
// of the method will transform most infinities into NaN ...
for (int i = 2; i < f.length; ++i) {
f[i] = f[i - 2];
}
} else {
// function derivatives
final double invL = 1.0 / (x - lo);
double xL = invL;
final double invH = 1.0 / (hi - x);
double xH = invH;
for (int i = 1; i < f.length; ++i) {
f[i] = xL + xH;
xL *= -i * invL;
xH *= i * invH;
}
}
return t.compose(f);
}
}
29. 类 org.apache.commons.math3.analysis.function.Max
29.1. Max
中英对照文档
类 Max
- java.lang.Object
-
- org.apache.commons.math3.analysis.function.Max
-
-
All Implemented Interfaces:
-
BivariateFunction
生物驾驶功能
public class Max extends Object implements BivariateFunction
Maximum function.
最大功能。
-
从以下版本开始:
-
3.0
3.0
-
BivariateFunction
-
-
构造器详细说明
-
Max
public Max()
-
-
方法详细说明
-
value
public double value(double x, double y)
Compute the value for the function.
计算函数的值。
-
指定者:
-
value
in interfaceBivariateFunction
界面二手功能中的值
参数:
-
x
- Abscissa for which the function value should be computed.
应计算函数值的X - 横坐标。
-
y
- Ordinate for which the function value should be computed.
Y型纵坐标应计算函数值。
返回:
-
the value.
价值。
-
-
-
29.2. Max
源码赏析
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math3.analysis.function;
import org.apache.commons.math3.analysis.BivariateFunction;
import org.apache.commons.math3.util.FastMath;
/**
* Maximum function.
*
* @since 3.0
*/
public class Max implements BivariateFunction {
/** {@inheritDoc} */
public double value(double x, double y) {
return FastMath.max(x, y);
}
}