【发布时间】:2021-12-12 23:17:56
【问题描述】:
我正在尝试使用commons-math 最小化 Java 中的值。我看过他们的documentation,但我真的不知道如何实现它。
基本上,在我下面的代码中,我有一个Double,其中包含足球比赛中的预期进球,我想将一场比赛中发生少于 3 个进球的概率值优化为 0.5。
import org.apache.commons.math3.distribution.PoissonDistribution;
public class Solver {
public static void main(String[] args) {
final Double expectedGoals = 2.9d;
final PoissonDistribution poissonGoals = new PoissonDistribution(expectedGoals);
Double probabilityUnderThreeGoals = 0d;
for (int score = 0; score < 15; score++) {
final Double probability =
poissonGoals.probability(score);
if (score < 3) {
probabilityUnderThreeGoals = probabilityUnderThreeGoals + probability;
}
}
System.out.println(probabilityUnderThreeGoals); //prints 0.44596319855718064, I want to optimise this to 0.5
}
}
【问题讨论】:
-
expectedGoals = 2.67406怎么样(如果我理解正确的话)?另外,请注意您可以使用cumulativeProbability(2)并且不需要循环。 -
@Sweeper 是的,2.67406 是正确的值——但我想知道当试错不是那么简单时,如何为未来的案例实现优化算法。
标签: java optimization apache-commons solver apache-commons-math