我正在寻找Pythons np.random.choice(Numpy as np)的Java等效代码或基础理论。我正在尝试用 Java 实现 Q-learning。我有一个类似的实现,它使用 Python 的 np.random.choice 方法从概率分布中选择随机移动。
输入列表:['pooh', 'rabbit', 'piglet', 'Christopher'] 和概率:[0.5, 0.1, 0.1, 0.3]
我想从输入列表中选择一个值,给出每个输入元素的相关概率。
最佳答案
使用 Apache Commons 数学库、EnumeratedInteger 发行版的好主意,http://commons.apache.org/proper/commons-math/javadocs/api-3.6/org/apache/commons/math3/distribution/EnumeratedIntegerDistribution.html
沿着线(在一些伪代码中)
values = new String[4]{'pooh', 'rabbit', 'piglet', 'Christopher'};
dist = new EnumeratedIntegerDistribution(new int[4]{0,1,2,3}, new double[4]{0.5, 0.1, 0.1, 0.3});
int idx = dist.sample();
return values[idx];
关于java - Python 的 Numpy np.random.choice 的 Java 等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49344715/