Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 |
|
---|
7 | namespace HeuristicLab.Algorithms.Bandits {
|
---|
8 | class BanditHelper {
|
---|
9 | public static void SampleArms(Random random, IBandit bandit, int nSamples, out double expRewardEst, out int bestArmForExpReward, out int bestArmForMaxReward) {
|
---|
10 | bestArmForExpReward = 0;
|
---|
11 | bestArmForMaxReward = 0;
|
---|
12 | expRewardEst = 0.0;
|
---|
13 | var bestSumReward = 0.0;
|
---|
14 | var bestUpperPercCount = 0;
|
---|
15 | for (int a = 0; a < bandit.NumArms; a++) {
|
---|
16 | var sumReward = 0.0;
|
---|
17 | var upperPercCount = 0;
|
---|
18 |
|
---|
19 | for (int i = 0; i < nSamples; i++) {
|
---|
20 | var reward = bandit.Pull(a);
|
---|
21 | sumReward += reward;
|
---|
22 | if (reward >= 0.95) upperPercCount++;
|
---|
23 | }
|
---|
24 |
|
---|
25 | if (sumReward > bestSumReward) {
|
---|
26 | bestSumReward = sumReward;
|
---|
27 | bestArmForExpReward = a;
|
---|
28 | expRewardEst = bestSumReward / nSamples;
|
---|
29 | }
|
---|
30 | if (upperPercCount > bestUpperPercCount) {
|
---|
31 | bestUpperPercCount = upperPercCount;
|
---|
32 | bestArmForMaxReward = a;
|
---|
33 | }
|
---|
34 | }
|
---|
35 | }
|
---|
36 | }
|
---|
37 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.