<commit_before>#pragma once

#include "policy.hpp"

namespace bandit{

//Savage algorithm
class SavagePolicy : public Policy{
  const uint K; //N=K*(K-1)/2 in condorcet (or other dueling) SAVAGE
  const uint T;
  const double delta;
  std::vector<std::vector<uint> > resultMatrix;
  std::set<uint> W; //active bandit arms
public:
  SavagePolicy(uint K, uint T, double delta): K(K), T(T), delta(delta) { //delta = 1/T at $5
    resultMatrix = std::vector<std::vector<uint> >(K, std::vector<uint>(K, 0));
    W.clear();
    for(uint i=0;i<K;++i){
      W.insert(i);
    }
  }
  double getConfidenceBound(uint sampleNum){
    return sqrt(log(K*(K-1)*T/delta)/(2.0*sampleNum));
  }
  std::pair<uint, uint> minimumTrialPair(){
    if(W.size() <= 1){
      std::cout << "Error: winner already defined" << std::endl;
    }
    std::pair<uint, uint> p;
    uint mv = UINT_MAX;
    //minimum
    for(std::set<uint>::iterator it = W.begin(); it != W.end(); it++){
      const uint i = *it;
      for(std::set<uint>::iterator it2 = W.begin(); it2 != W.end(); it2++){
        const uint j = *it2;
        uint n = resultMatrix[i][j] + resultMatrix[j][i];
        if(n<mv){
          mv = n;
          p = std::make_pair(i,j);
        }
      }
    }
    if(mv == UINT_MAX){
      std::cout << "Error: minimum sample not found in Savage::minimumTrialPair" << std::endl;
      exit(0);
    }
    return p;
  }
  virtual std::pair<uint,uint> selectNextPair(uint /*t*/){
    if(W.size()==0){
      std::cout << "Error: no arm left" << std::endl;<commit_msg>fix savage<commit_after>#pragma once

#include "policy.hpp"

namespace bandit{

//Savage algorithm
class SavagePolicy : public Policy{
  const uint K; //N=K*(K-1)/2 in condorcet (or other dueling) SAVAGE
  const uint T;
  const double delta;
  std::vector<std::vector<uint> > resultMatrix;
  std::set<uint> W; //active bandit arms
public:
  SavagePolicy(uint K, uint T, double delta): K(K), T(T), delta(delta) { //delta = 1/T at $5
    resultMatrix = std::vector<std::vector<uint> >(K, std::vector<uint>(K, 0));
    W.clear();
    for(uint i=0;i<K;++i){
      W.insert(i);
    }
  }
  double getConfidenceBound(uint sampleNum){
    return sqrt(log(K*(K-1)*T/delta)/(2.0*sampleNum));
  }
  std::pair<uint, uint> minimumTrialPair(){
    if(W.size() <= 1){
      std::cout << "Error: winner already defined" << std::endl;
    }
    std::pair<uint, uint> p;
    uint mv = UINT_MAX;
    //minimum
    for(std::set<uint>::iterator it = W.begin(); it != W.end(); it++){
      const uint i = *it;
      for(std::set<uint>::iterator it2 = W.begin(); it2 != W.end(); it2++){
        const uint j = *it2;
        if(i==j){
          continue;
        }
        uint n = resultMatrix[i][j] + resultMatrix[j][i];
        if(n<mv){
          mv = n;
          p = std::make_pair(i,j);
        }
      }
    }
    if(mv == UINT_MAX){
      std::cout << "Error: minimum sample not found in Savage::minimumTrialPair" << std::endl;
      exit(0);
    }
    return p;
  }
  virtual std::pair<uint,uint> selectNextPair(uint /*t*/){
    if(W.size()==0){
      std::cout << "Error: no arm left" << std::endl;
{'fraction_non_alphanumeric': 0.1902782219379597, 'fraction_numerical': 0.010233450591621363, 'mean_word_length': 2.895392278953923, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4004887', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1131, 'n_words': 272}