本文整理匯總了Java中org.apache.commons.math3.analysis.UnivariateFunction類的典型用法代碼示例。如果您正苦於以下問題:Java UnivariateFunction類的具體用法?Java UnivariateFunction怎麽用?Java UnivariateFunction使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
UnivariateFunction類屬於org.apache.commons.math3.analysis包,在下文中一共展示了UnivariateFunction類的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: calculateSkgEv
import org.apache.commons.math3.analysis.UnivariateFunction; //導入依賴的package包/類
public double calculateSkgEv(final double[] one_over_aqrt_sigma_diff, final double[] mu_m, final double mum_maxOfOthers, final int[] d) {
UnivariateFunction F = new UnivariateFunction() {
@Override
public double value(double x) {
if (x < mum_maxOfOthers) return 0.0;
double res = 1;
for (int j=0;j<mu_m.length;j++) {
if (d[j] > 0) {
res *= normal.cumulativeProbability((x-mu_m[j])*one_over_aqrt_sigma_diff[j]);
}
}
return res;
}
};
//double res1= CalculateEv.calculateEv_old_stepH(F,-15,15,1.0/65536);
double res1 = CalculateEv.calculateEV_KG(F);
return res1;
}
示例3: calculateAkgEv
import org.apache.commons.math3.analysis.UnivariateFunction; //導入依賴的package包/類
public double calculateAkgEv(final double[] sigmas2ki_si_p1, final double[] muk, final double[] muk_maxOfOthers_s, final int s[], final double[] sigmas2ki_si, final int i) {
UnivariateFunction F = new UnivariateFunction() {
@Override
public double value(double x) {
if (x < muk_maxOfOthers_s[i]) return 0.0;
double res = 1;
for (int j=0;j<muk.length;j++) {
if (j==i ) { //considering si+1
res *= normal.cumulativeProbability((x-muk[i])/sqrt(sigmas2ki_si_p1[i]));
} else if (s[j] > 0) { //only in this case sigmas2ki_si exists
res *= normal.cumulativeProbability((x-muk[j])/sqrt(sigmas2ki_si[j]));
}
}
return res;
}
};
//double res1= CalculateEv.calculateEv_old_stepH(F,-15,15,1.0/65536);
double res1 = CalculateEv.calculateEV_KG(F);
return res1;
}
示例4: derivative
import org.apache.commons.math3.analysis.UnivariateFunction; //導入依賴的package包/類
/** {@inheritDoc} */
public UnivariateFunction derivative() {
return new UnivariateFunction() {
/** {@inheritDoc} */
public double value(double x) {
final double diff = x - mean;
final double g = Gaussian.value(diff, norm, i2s2);
if (g == 0) {
// Avoid returning NaN in case of overflow.
return 0;
} else {
return -2 * diff * i2s2 * g;
}
}
};
}
示例5: 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;
}
};
}
示例6: optimize
import org.apache.commons.math3.analysis.UnivariateFunction; //導入依賴的package包/類
/** {@inheritDoc} */
public UnivariatePointValuePair optimize(int maxEval, UnivariateFunction f,
GoalType goalType,
double min, double max,
double startValue) {
// Checks.
if (f == null) {
throw new NullArgumentException();
}
if (goalType == null) {
throw new NullArgumentException();
}
// Reset.
searchMin = min;
searchMax = max;
searchStart = startValue;
goal = goalType;
function = f;
evaluations.setMaximalCount(maxEval);
evaluations.resetCount();
// Perform computation.
return doOptimize();
}
示例7: search
import org.apache.commons.math3.analysis.UnivariateFunction; //導入依賴的package包/類
/**
* Find the minimum of the function {@code f(p + alpha * d)}.
*
* @param p Starting point.
* @param d Search direction.
* @return the optimum.
* @throws org.apache.commons.math3.exception.TooManyEvaluationsException
* if the number of evaluations is exceeded.
*/
public UnivariatePointValuePair search(final double[] p, final double[] d) {
final int n = p.length;
final UnivariateFunction f = new UnivariateFunction() {
/** {@inheritDoc} */
public double value(double alpha) {
final double[] x = new double[n];
for (int i = 0; i < n; i++) {
x[i] = p[i] + alpha * d[i];
}
final double obj = PowellOptimizer.this.computeObjectiveValue(x);
return obj;
}
};
final GoalType goal = PowellOptimizer.this.getGoalType();
bracket.search(f, goal, 0, 1);
// Passing "MAX_VALUE" as a dummy value because it is the enclosing
// class that counts the number of evaluations (and will eventually
// generate the exception).
return optimize(Integer.MAX_VALUE, f, goal,
bracket.getLo(), bracket.getHi(), bracket.getMid());
}
示例8: setup
import org.apache.commons.math3.analysis.UnivariateFunction; //導入依賴的package包/類
/**
* Prepare for computation.
* Subclasses must call this method if they override any of the
* {@code solve} methods.
*
* @param maxEval Maximum number of evaluations.
* @param f the integrand function
* @param lower the min bound for the interval
* @param upper the upper bound for the interval
* @throws NullArgumentException if {@code f} is {@code null}.
* @throws MathIllegalArgumentException if {@code min >= max}.
*/
protected void setup(final int maxEval,
final UnivariateFunction f,
final double lower, final double upper)
throws NullArgumentException, MathIllegalArgumentException {
// Checks.
MathUtils.checkNotNull(f);
UnivariateSolverUtils.verifyInterval(lower, upper);
// Reset.
min = lower;
max = upper;
function = f;
evaluations = evaluations.withMaximalCount(maxEval).withStart(0);
count = count.withStart(0);
}
示例9: 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));
}
}
示例10: 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
}
示例11: getOptimalTime
import org.apache.commons.math3.analysis.UnivariateFunction; //導入依賴的package包/類
Pair<LocalDateTime, Double> getOptimalTime(Path path,
TimeRange<LocalDateTime> timeRange, int starts) {
// the objective function to be passed to the BrentOptimizer
UnivariateFunction univariateFunction = (x) -> {
LocalDateTime time = timeRange.getFrom().plusSeconds((long) x);
Weighting weighting = routingHelper
.createWeighting(this.weightingType, time);
OptionalDouble value = objectiveFunctionPath.value(time, path,
weighting);
if (value.isPresent()) {
return value.getAsDouble();
} else {
return Double.MAX_VALUE;
}
};
// interval used for optimization is 0 and the duration between the
// lower and upper bound in seconds
double lower = 0;
double upper = timeRange.durationInSeconds() + 1;
logger.debug("lower = " + lower + ", upper = " + upper);
BrentOptimizer optimizer = new BrentOptimizer(RELATIVE_THRESHOLD,
ABSOLUTE_THRESHOLD);
MultiStartUnivariateOptimizer multiStartOptimizer = new MultiStartUnivariateOptimizer(
optimizer, starts, rng);
UnivariatePointValuePair res = multiStartOptimizer.optimize(
new MaxEval(MAX_EVAL), GOAL_TYPE,
new SearchInterval(lower, upper),
new UnivariateObjectiveFunction(univariateFunction));
return Pair.of(timeRange.getFrom().plusSeconds((long) res.getPoint()),
res.getValue());
}
示例12: 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;
}
示例13: 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<>();
if (entity.has(attrName)) {
List<Feature> feaList = new ArrayList<>();
double val = entity.get(attrName).asDouble();
UnivariateFunction log10 = new Log10();
FeatureExtractorUtilities.getOrSetIndexSpaceToFeaturize(feaList, update,
indexSpace, indexName, attrName, log10.value(val + 1.0));
feaMap.put(feaName, feaList);
} else {
logger.warn("{} is not present in {}", attrName, entity);
}
return feaMap;
}
示例14: calculateEV_KG
import org.apache.commons.math3.analysis.UnivariateFunction; //導入依賴的package包/類
public static double calculateEV_KG(double xmin, double xmax, final UnivariateFunction F, double base) {
if (Double.isNaN(base)) {
base = int_KG(xmin, xmax, F);
}
double mid = (xmin + xmax) / 2;
double leftint = int_KG(xmin, mid, F);
double rightint = int_KG(mid, xmax, F);
double refined = leftint + rightint;
if (Math.abs(refined - base) < 1e-13) {
return refined;
}
return calculateEV_KG(xmin, mid, F, leftint) + calculateEV_KG(mid, xmax, F, rightint);
}
示例15: 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;
}