void AtariFTNeatExperiment::convertIndividual(shared_ptr<GeneticIndividual> FTNEAT_individual,
                                                  NEAT::LayeredSubstrate<float>* HyperNEAT_substrate)
                                                  
    {
        NEAT::FastLayeredNetwork<float>* HyperNEAT_network = HyperNEAT_substrate->getNetwork();

        // [Links] Input --> Processing 
        for (int i=0; i<=numObjClasses; ++i) {
            for (int x=0; x<substrate_width; x++) {
                for (int y=0; y<substrate_height; y++) {
                    Node fromNode(x, y, i);
                    int xmod = substrate_width*i+x; 
                    string sourceString(toString(xmod) + string("/") + toString(y) + string("/") + toString("0"));
                    GeneticNodeGene* sourceNode = FTNEAT_individual->getNode(sourceString);
                    // Processing Layer
                    for (int toY=0; toY<substrate_height; toY++) {
                        for (int toX=0; toX<substrate_width; toX++) {
                            Node toNode(toX, toY, numObjClasses+1);
                            string targetString(toString(toX) + string("/") + toString(toY) +
                                                string("/") + toString("1"));
                            GeneticNodeGene* targetNode = FTNEAT_individual->getNode(targetString);

                            float linkWeight = HyperNEAT_network->getLink(fromNode,toNode);

                            GeneticLinkGene* FTNEAT_link;
                            FTNEAT_link = FTNEAT_individual->getLink(sourceNode->getID(), targetNode->getID());
                            FTNEAT_link->setWeight(double(linkWeight));
                        }
                    }
                }
            }
        }

        // [Links] Processing --> Output
        for (int y=0; y<substrate_height; y++) {
            for (int x=0; x<substrate_width; x++) {
                Node fromNode(x, y, numObjClasses+1);
                string sourceString(toString(x) + string("/") + toString(y) + string("/") + toString("1"));
                GeneticNodeGene* sourceNode = FTNEAT_individual->getNode(sourceString);

                // Output Layer
                for (int i=0; i<numActions; i++) {
                    Node toNode(i, 0, numObjClasses+2);

                    string targetString(toString(i) + string("/") + toString("0") + string("/") + toString("2"));
                    GeneticNodeGene* targetNode = FTNEAT_individual->getNode(targetString);

                    float linkWeight = HyperNEAT_network->getLink(fromNode,toNode);

                    GeneticLinkGene* FTNEAT_link;
                    FTNEAT_link = FTNEAT_individual->getLink(sourceNode->getID(), targetNode->getID());
                    FTNEAT_link->setWeight(double(linkWeight));
                }
            }
        }
    }
