Java 等同于 Python 的 Numpy np.random.choice 是什么?

What is the Java equivalent of Python's Numpy np.random.choice?

我正在寻找 Java 的等效代码或 python 的基础理论 np.random.choice(Numpy 作为 np)。我正在尝试在 Java 中实施 Q-learning。我有一个类似的实现,它使用 Python 的 np.random.choice 方法来 select 从概率分布中随机移动。

Python's code

输入列表:['pooh'、'rabbit'、'piglet'、'Christopher'] 和概率:[0.5、0.1、0.1、0.3]

我想 select 给定每个输入元素的相关概率,输入列表中的值之一。

使用 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];