Example #1
0
  Samu ( const char* name, const char* soul ) : name ( name ), soul ( soul )
  {
#ifndef Q_LOOKUP_TABLE

    std::fstream samuFile ( soul,  std::ios_base::in );
    if ( samuFile )
      load ( samuFile );
#endif

    std::unique_lock<std::mutex> lk ( mutex_ );
    cv_.notify_all();
  }
Example #2
0
  Samu ( const char* name, const char* soul ) : name ( name ), soul ( soul )
  {
#ifndef Q_LOOKUP_TABLE

    std::fstream samuFile ( soul,  std::ios_base::in );
    if ( samuFile )
      load ( samuFile );
#endif

    std::unique_lock<std::mutex> lk ( mutex_ );
    cv_.notify_all();
    
#ifdef AUDIO_RESPONSE
    this->sc.setSynced(false);
#endif
  }
Example #3
0
int main ( int argc, char **argv )
{

#ifndef Q_LOOKUP_TABLE
  std::string samuImage {"samu.soul.txt"};

  std::fstream samuFile ( samuImage,  std::ios_base::in );
  if ( samuFile )
    samu.load ( samuFile );
#endif

  struct sigaction sa;
  sa.sa_handler = save_samu;
  sigemptyset ( &sa.sa_mask );
  sa.sa_flags = SA_RESTART;

  sigaction ( SIGINT, &sa, NULL );
  sigaction ( SIGTERM, &sa, NULL );
  sigaction ( SIGKILL, &sa, NULL );
  sigaction ( SIGHUP, &sa, NULL );

  // Do not remove this copyright notice!
  std::cerr << "This program is Isaac, the son of Samu Bátfai."
            << std::endl
            << "Copyright (C) 2015 Norbert Bátfai"
            << std::endl
            << "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>"
            << std::endl
            << "This is free software: you are free to change and redistribute it."
            << std::endl
            << "There is NO WARRANTY, to the extent permitted by law."
            << std::endl
            << std::endl;


  std::map<std::string, std::vector<std::string>> tests
  {
    {
      "sentences of the paper [1]",
      {
        "A rare black squirrel has become a regular visitor to a suburban garden",
        "This is a car",
        "This car is mine",
        "I have a little car",
        "The sky is blue",
        "The little brown bear has eaten all of the honey",
        "I love Samu"
      }
    },
    {
      "introduce myself",
      {
        "Who are you",
        "I am a robot",
        "What is your name",
        "My name is Judah",
        "Where do you live",
        "I live in Debrecen",
        "How old are you",
        "I am one year old",
        "Where were you born"
        "I was born is Debrecen"
        "What is your favourite colour"
        "My favourite colours are red, white and green"
      }
    }
  };

  std::map<std::string, SPOTriplets> test_triplets
  {
    {
      "introduce myself",
      {
        { "who", "are", "you" },
        { "i", "am", "robot"  },
        {"what",  "is",  "name"},
        {"name", "is", "Judah"},
        {"you", "live", "where"},
        {"I", "live", "Debrecen"},
        {"you", "are", "how"},
        {"i", "am", "one"},
        {"you", "born", "where"},
        {"I", "born", "Debrecen"}
      }
    }
  };

  int j {0};
  int N_e {25};
  std::string training_file = samu.get_training_file();

  samu.set_training_file ( "bbe" );

  double prev_mbrel {0};
  int mbrelc {0};

#ifdef SUPER_OR_REMOTE_COMP
  //for ( int ii {0}; samu.run() && ii < 1000 + 4000 + 5000 + 4000 + 1000; ++ii )
  for ( int ii {0}; samu.run() /*&& ii < 50000*/; ++ii )
#else
  for ( ; samu.run(); )
  //for ( int ii {0}; samu.run() && ii < 50; ++ii )
#endif
    {
      auto start = std::chrono::high_resolution_clock::now();
      double sum {0.0};
      int cnt {0};
      int brel {0};
      if ( samu.sleep() )
        {

#ifdef SUPER_OR_REMOTE_COMP
          /*
                    if ( ii == 1 )
                      {
                        std::cerr << " iter, training file changed " << std::endl;
                        samu.set_training_file ( "bbe" );
                      }
                    else if ( ii == 3 )
                      {
                        std::cerr << " iter, training file changed " << std::endl;
                        training_file = "bbe";
                      }
          */
          /*
                if ( ii == 1000 )
                  {
                    std::cerr << " iter, training file changed " << std::endl;
                    samu.set_training_file ( "bbe" );
                  }
                else if ( ii == 1000 + 4000 )
                  {
                    std::cerr << " iter, training file changed " << std::endl;
                    training_file = "none";
                    samu.set_training_file ( training_file );
                  }
                else if ( ii == 1000 + 4000 + 5000 )
                  {
                    std::cerr << " iter, training file changed " << std::endl;
                    samu.set_training_file ( "bbe" );
                  }
                else if ( ii == 1000 + 4000 + 5000 + 4000 )
                  {
                    std::cerr << " iter, training file changed " << std::endl;
                    training_file = "none";
                    samu.set_training_file ( training_file );
                  }
                  */
#endif

          samu.clear_vi();
          if ( samu.get_training_file() == training_file )
            {
              samu.set_N_e ( N_e );
              for ( int i {0}; i<test_triplets["introduce myself"].size() && samu.sleep(); ++i )
                {
                  SPOTriplets tv;
                  tv.push_back ( test_triplets["introduce myself"][i] );
                  sum += to_samu ( 11, tv );
                  ++cnt;
                  brel += samu.get_brel();
                }
            }
          else
            {
              samu.set_N_e ( N_e );
              std::string key = samu.get_training_file();

              if ( cache.find ( key ) == cache.end() )
                {

                  std::fstream triplet_train ( key+".triplets",  std::ios_base::in );
                  if ( triplet_train )
                    {

                      do
                        {

                          SPOTriplet t;
                          triplet_train >> t;

                          if ( !t.empty() )
                            cache[key].push_back ( t );

                        }
                      while ( !triplet_train.eof() && samu.sleep() );

                      triplet_train.close();

                      sum = read_cache ( key, cnt, brel );

                    }
                  else
                    {

                      std::fstream train ( samu.get_training_file(),  std::ios_base::in );
                      if ( train )
                        {
                          std::string file = key+".triplets";
                          for ( std::string line; std::getline ( train, line ) && samu.sleep(); )
                            {

#ifndef TRIPLET_CACHE
                              sum += to_samu ( 12, line );
#else
                              sum += to_samu ( 12, line, file );
#endif
                              ++cnt;
                              brel += samu.get_brel();

                            }
                          train.close();
                        }

                    }

                }
              else
                {
Example #4
0
int main ( int argc, char **argv )
{

#ifndef Q_LOOKUP_TABLE
  std::string samuImage {"samu.image.txt"};

  std::fstream samuFile ( samuImage,  std::ios_base::in );
  if ( samuFile )
    samu.load ( samuFile );
#endif


  struct sigaction sa;
  sa.sa_handler = save_samu;
  sigemptyset ( &sa.sa_mask );
  sa.sa_flags = SA_RESTART;

  sigaction ( SIGINT, &sa, NULL );
  sigaction ( SIGTERM, &sa, NULL );
  sigaction ( SIGKILL, &sa, NULL );
  sigaction ( SIGHUP, &sa, NULL );

  // Do not remove this copyright notice!
  std::cout << "This program is Isaac, the son of Samu Bátfai."
            << std::endl
            << "Copyright (C) 2015 Norbert Bátfai"
            << std::endl
            << "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>"
            << std::endl
            << "This is free software: you are free to change and redistribute it."
            << std::endl
            << "There is NO WARRANTY, to the extent permitted by law."
            << std::endl
            << std::endl;


  std::cout << "The prenatal development phase has started."
            << std::endl;
  //
  std::cout << "The prenatal development phase has finished."
            << std::endl;


  std::string test[] =
  {
    "A rare black squirrel has become a regular visitor to a suburban garden",
    "This is a car",
    "This car is mine",
    "I have a little car",
    "The sky is blue",
    "The little brown bear has eaten all of the honey",
    "I love Samu"
  };

  int j {0};

  for ( ; samu.run(); )
    {
      double sum {0.0};
      if ( samu.sleep() )
        {
          for ( int i {0}; i<7; ++i )
            {
              samu << test[i];
              sum += samu.reward();

            }
          std::cerr << "###### " << ++j << "-th iter " << sum << std::endl;
        }
    }

  return 0;
}