本文整理汇总了Java中org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunctionGradient类的典型用法代码示例。如果您正苦于以下问题:Java ObjectiveFunctionGradient类的具体用法?Java ObjectiveFunctionGradient怎么用?Java ObjectiveFunctionGradient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObjectiveFunctionGradient类属于org.apache.commons.math3.optim.nonlinear.scalar包,在下文中一共展示了ObjectiveFunctionGradient类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getObjectiveFunctionGradient
import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunctionGradient; //导入依赖的package包/类
public ObjectiveFunctionGradient getObjectiveFunctionGradient() {
return new ObjectiveFunctionGradient(new MultivariateVectorFunction() {
public double[] value(double[] params) {
Vector2D center = new Vector2D(params[0], params[1]);
double radius = getRadius(center);
// gradient of the sum of squared residuals
double dJdX = 0;
double dJdY = 0;
for (Vector2D pk : points) {
double dk = pk.distance(center);
dJdX += (center.getX() - pk.getX()) * (dk - radius) / dk;
dJdY += (center.getY() - pk.getY()) * (dk - radius) / dk;
}
dJdX *= 2;
dJdY *= 2;
return new double[] { dJdX, dJdY };
}
});
}
示例2: getObjectiveFunctionGradient
import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunctionGradient; //导入依赖的package包/类
public ObjectiveFunctionGradient getObjectiveFunctionGradient() {
return new ObjectiveFunctionGradient(new MultivariateVectorFunction() {
public double[] value(double[] point) {
double[] r = factors.operate(point);
for (int i = 0; i < r.length; ++i) {
r[i] -= target[i];
}
double[] p = factors.transpose().operate(r);
for (int i = 0; i < p.length; ++i) {
p[i] *= 2;
}
return p;
}
});
}