Example #1
0
  std::map<std::string, unsigned int> Reader::parseCounterMetadata() {
    std::map<std::string, unsigned int> counters;
    string content, mimeType, item, counterString;
    unsigned int contentLength, counter;
    string counterUrl = "/M/Counter";

    this->getContentByUrl(counterUrl, content, contentLength, mimeType);
    stringstream ssContent(content);

    while(getline(ssContent, item,  ';')) {
      stringstream ssItem(item);
      getline(ssItem, mimeType, '=');
      getline(ssItem, counterString, '=');
      if (!counterString.empty() && !mimeType.empty()) {
	sscanf(counterString.c_str(), "%u", &counter);
	counters.insert(pair<string, int>(mimeType, counter));
      }
    }

    return counters;
  }
Example #2
0
void HashTable::loadActionValueTable(const string& fileName)
{
    //        fprintf(stream, "Q-Hash Table\n");
        
    
    double maxDiscreteBin = 0.;
    ifstream inFile(fileName.c_str());
    if (!inFile.is_open())
    {
        cerr << "ERROR: Cannot open Q Table file <" << fileName << ">!" << endl;
        exit(1);
    }
    
    _valueTable.clear();
    
    nor_utils::StreamTokenizer lineToken(inFile, "\n\r");
    while (lineToken.has_token())
    {
        string line = lineToken.next_token();
        
        if (line.size() == 0)
            continue;
        
        stringstream ssLine(line);
        nor_utils::StreamTokenizer itemToken(ssLine, " \n\r\t");

        ValueKey key;
        string item = itemToken.next_token();
//        assert(tmp.compare("(") == 0);
        
        int pointer = 0;
        while (itemToken.has_token()) {
            item = itemToken.next_token();

            if (item.size() == 0)
                continue;
            if (item.compare(")") == 0) 
                break;
            
            stringstream ssItem(item);
            double k;
            ssItem >> k;
            key.push_back(k);
            
            // if it points to the bin index and if it's not the max yet
            if (pointer == (_numWinnerClasses + 1) && k > maxDiscreteBin) {
                maxDiscreteBin = k;
            }

            ++pointer;
        }
        
        while (itemToken.has_token())
        {
            item = itemToken.next_token();

            if (item.size() == 0)
                continue;

            stringstream ssItem(item);
            AlphaReal q;
            ssItem >> q;
            _valueTable[key].push_back(q);
        }
        
        assert(_valueTable[key].size() == _numberOfActions);
    }
    
    ++maxDiscreteBin; //starts at 0
    
    if ((1./maxDiscreteBin) != _stepResolution) {
        cout << "[!] Warning: the score resolution used (" << 1/_stepResolution << ") seems to be different in the Q table file (" << (int)maxDiscreteBin << ")." << endl;
    }
}