什么是与Python的Numpy等价的Java随机选择?

2024-06-16 12:42:47 发布

您现在位置:Python中文网/ 问答频道 /正文

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

Python's code

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

我想从输入列表中选择一个给定每个输入元素的相关概率的值。在


Tags: 方法代码numpy列表npcodejava概率
1条回答
网友
1楼 · 发布于 2024-06-16 12:42:47

使用apachecommons数学库的好主意,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];

相关问题 更多 >