Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Problems.Bandits/BanditHelper.cs @ 13964

Last change on this file since 13964 was 11849, checked in by gkronber, 10 years ago

#2283: solution reorganization

File size: 1.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6
7namespace 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.