Exemplo n.º 2
0
void
CoverFetchArtPayload::prepareUrls()
{
    if( m_src == CoverFetch::Google )
    {
        // google is special
        prepareGoogleUrls();
        return;
    }

    QXmlStreamReader xml( m_xml );
    switch( m_src )
    {
    default:
    case CoverFetch::LastFm:
        prepareLastFmUrls( xml );
        break;
    case CoverFetch::Yahoo:
        prepareYahooUrls( xml );
        break;
    case CoverFetch::Discogs:
        prepareDiscogsUrls( xml );
        break;
    }

    if( xml.hasError() )
    {
        debug() << QString( "Error occured when pareparing %1 urls for %2: %3" )
            .arg( sourceString(), (album() ? album()->name() : "'unknown'"), xml.errorString() );
        debug() << urls();
    }
}
Exemplo n.º 3
0
std::string DebugMessage::toString() const
{
    std::stringstream stream;

    stream
        << typeString()
        << ": " << std::hex << "0x" << m_id << std::dec
        << ", " << severityString() << " severity"
        << " (" << sourceString() << ")"
        << std::endl
        << "\t" << m_message;

    return stream.str();
}
Exemplo n.º 4
0
unsigned ProgramBindingBase::loadShader(GraphicsContext3D* context, unsigned type, const String& shaderSource)
{
    unsigned shader = context->createShader(type);
    if (!shader)
        return 0;
    String sourceString(shaderSource);
    GLC(context, context->shaderSource(shader, sourceString));
    GLC(context, context->compileShader(shader));
#ifndef NDEBUG
    int compiled = 0;
    GLC(context, context->getShaderiv(shader, GraphicsContext3D::COMPILE_STATUS, &compiled));
    if (!compiled) {
        GLC(context, context->deleteShader(shader));
        return 0;
    }
#endif
    return shader;
}
Exemplo n.º 5
0
/// Once source is obtained from either file or hard-coded map, compile the
/// shader, release the string memory and return the ID.
GLuint loadShaderFile(const char* filename, const unsigned long Type)
{
    if (filename == NULL)
        return 0;
    const std::string shaderSource = GetShaderSource(filename);
    std::string sourceString(shaderSource);

    if (sourceString.empty())
        return 0;
    GLint length = static_cast<GLint>(sourceString.length());

    GLuint shaderId = glCreateShader(Type);
    const GLchar* pSrcStr = sourceString.c_str();
    glShaderSource(shaderId, 1, &pSrcStr, &length);
    glCompileShader(shaderId);

    return shaderId;
}
Exemplo n.º 6
0
bool HyperTreeLoader::Load(AllOptions const& opts,
                           const std::vector<FactorType> &input,
                           const std::vector<FactorType> &output,
                           const std::string &inFile,
                           const RuleTableFF &ff,
                           HyperTree &trie,
                           boost::unordered_set<std::size_t> &sourceTermSet)
{
  PrintUserTime(std::string("Start loading HyperTree"));

  sourceTermSet.clear();

  std::size_t count = 0;

  std::ostream *progress = NULL;
  IFVERBOSE(1) progress = &std::cerr;
  util::FilePiece in(inFile.c_str(), progress);

  // reused variables
  std::vector<float> scoreVector;
  StringPiece line;

  double_conversion::StringToDoubleConverter converter(double_conversion::StringToDoubleConverter::NO_FLAGS, NAN, NAN, "inf", "nan");

  HyperPathLoader hyperPathLoader;

  Phrase dummySourcePhrase;
  {
    Word *lhs = NULL;
    dummySourcePhrase.CreateFromString(Input, input, "hello", &lhs);
    delete lhs;
  }

  while(true) {
    try {
      line = in.ReadLine();
    } catch (const util::EndOfFileException &e) {
      break;
    }

    util::TokenIter<util::MultiCharacter> pipes(line, "|||");
    StringPiece sourceString(*pipes);
    StringPiece targetString(*++pipes);
    StringPiece scoreString(*++pipes);

    StringPiece alignString;
    if (++pipes) {
      StringPiece temp(*pipes);
      alignString = temp;
    }

    ++pipes;  // counts

    scoreVector.clear();
    for (util::TokenIter<util::AnyCharacter, true> s(scoreString, " \t"); s; ++s) {
      int processed;
      float score = converter.StringToFloat(s->data(), s->length(), &processed);
      UTIL_THROW_IF2(std::isnan(score), "Bad score " << *s << " on line " << count);
      scoreVector.push_back(FloorScore(TransformScore(score)));
    }
    const std::size_t numScoreComponents = ff.GetNumScoreComponents();
    if (scoreVector.size() != numScoreComponents) {
      UTIL_THROW2("Size of scoreVector != number (" << scoreVector.size() << "!="
                  << numScoreComponents << ") of score components on line " << count);
    }

    // Source-side
    HyperPath sourceFragment;
    hyperPathLoader.Load(sourceString, sourceFragment);
    ExtractSourceTerminalSetFromHyperPath(sourceFragment, sourceTermSet);

    // Target-side
    TargetPhrase *targetPhrase = new TargetPhrase(&ff);
    Word *targetLHS = NULL;
    targetPhrase->CreateFromString(Output, output, targetString, &targetLHS);
    targetPhrase->SetTargetLHS(targetLHS);
    targetPhrase->SetAlignmentInfo(alignString);

    if (++pipes) {
      StringPiece sparseString(*pipes);
      targetPhrase->SetSparseScore(&ff, sparseString);
    }

    if (++pipes) {
      StringPiece propertiesString(*pipes);
      targetPhrase->SetProperties(propertiesString);
    }

    targetPhrase->GetScoreBreakdown().Assign(&ff, scoreVector);
    targetPhrase->EvaluateInIsolation(dummySourcePhrase,
                                      ff.GetFeaturesToApply());

    // Add rule to trie.
    TargetPhraseCollection::shared_ptr phraseColl
    = GetOrCreateTargetPhraseCollection(trie, sourceFragment);
    phraseColl->Add(targetPhrase);

    count++;
  }

  // sort and prune each target phrase collection
  if (ff.GetTableLimit()) {
    SortAndPrune(trie, ff.GetTableLimit());
  }

  return true;
}