本文整理匯總了Java中org.apache.commons.math3.analysis.UnivariateFunction.value方法的典型用法代碼示例。如果您正苦於以下問題:Java UnivariateFunction.value方法的具體用法?Java UnivariateFunction.value怎麽用?Java UnivariateFunction.value使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.math3.analysis.UnivariateFunction
的用法示例。
在下文中一共展示了UnivariateFunction.value方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: extract
import org.apache.commons.math3.analysis.UnivariateFunction; //導入方法依賴的package包/類
public Map<String, List<Feature>> extract(JsonNode entity, boolean update,
IndexSpace indexSpace) {
Map<String, List<Feature>> feaMap = new HashMap<>();
double product = 1.0;
UnivariateFunction sig = new SelfPlusOneRatioFunction();
for (String attrName : attrNames) {
if (entity.has(attrName)) {
double val = entity.get(attrName).asDouble();
if (sigmoid) {
val = sig.value(val);
}
product *= val;
} else {
logger.warn("{} is not present in {}", attrName, entity);
}
}
List<Feature> feaList = new ArrayList<>();
String key = FeatureExtractorUtilities.composeKey(attrNames);
FeatureExtractorUtilities.getOrSetIndexSpaceToFeaturize(feaList, update,
indexSpace, indexName, key, product);
feaMap.put(feaName, feaList);
return feaMap;
}
示例2: function
import org.apache.commons.math3.analysis.UnivariateFunction; //導入方法依賴的package包/類
/**
* Creates an initializer from a univariate function {@code f(x)}.
* The argument {@code x} is set to {@code init} at the first call
* and will be incremented at each call.
*
* @param f Function.
* @param init Initial value.
* @param inc Increment
* @return the initializer.
*/
public static FeatureInitializer function(final UnivariateFunction f,
final double init,
final double inc) {
return new FeatureInitializer() {
/** Argument. */
private double arg = init;
/** {@inheritDoc} */
public double value() {
final double result = f.value(arg);
arg += inc;
return result;
}
};
}
示例3: verifyBracketing
import org.apache.commons.math3.analysis.UnivariateFunction; //導入方法依賴的package包/類
/**
* Check that the endpoints specify an interval and the end points
* bracket a root.
*
* @param function Function.
* @param lower Lower endpoint.
* @param upper Upper endpoint.
* @throws NoBracketingException if the function has the same sign at the
* endpoints.
* @throws NullArgumentException if {@code function} is {@code null}.
*/
public static void verifyBracketing(UnivariateFunction function,
final double lower,
final double upper)
throws NullArgumentException,
NoBracketingException {
if (function == null) {
throw new NullArgumentException(LocalizedFormats.FUNCTION);
}
verifyInterval(lower, upper);
if (!isBracketing(function, lower, upper)) {
throw new NoBracketingException(lower, upper,
function.value(lower),
function.value(upper));
}
}
示例4: getStartPointPhase
import org.apache.commons.math3.analysis.UnivariateFunction; //導入方法依賴的package包/類
/**
* Calculates the 'canonical' start point. This version uses
* (a) a coarse search for a global maximum of fp() and subsequently
* (b) a numerical optimization using Brent's method
* (implemented with Apache Commons Math).
*
* @param Mp number of Fourier coefficient pairs
* @return start point phase
*/
public double getStartPointPhase(int Mp) {
Mp = Math.min(Mp, (G.length-1)/2);
UnivariateFunction fp = new TargetFunction(Mp);
// search for the global maximum in coarse steps
double cmax = Double.NEGATIVE_INFINITY;
int kmax = -1;
int K = 25; // number of steps over 180 degrees
for (int k = 0; k < K; k++) {
final double phi = Math.PI * k / K; // phase to evaluate
final double c = fp.value(phi);
if (c > cmax) {
cmax = c;
kmax = k;
}
}
// optimize using previous and next point as the bracket.
double minPhi = Math.PI * (kmax - 1) / K;
double maxPhi = Math.PI * (kmax + 1) / K;
UnivariateOptimizer optimizer = new BrentOptimizer(1E-4, 1E-6);
int maxIter = 20;
UnivariatePointValuePair result = optimizer.optimize(
new MaxEval(maxIter),
new UnivariateObjectiveFunction(fp),
GoalType.MAXIMIZE,
new SearchInterval(minPhi, maxPhi)
);
double phi0 = result.getPoint();
return phi0; // the canonical start point phase
}
示例5: extract
import org.apache.commons.math3.analysis.UnivariateFunction; //導入方法依賴的package包/類
public Map<String, List<Feature>> extract(JsonNode entity, boolean update,
IndexSpace indexSpace) {
Map<String, List<Feature>> feaMap = new HashMap<>();
List<Feature> feaList = new ArrayList<>();
for (String attrName : attrNames) {
if (!entity.has(attrName)) {
logger.warn("{} is not present in {}", attrName, entity);
}
}
for (String leftName : attrNames) {
for (String rightName : attrNames) {
List<String> keyNames = Lists.newArrayList(leftName, rightName);
String key = FeatureExtractorUtilities.composeKey(keyNames);
double product;
if (sigmoid) {
UnivariateFunction func = new SelfPlusOneRatioFunction();
product = func.value(entity.get(leftName).asDouble()) *
func.value(entity.get(rightName).asDouble());
} else {
product = entity.get(leftName).asDouble() * entity.get(rightName).asDouble();
}
FeatureExtractorUtilities.getOrSetIndexSpaceToFeaturize(feaList, update,
indexSpace, indexName, key, product);
feaMap.put(feaName, feaList);
}
}
return feaMap;
}
示例6: int_KG
import org.apache.commons.math3.analysis.UnivariateFunction; //導入方法依賴的package包/類
private static double int_KG(double xmin, double xmax,final UnivariateFunction F) {
double quad = 0;
double range = (xmax - xmin) / 2;
double mean = (xmax + xmin) / 2;
for (int i = 0; i < 61; i++) {
double x = gkx[i] * range + mean;
quad += range * gkw[i]
* (1 - F.value((1 - x) / x) - F.value(-(1 - x) / x))
/ (x * x);
}
return quad;
}
示例7: estimate
import org.apache.commons.math3.analysis.UnivariateFunction; //導入方法依賴的package包/類
/**
* Estimate the quantile for the current marker.
*
* @return estimated quantile
*/
private double estimate() {
final double di = difference();
final boolean isNextHigher =
next.intMarkerPosition - intMarkerPosition > 1;
final boolean isPreviousLower =
previous.intMarkerPosition - intMarkerPosition < -1;
if (di >= 1 && isNextHigher || di <= -1 && isPreviousLower) {
final int d = di >= 0 ? 1 : -1;
final double[] xval =
new double[] { previous.intMarkerPosition,
intMarkerPosition, next.intMarkerPosition };
final double[] yval =
new double[] { previous.markerHeight, markerHeight,
next.markerHeight };
final double xD = intMarkerPosition + d;
UnivariateFunction univariateFunction =
nonLinear.interpolate(xval, yval);
markerHeight = univariateFunction.value(xD);
// If parabolic estimate is bad then turn linear
if (isEstimateBad(yval, markerHeight)) {
int delta = xD - xval[1] > 0 ? 1 : -1;
final double[] xBad =
new double[] { xval[1], xval[1 + delta] };
final double[] yBad =
new double[] { yval[1], yval[1 + delta] };
MathArrays.sortInPlace(xBad, yBad);// since d can be +/- 1
univariateFunction = linear.interpolate(xBad, yBad);
markerHeight = univariateFunction.value(xD);
}
incrementPosition(d);
}
return markerHeight;
}
示例8: findUpperBound
import org.apache.commons.math3.analysis.UnivariateFunction; //導入方法依賴的package包/類
/**
* Find the upper bound b ensuring bracketing of a root between a and b.
*
* @param f function whose root must be bracketed.
* @param a lower bound of the interval.
* @param h initial step to try.
* @return b such that f(a) and f(b) have opposite signs.
* @throws MathIllegalStateException if no bracket can be found.
*/
private double findUpperBound(final UnivariateFunction f,
final double a, final double h) {
final double yA = f.value(a);
double yB = yA;
for (double step = h; step < Double.MAX_VALUE; step *= FastMath.max(2, yA / yB)) {
final double b = a + step;
yB = f.value(b);
if (yA * yB <= 0) {
return b;
}
}
throw new MathIllegalStateException(LocalizedFormats.UNABLE_TO_BRACKET_OPTIMUM_IN_LINE_SEARCH);
}
示例9: eval
import org.apache.commons.math3.analysis.UnivariateFunction; //導入方法依賴的package包/類
/**
* @param f Function.
* @param x Argument.
* @return {@code f(x)}
* @throws TooManyEvaluationsException if the maximal number of evaluations is
* exceeded.
*/
private double eval(UnivariateFunction f, double x) {
try {
evaluations.incrementCount();
} catch (MaxCountExceededException e) {
throw new TooManyEvaluationsException(e.getMax());
}
return f.value(x);
}
示例10: integrate
import org.apache.commons.math3.analysis.UnivariateFunction; //導入方法依賴的package包/類
/**
* Returns an estimate of the integral of {@code f(x) * w(x)},
* where {@code w} is a weight function that depends on the actual
* flavor of the Gauss integration scheme.
* The algorithm uses the points and associated weights, as passed
* to the {@link #GaussIntegrator(double[],double[]) constructor}.
*
* @param f Function to integrate.
* @return the integral of the weighted function.
*/
public double integrate(UnivariateFunction f) {
double s = 0;
double c = 0;
for (int i = 0; i < points.length; i++) {
final double x = points[i];
final double w = weights[i];
final double y = w * f.value(x) - c;
final double t = s + y;
c = (t - s) - y;
s = t;
}
return s;
}
示例11: differentiate
import org.apache.commons.math3.analysis.UnivariateFunction; //導入方法依賴的package包/類
/** {@inheritDoc}
* <p>The returned object cannot compute derivatives to arbitrary orders. The
* value function will throw a {@link NumberIsTooLargeException} if the requested
* derivation order is larger or equal to the number of points.
* </p>
*/
public UnivariateDifferentiableFunction differentiate(final UnivariateFunction function) {
return new UnivariateDifferentiableFunction() {
/** {@inheritDoc} */
public double value(final double x) throws MathIllegalArgumentException {
return function.value(x);
}
/** {@inheritDoc} */
public DerivativeStructure value(final DerivativeStructure t)
throws MathIllegalArgumentException {
// check we can achieve the requested derivation order with the sample
if (t.getOrder() >= nbPoints) {
throw new NumberIsTooLargeException(t.getOrder(), nbPoints, false);
}
// compute sample position, trying to be centered if possible
final double t0 = FastMath.max(FastMath.min(t.getValue(), tMax), tMin) - halfSampleSpan;
// compute sample points
final double[] y = new double[nbPoints];
for (int i = 0; i < nbPoints; ++i) {
y[i] = function.value(t0 + i * stepSize);
}
// evaluate derivatives
return evaluate(t, t0, y);
}
};
}
示例12: eval
import org.apache.commons.math3.analysis.UnivariateFunction; //導入方法依賴的package包/類
/**
* @param f Function.
* @param x Argument.
* @return {@code f(x)}
* @throws TooManyEvaluationsException if the maximal number of evaluations is
* exceeded.
*/
private double eval(UnivariateFunction f, double x) {
try {
evaluations.increment();
} catch (MaxCountExceededException e) {
throw new TooManyEvaluationsException(e.getMax());
}
return f.value(x);
}
示例13: mapToSelf
import org.apache.commons.math3.analysis.UnivariateFunction; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Override
public ArrayRealVector mapToSelf(UnivariateFunction function) {
for (int i = 0; i < data.length; i++) {
data[i] = function.value(data[i]);
}
return this;
}
示例14: isBracketing
import org.apache.commons.math3.analysis.UnivariateFunction; //導入方法依賴的package包/類
/**
* Check whether the interval bounds bracket a root. That is, if the
* values at the endpoints are not equal to zero, then the function takes
* opposite signs at the endpoints.
*
* @param function Function.
* @param lower Lower endpoint.
* @param upper Upper endpoint.
* @return {@code true} if the function values have opposite signs at the
* given points.
* @throws NullArgumentException if {@code function} is {@code null}.
*/
public static boolean isBracketing(UnivariateFunction function,
final double lower,
final double upper)
throws NullArgumentException {
if (function == null) {
throw new NullArgumentException(LocalizedFormats.FUNCTION);
}
final double fLo = function.value(lower);
final double fHi = function.value(upper);
return (fLo >= 0 && fHi <= 0) || (fLo <= 0 && fHi >= 0);
}
示例15: mapToSelf
import org.apache.commons.math3.analysis.UnivariateFunction; //導入方法依賴的package包/類
/**
* Acts as if it is implemented as:
* <pre>
* Entry e = null;
* for(Iterator<Entry> it = iterator(); it.hasNext(); e = it.next()) {
* e.setValue(function.value(e.getValue()));
* }
* </pre>
* Entries of this vector are modified in-place by this method.
*
* @param function Function to apply to each entry.
* @return a reference to this vector.
*/
public RealVector mapToSelf(UnivariateFunction function) {
Iterator<Entry> it = (function.value(0) == 0) ? sparseIterator() : iterator();
Entry e;
while (it.hasNext() && (e = it.next()) != null) {
e.setValue(function.value(e.getValue()));
}
return this;
}