Пример #1
0
void Cursor::setMode(Cursor::Mode m) {
  // m_mode = m;
  if (m_mode == m) {
    return;
  }
  m_mode = m;

  switch (m) {
  case Mode::PanningGallery:
    setImage(images[ordinal(Mode::PanningImage)]);
    setAnimate(false);
    break;

  case Mode::PanningImage:
    setImage(images[ordinal(Mode::PanningImage)]);
    break;

  case Mode::Selecting:
    setImage(images[ordinal(Mode::Selecting)]);
    setAnimate(true);
    break;

  case Mode::Selected:
    setImage(images[ordinal(Mode::Selected)]);
    setAnimate(false);
    break;

  case Mode::Normal:
  default:
    setImage(images[ordinal(Mode::Normal)]);
    setAnimate(false);
    break;
  }
}
Пример #2
0
void timeprint(void)
{
  static char * old_month = 0;

  /* WSS * HACK * This shouldn't be here at all but time is so screwed up */
  /* WSS * HACK * I don't know where else I can check for a new month reliably */
  if (!old_month)
    old_month = month();
  else
    {
      /* WSS * HACK * ptr comparision... works cause they're static */
      if (old_month != month() && Player.rank[LEGION] > 0)
        {
          bank_account * account;
          account = bank_index_number(SalaryAccount);
          if (account) account->balance += SalaryAmount;
          old_month = month();
        }
    }

  wclear(Timew);
  wprintw(Timew,"%d:%d",showhour(),showminute());
  if (showminute()==0) waddch(Timew,'0');
  wprintw(Timew,hour()>11 ? " PM \n" : " AM \n");
  wprintw(Timew,month());
  wprintw(Timew," the %d",day());
  wprintw(Timew,ordinal(day()));
  wrefresh(Timew);
}
Пример #3
0
unsigned JniFlags::flags(JNIEnv * env, jobject obj) const {
    DJINNI_ASSERT(obj && env->IsInstanceOf(obj, m_clazz.get()), env);
    auto size = env->CallIntMethod(obj, m_methSize);
    jniExceptionCheck(env);
    unsigned flags = 0;
    auto it = LocalRef<jobject>(env, env->CallObjectMethod(obj, m_methIterator));
    jniExceptionCheck(env);
    for(jint i = 0; i < size; ++i) {
        auto jf = LocalRef<jobject>(env, env->CallObjectMethod(it, m_iterator.methNext));
        jniExceptionCheck(env);
        flags |= (1u << static_cast<unsigned>(ordinal(env, jf)));
    }
    return flags;
}
Пример #4
0
void Generic_ordinal::invert()
{
  std::vector<ftype> hinv( hist.size() );
  hinv[0]             = range_.min();
  hinv[hist.size()-1] = range_.max();
  for ( int i = 1; i < hist.size()-1; i++ ) {
    ftype target = ftype(i)/nranges;
    ftype guess = 0.5 * ( range_.max() + range_.min() );
    ftype step  = 0.5 * ( range_.max() - range_.min() );
    for ( int j = 0; j < 10; j++ ) {
      if ( ordinal( guess ) > target ) guess -= step;
      else                             guess += step;
      step *= 0.5;
    }
    hinv[i] = Util::bound( range_.min(), guess, range_.max() );
  }
  range_ = Range<ftype>( 0.0, 1.0 );
  hist = hinv;
}
int AlternatingListItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    typedef bb::cascades::CustomControl QMocSuperClass;
    _id = QMocSuperClass::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 4)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 4;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QString*>(_v) = colour_code(); break;
        case 1: *reinterpret_cast< QString*>(_v) = description(); break;
        case 2: *reinterpret_cast< QString*>(_v) = itemLabel(); break;
        case 3: *reinterpret_cast< int*>(_v) = ordinal(); break;
        }
        _id -= 4;
    } else if (_c == QMetaObject::WriteProperty) {
        _id -= 4;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 4;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 4;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 4;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 4;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 4;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 4;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Пример #6
0
std::ostream& Ghosting::operator<<(std::ostream& out) const
{
  out << "Ghosting object: name: " << name()
      << ", ordinal: " << ordinal() << "\n";

  out << "  Locally owned entities ghosted on other processors (send list):\n";

  for ( EntityCommListInfoVector::const_iterator
        i =  m_mesh.internal_comm_list().begin() ;
        i != m_mesh.internal_comm_list().end() ; ++i ){
    if ( i->owner == m_mesh.parallel_rank() ) {
      for ( PairIterEntityComm ec = m_mesh.internal_entity_comm_map(i->key) ; ! ec.empty() ; ++ec ) {
        if ( ec->ghost_id == m_ordinal ) {
          out << "    ";
          out << i->key.id();
          out << ", sending ghost to " << ec->proc << ", status is: "
              << m_mesh.state(i->entity) << "\n";
        }
      }
    }
  }

  out << "  Entities ghosted on this processor from the owner (recv list):\n";
  for ( EntityCommListInfoVector::const_iterator
        i =  m_mesh.internal_comm_list().begin() ;
        i != m_mesh.internal_comm_list().end() ; ++i ) {
    if ( i->owner != m_mesh.parallel_rank() ) {
      for ( PairIterEntityComm ec = m_mesh.internal_entity_comm_map(i->key); !ec.empty(); ++ec ) {
        if ( ec->ghost_id == m_ordinal ) {
          out << "    ";
          out << i->key.id();
          out << ", owner of ghost is " << i->owner
              << ", status is: " << m_mesh.state(i->entity) << "\n";
        }
      }
    }
  }
  return out;
}
Пример #7
0
void Cursor::init(int w, int h) {
  m_circleSection = Image::load(resourcePath + "circle_section_white.png");

  Image *handClosed = Image::load(resourcePath + "HandCursorClosed.png");
  Image *handOpened = Image::load(resourcePath + "HandCursorOpened.png");
  Image *exit = Image::load(resourcePath + "exit.png");

  images[ordinal(Mode::Normal)] = handOpened;
  images[ordinal(Mode::PanningGallery)] = handClosed;
  images[ordinal(Mode::PanningImage)] = handClosed;
  images[ordinal(Mode::Selecting)] = handClosed;
  images[ordinal(Mode::Selected)] = handClosed;
  images[ordinal(Mode::Exit)] = exit;

  for (int i = 0; i < images.size(); ++i) {
    images[i]->setSize(w, h);
  }

  setImage(images[ordinal(Mode::Normal)]);
  m_mode = Mode::Normal;

  createRingTexture();
}
Пример #8
0
int main(int argc, char* argv[])
{
	if (argc != 2 && argc != 3)
	{
		cout << "usage rnnlib [-s | --save] config_file" << endl;
		exit(0);
	}
	bool autosave = false;
	string configFilename;
	if (argc == 3)
	{
		string saveFlag(argv[1]);
		autosave = (saveFlag == "-s" || saveFlag == "--save");
		configFilename = argv[2];
	}
	else
	{
		configFilename = argv[1];
	}
	ConfigFile conf(configFilename);
#ifdef FAST_LOGISTIC
	Logistic::fill_lookup();
#endif
	string task = conf.get<string>("task");
	if (task == "transcription" && conf.has("dictionary"))
	{
		task = conf.set<string>("task", "dictionary_transcription");
	}
	bool display = conf.get<bool>("display", false);
	vector<int> jacobianCoords = conf.get_list<int>("jacobianCoords");
	bool gradCheck = conf.get<bool>("gradCheck", false);
	verbose = conf.get<bool>("verbose", false);
	int displaySequence = conf.get<int>("sequence", 0);
	string dataset = conf.get<string>("dataset", "train");
	check(in(validDatasets, dataset), 
		  dataset + " given as 'dataset' parameter in config file '" 
		  + configFilename + "'\nmust be one of '" + str(validDatasets) + "'");
	string dataFileString = dataset + "File";
	string saveName = "";
	ofstream* logout = 0;
	TeeDev* tdev = 0;
	TeeStream* tout = 0;
	string displayPath = "";
	string logname = "";
	if (display || jacobianCoords.size())
	{
		displayPath = conf.get<string>("displayPath");
		logname = displayPath + "log";
	} 
	else if (autosave)
	{
		if (in (conf.filename, '@'))
		{
			saveName = conf.filename.substr(0, conf.filename.find('@'));
		}
		else
		{
			saveName = conf.filename.substr(0, conf.filename.rfind('.'));
		}
		saveName += "@" + time_stamp();
		logname = saveName + ".log";
	}
	if (autosave || display || jacobianCoords.size())
	{
		logout = new ofstream(logname.c_str());
		check(logout->is_open(), "can't open log file " + logname);
		tdev = new TeeDev(cout, *logout);
		tout = new TeeStream(*tdev);
		cout << "writing to log file " << logname << endl;
	}
	ostream& out = tout ? *tout : cout;
	vector<string> dataFiles = conf.get_list<string>(dataFileString);
	int dataFileNum = conf.get<int>("dataFileNum", 0);
	check(dataFiles.size() > dataFileNum, "no " + ordinal(dataFileNum) + " file in size " + str(dataFiles.size()) + " file list " + dataFileString + " in " + configFilename);
	DataHeader header(dataFiles[dataFileNum], task, 1);
	DataSequence* testSeq = 0;
	if (display || gradCheck || jacobianCoords.size())
	{
		NetcdfDataset* data = new NetcdfDataset(dataFiles[dataFileNum], task, displaySequence);
		testSeq = new DataSequence((*data)[0]);
		delete data;
	}
	Mdrnn *net;
	if (task == "code")
	{
		net = new CodeNet(out, conf, header);
	}
	else if (task == "memory")
	{
		net = new MemoryNet(out, conf, header);
	}
	else if (task == "pm")
	{
		net = new PmNet(out, conf, header);
	}
	else
	{
		net = new MultilayerNet(out, conf, header);
	}
	out << endl << "network:" << endl;
	PRINT(task, out);
	out << *net;
	
	//build weight container after net is created
	WeightContainer::instance().build();
	int numWeights = WeightContainer::instance().weights.size();
	out << numWeights << " weights" << endl << endl;
	
	//build the network after the weight container
	net->build();
	
	//only construct optimiser after weight container is built
	Optimiser* opt;
	if (conf.get<string>("optimiser", "steepest") == "rprop")
	{
		opt = new Rprop(out);
	}
	else
	{
		opt = new SteepestDescent(out, conf.get<double>("learnRate", 1e-4), conf.get<double>("momentum", 0.9));
	}
	Trainer trainer(out, net, opt, conf);
	out << "setting random seed to " << Random::set_seed(conf.get<unsigned long int>("randSeed", 0)) << endl << endl;
	if (conf.get<bool>("loadWeights", false))
	{
		out << "loading dynamic data from "  << conf.filename << endl;
		DataExportHandler::instance().load(conf, out);
		out << "epoch = " << trainer.epoch << endl << endl;
	}
	double initWeightRange = conf.get<double>("initWeightRange", 0.1);
	out << "randomising uninitialised weights with mean 0 std. dev. " << initWeightRange << endl << endl;
	WeightContainer::instance().randomise(initWeightRange);	
	out << "optimiser:" << endl << *opt << endl;
	if (gradCheck)
 	{
		out << "data header:" << endl << header << endl;
		out << "running gradient check for sequence " << displaySequence << endl;
		out << *testSeq; 
		prt_line(out);
 		GradientCheck(out, net, *testSeq, conf.get<int>("sigFigs", 6), 
			conf.get<double>("pert", 1e-5), conf.get<bool>("verbose", false));
 	}
	else if (jacobianCoords.size())
	{
		out << "data header:" << endl << header << endl;
		out << "calculating Jacobian for sequence " << displaySequence << " at coords " << jacobianCoords << endl;
		out << *testSeq; 
		out << "output path: " << endl << displayPath << endl;
		net->feed_forward(*testSeq);
		net->print_output_shape(out);
		net->outputLayer->outputErrors.get(jacobianCoords) = net->outputLayer->outputActivations.get(jacobianCoords);
		net->feed_back();
		DataExportHandler::instance().display(displayPath);
	}
	else if (display)
	{
		out << "data header:" << endl << header << endl;
		out << "displaying sequence " << displaySequence << endl;
		out << *testSeq; 
		out << "output path: " << endl << displayPath << endl;
		net->train(*testSeq);
		net->print_output_shape(out);
		out << "errors:" << endl << net->outputLayer->errorMap;
		DataExportHandler::instance().display(displayPath);
	}
	else if (conf.get<bool>("errorTest", false))
	{
		trainer.calculate_all_errors();
	}
	else
	{
		out << "trainer:" << endl;
		trainer.train(saveName);
	}
	if (logout)
	{
		delete logout;
	}
	if (tdev)
	{
		delete tdev;
	}
//	if (tout)
//	{
//		delete tout;
//	}
	delete net;
	delete opt;
}
Пример #9
0
void knowledge(int blessing)
{
  if (blessing < 0)
    mprint("You feel ignorant.");
  else {
    mprint("You feel knowledgeable!");
    menuclear();
    menuprint("Current Point Total: ");
    menulongprint(calc_points());
    menuprint("\nAlignment:");
    if (Player.alignment == 0)
      menuprint("Neutral, embodying the Cosmic Balance");
    else if (abs(Player.alignment) < 10)
      menuprint("Neutral, tending toward ");
    else if (abs(Player.alignment) < 50)
      menuprint("Neutral-");
    else if (abs(Player.alignment) < 100) ;
    else if (abs(Player.alignment) < 200)
      menuprint("Servant of ");
    else if (abs(Player.alignment) < 400)
      menuprint("Master of ");
    else if (abs(Player.alignment) < 800)
      menuprint("The Essence of ");
    else menuprint("The Ultimate Avatar of ");
    if (Player.alignment < 0) menuprint("Chaos\n");
    else if (Player.alignment > 0) menuprint("Law\n");
    showmenu();
    morewait();
    menuclear();
    menuprint("Current stati:\n");
    if (Player.status[BLINDED])
      menuprint("Blinded\n");
    if (Player.status[SLOWED])
      menuprint("Slowed\n");
#ifdef DEBUG
    if (Player.status[SLOWED])
      fprintf(DG_debug_log, "Slowed is %d\n", Player.status[SLOWED] );
#endif
    if (Player.status[HASTED])
      menuprint("Hasted\n");
    if (Player.status[DISPLACED])
      menuprint("Displaced\n");
    if (Player.status[SLEPT])
      menuprint("Slept\n");
    if (Player.status[DISEASED])
      menuprint("Diseased\n");
    if (Player.status[POISONED])
      menuprint("Poisoned\n");
    if (Player.status[BREATHING])
      menuprint("Breathing\n");
    if (Player.status[INVISIBLE])
      menuprint("Invisible\n");
    if (Player.status[REGENERATING])
      menuprint("Regenerating\n");
    if (Player.status[VULNERABLE])
      menuprint("Vulnerable\n");
    if (Player.status[BERSERK])
      menuprint("Berserk\n");
    if (Player.status[IMMOBILE])
      menuprint("Immobile\n");
    if (Player.status[ALERT])
      menuprint("Alert\n");
    if (Player.status[AFRAID])
      menuprint("Afraid\n");
    if (Player.status[ACCURATE])
      menuprint("Accurate\n");
    if (Player.status[HERO])
      menuprint("Heroic\n");
    if (Player.status[LEVITATING])
      menuprint("Levitating\n");
    if (Player.status[TRUESIGHT]) /* FIXED! 12/30/98 DG */
      menuprint("Sharp\n");
    if (Player.status[SHADOWFORM])
      menuprint("Shadowy\n");
    if (Player.status[ILLUMINATION])
      menuprint("Glowing\n");
    if (Player.status[DEFLECTION])
      menuprint("Buffered\n");
    if (Player.status[RETURNING])
      menuprint("Returning\n");
    showmenu();
    morewait();
    menuclear();
    menuprint("Immunities:\n");
    if (p_immune(NORMAL_DAMAGE))
      menuprint("Normal Damage\n");
    if (p_immune(FLAME))
      menuprint("Flame\n");
    if (p_immune(ELECTRICITY))
      menuprint("Electricity\n");
    if (p_immune(COLD))
      menuprint("Cold\n");
    if (p_immune(POISON))
      menuprint("Poison\n");
    if (p_immune(ACID))
      menuprint("Acid\n");
    if (p_immune(FEAR))
      menuprint("Fear\n");
    if (p_immune(SLEEP))
      menuprint("Sleep\n");
    if (p_immune(NEGENERGY))
      menuprint("Negative Energies\n");
    if (p_immune(THEFT))
      menuprint("Theft\n");
    if (p_immune(GAZE))
      menuprint("Gaze\n");
    if (p_immune(INFECTION))
      menuprint("Infection\n");
    showmenu();
    morewait();
    menuclear();
    menuprint("Ranks:\n");
    switch(Player.rank[LEGION]) {
    case COMMANDANT:
      menuprint("Commandant of the Legion"); 
      break;
    case COLONEL:    
      menuprint("Colonel of the Legion");
      break;
    case FORCE_LEADER:
      menuprint("Force Leader of the Legion");
      break;
    case CENTURION:
      menuprint("Centurion of the Legion");
      break;
    case LEGIONAIRE:
      menuprint("Legionaire");
      break;
    }
    if (Player.rank[LEGION] > 0) {
      menuprint(" (");
      menunumprint(Player.guildxp[LEGION]);
      menuprint(" XP).\n");
    }
    switch(Player.rank[ARENA]) {
    case -1:
      menuprint("Ex-gladiator\n");
      break;
    case CHAMPION:
      menuprint("Gladiator Champion");
      break;
    case GLADIATOR:    
      menuprint("Gladiator of the Arena");
      break;
    case RETIARIUS:
      menuprint("Retiarius of the Arena");
      break;
    case BESTIARIUS:
      menuprint("Bestiarius of the Arena");
      break;
    case TRAINEE:
      menuprint("Gladiator Trainee of the Arena");
      break;
    }
    if (Player.rank[ARENA] > 0) {
      menuprint(" (Opponent ");
      menunumprint(Arena_Opponent);
      menuprint(")\n");
    }
    switch(Player.rank[COLLEGE]) {
    case ARCHMAGE:
      menuprint("Archmage of the Collegium Magii");
      break;
    case MAGE:
      menuprint("Collegium Magii: Mage");
      break;
    case PRECEPTOR:
      menuprint("Collegium Magii: Preceptor");
      break;
    case STUDENT:
      menuprint("Collegium Magii: Student");
      break;
    case NOVICE:
      menuprint("Collegium Magii: Novice");
      break;
    }
    if (Player.rank[COLLEGE] > 0) {
      menuprint(" (");
      menunumprint(Player.guildxp[COLLEGE]);
      menuprint(" XP).\n");
    }
    switch(Player.rank[NOBILITY]) {
    case DUKE:
      menuprint("Duke of Rampart");
      break;
    case LORD:
      menuprint("Peer of the Realm");
      break;
    case KNIGHT:
      menuprint("Order of the Knights of Rampart");
      break;
    case ESQUIRE:
      menuprint("Squire of Rampart");
      break;
    case COMMONER:
      menuprint("Commoner");
      break;
    default:
      menuprint("Lowly Commoner\n");
      break;
    }
    if (Player.rank[NOBILITY] > 1) {
      menuprint(" (");
      menunumprint(Player.rank[NOBILITY] - 1);
      menuprint(ordinal(Player.rank[NOBILITY] - 1));
      menuprint(" Quest Completed)\n");
    }
    else if (Player.rank[NOBILITY] == 1) {
      menuprint(" (1st Quest Undertaken)\n");
    }
    switch(Player.rank[CIRCLE]) {
    case -1:
      menuprint("Former member of the Circle.\n");
      break;
    case PRIME:
      menuprint("Prime Sorceror of the Inner Circle");
      break;
    case HIGHSORCEROR:
      menuprint("High Sorceror of the Inner Circle");
      break;
    case SORCEROR:
      menuprint("Member of the Circle of Sorcerors");
      break;
    case ENCHANTER:
      menuprint("Member of the Circle of Enchanters");
      break;
    case INITIATE:
      menuprint("Member of the Circle of Initiates");
      break;
    }
    if (Player.rank[CIRCLE] > 0) {
      menuprint(" (");
      menunumprint(Player.guildxp[CIRCLE]);
      menuprint(" XP).\n");
    }
    switch(Player.rank[ORDER]) {
    case -1:
      menuprint("Washout from the Order of Paladins\n");
      break;
    case JUSTICIAR:
      menuprint("Justiciar of the Order of Paladins");
      break;
    case PALADIN:
      menuprint("Paladin of the Order");
      break;
    case CHEVALIER:
      menuprint("Chevalier of the Order");
      break;
    case GUARDIAN:
      menuprint("Guardian of the Order");
      break;
    case GALLANT:
      menuprint("Gallant of the Order");
      break;
    }
    if (Player.rank[ORDER] > 0) {
      menuprint(" (");
      menunumprint(Player.guildxp[ORDER]);
      menuprint(" XP).\n");
    }
    switch(Player.rank[THIEVES]) {
    case SHADOWLORD:
      menuprint("Guild of Thieves: Shadowlord");
      break;
    case TMASTER:
      menuprint("Guild of Thieves: Master Thief");
      break;
    case THIEF:
      menuprint("Guild of Thieves: Thief");
      break;
    case ATHIEF:
      menuprint("Guild of Thieves: Apprentice Thief");
      break;
    case TMEMBER:
      menuprint("Guild of Thieves: Candidate Member");
      break;
    }
    if (Player.rank[THIEVES] > 0) {
      menuprint(" (");
      menunumprint(Player.guildxp[THIEVES]);
      menuprint(" XP).\n");
    }
    switch(Player.rank[PRIESTHOOD]) {
      case LAY:
        menuprint("A lay devotee of ");
	break;
      case ACOLYTE:
        menuprint("An Acolyte of ");
	break;
      case PRIEST:
        menuprint("A Priest of ");
	break;
      case SPRIEST:
        menuprint("A Senior Priest of ");
	break;
      case HIGHPRIEST:
        menuprint("The High Priest of ");
	break;
      }
    switch(Player.patron) {
      case ODIN:
        menuprint("Odin");
	break;
      case SET:
        menuprint("Set");
	break;
      case ATHENA:
        menuprint("Athena");
	break;
      case HECATE:
        menuprint("Hecate");
	break;
      case DRUID:
        menuprint("Druidism");
	break;
      case DESTINY:
        menuprint("the Lords of Destiny");
	break;
    }
    if (Player.rank[PRIESTHOOD] > 0) {
      menuprint(" (");
      menunumprint(Player.guildxp[PRIESTHOOD]);
      menuprint(" XP).\n");
    }
#ifdef INCLUDE_MONKS
    switch(Player.rank[MONKS]) {
    case MONK_GRANDMASTER:
      menuprint("Tholian Monks: Grandmaster");
      break;
    case MONK_MASTER_TEARS:
      menuprint("Tholian Monks: Master of Tears");
      break;
    case MONK_MASTER_PAINS:
      menuprint("Tholian Monks: Master of Pain");
      break;
    case MONK_MASTER_SIGHS:
      menuprint("Tholian Monks: Master of Sighs");
      break;
    case MONK_MASTER:
      menuprint("Tholian Monks: Master");
      break;
    case MONK_MONK:
      menuprint("Tholian Monks: Monk");
      break;
    case MONK_TRAINEE:
      menuprint("Tholian Monks: Trainee");
      break;
    }
    if (Player.rank[MONKS] > 0) {
      menuprint(" (");
      menunumprint(Player.guildxp[MONKS]);
      menuprint(" XP).\n");
    }
#endif
    if (Player.rank[ADEPT] > 0) 
      menuprint("**************\n*Omegan Adept*\n**************\n");
    showmenu();
    morewait();
    xredraw();
  }
}
Пример #10
0
const char*
Shader::typeString() const
{
  return gl_to_string(gl_target[ordinal(m_type)]);
}
Пример #11
0
int main(int argc, char *argv[]) {
  //    rmsPropTest();
  if (argc < 3) {
    cout << "usage rnnsynth [config_options] config_file" << endl;
    cout << "config_options syntax: --<variable_name>=<variable_value>" << endl;
    cout << "whitespace not allowed in variable names or values" << endl;
    cout << "all config_file variables overwritten by config_options" << endl;
    cout << "setting <variable_value> = \"\" removes the variable from the "
            "config" << endl;
    cout << "repeated variables overwritten by last specified" << endl;
    exit(0);
  }
  ConfigFile conf(argv[argc - 2]);
  ConfigFile conf_1(argv[argc - 1]);
  bool autosave = false;
  string configFilename;
#ifdef FAST_LOGISTIC
  Logistic::fill_lookup();
#endif
  string task = conf.get<string>("task");
  CHECK_STRICT(task == "prediction", "must have prediction task");
  if (task == "prediction" && conf.get<int>("predictionSteps", 1) == 1) {
    task = conf.set_val<string>("task", "window-prediction");
  }
  verbose = true;
  ostream &out = cout;
  string dataset = conf.get<string>("dataset", "train");
  check(in(validDatasets, dataset),
        dataset + " given as 'dataset' parameter in config file '" +
            configFilename + "'\nmust be one of '" + str(validDatasets) + "'");
  string dataFileString = dataset + "File";

  vector<string> dataFiles = conf.get_list<string>(dataFileString);
  int dataFileNum = conf.get<int>("dataFileNum", 0);
  check(dataFiles.size() > dataFileNum,
        "no " + ordinal(dataFileNum) + " file in size " +
            str(dataFiles.size()) + " file list " + dataFileString + " in " +
            configFilename);
  string datafile = dataFiles[dataFileNum];
  DataHeader header(datafile, task, 1);

  PRINT(task, out);

  std::unique_ptr<Mdrnn> net;
  net.reset(new VerticalNet(out, conf, header));

  // build weight container after net is created
  WeightContainer &wc = WeightContainer::instance();
  wc.build();
  Rmsprop optimiser("weight_optimiser", out, wc.weights, wc.derivatives);
  int numWeights = WeightContainer::instance().weights.size();
  out << "loading dynamic data from " << conf.filename << endl;
  out << "number of weights to load " << numWeights << endl;
  DataExportHandler::instance().load(conf, out);
  Vector<real_t> weights = wc.weights;
  Vector<real_t> derivatives = wc.derivatives;
  Vector<real_t> deltas = optimiser.deltas;
  Vector<real_t> n = optimiser.n;
  Vector<real_t> g = optimiser.g;
  out << "loading dynamic data from " << conf_1.filename << endl;
  DataExportHandler::instance().load(conf_1, out);
  addVectors(wc.weights, weights);
  addVectors(wc.derivatives, derivatives);
  addVectors(optimiser.deltas, deltas);
  addVectors(optimiser.n, n);
  addVectors(optimiser.g, g);
  const std::string filename("agg.save");
  ofstream fout(filename.c_str());
  if (fout.is_open()) {
    out << "saving to " << filename << endl;
    fout << DataExportHandler::instance();
  } else {
    out << "WARNING unable to save to file " << filename << endl;
  }

  return 0;
}
Пример #12
0
short dump_ranks( FILE *dumpfile )
{
  char *cp;
	
  /* reset "checksum" */
  dumpcheck = 0;

  if ( !dump( dumpfile, "-- Current Ranks --\n\n", FALSE ) )
    return FALSE;
	
  if ( Player.rank[ LEGION ] > 0 )
    {
      strcpy( dump_buf, legion_rank_string( Player.rank[ LEGION ] ) );
      cp = fill_rank_field( dump_buf );
      sprintf( cp, "Exp: %ld\n", Player.guildxp[ LEGION ] );
      if ( !dump( dumpfile, dump_buf, TRUE ) )
        return FALSE;
    }
	
  if ( Player.rank[ ARENA ] != 0 )
    {
      strcpy( dump_buf, arena_rank_string( Player.rank[ ARENA ] ) );
      if ( Player.rank[ ARENA ] > 0 )
        {
          cp = fill_rank_field( dump_buf );
          sprintf( cp, "%d opponents defeated\n", Arena_Opponent - 3 );
        }
      else
        {
          strcat( dump_buf, "\n" );
        }
      if ( !dump( dumpfile, dump_buf, TRUE ) )
        return FALSE;
    }
	
  if ( Player.rank[ COLLEGE ] > 0 )
    {
      strcpy( dump_buf, college_rank_string( Player.rank[ COLLEGE ] ) );
      cp = fill_rank_field( dump_buf );
      sprintf( cp, "Exp: %ld\n", Player.guildxp[ COLLEGE ] );
      if ( !dump( dumpfile, dump_buf, TRUE ) )
        return FALSE;
    }
	
  strcpy( dump_buf, nobility_rank_string( Player.rank[ NOBILITY ] ) );
  cp = fill_rank_field( dump_buf );
  if ( Player.rank[ NOBILITY ] == 0 )
    {
      *cp++ = '\n';
      *cp = '\0';
    }
  else if ( Player.rank[ NOBILITY ] == 1 )
    {
      sprintf( cp, "1st quest undertaken\n" );
    }
  else if ( Player.rank[ NOBILITY ] > 1 )
    {
      sprintf( cp, "%d%s quest completed\n", Player.rank[ NOBILITY ] - 1,
               ordinal( Player.rank[ NOBILITY ] - 1 ) );
    }
  if ( !dump( dumpfile, dump_buf, TRUE ) )
    return FALSE;
	
  if ( Player.rank[ CIRCLE ] != 0 )
    {
      strcpy( dump_buf, circle_rank_string( Player.rank[ CIRCLE ] ) );
      if ( Player.rank[ CIRCLE ] > 0 )
        {
          cp = fill_rank_field( dump_buf );
          sprintf( cp, "Exp: %ld\n", Player.guildxp[ CIRCLE ] );
        }
      else
        {
          strcat( dump_buf, "\n" );
        }
      if ( !dump( dumpfile, dump_buf, TRUE ) )
        return FALSE;
    }
	
  if ( Player.rank[ ORDER ] != 0 )
    {
      strcpy( dump_buf, order_rank_string( Player.rank[ ORDER ] ) );
      if ( Player.rank[ ORDER ] > 0 )
        {
          cp = fill_rank_field( dump_buf );
          sprintf( cp, "Exp: %ld\n", Player.guildxp[ ORDER ] );
        }
      else
        {
          strcat( dump_buf, "\n" );
        }
      if ( !dump( dumpfile, dump_buf, TRUE ) )
        return FALSE;
    }
	
  if ( Player.rank[ THIEVES ] > 0 )
    {
      strcpy( dump_buf, thieves_rank_string( Player.rank[ THIEVES ] ) );
      cp = fill_rank_field( dump_buf );
      sprintf( cp, "Exp: %ld\n", Player.guildxp[ THIEVES ] );
      if ( !dump( dumpfile, dump_buf, TRUE ) )
        return FALSE;
    }
	
  if ( Player.rank[ PRIESTHOOD ] > 0 )
    {
      strcpy( dump_buf, priesthood_rank_string( Player.rank[ PRIESTHOOD ], Player.patron ) );
      cp = fill_rank_field( dump_buf );
      sprintf( cp, "Exp: %ld\n", Player.guildxp[ PRIESTHOOD ] );
      if ( !dump( dumpfile, dump_buf, TRUE ) )
        return FALSE;
    }
		
  if ( Player.rank[ MONKS ] > 0 )
    {
      strcpy(dump_buf, monk_rank_string(Player.rank[MONKS]));
      cp = fill_rank_field(dump_buf);
      sprintf(cp, "Exp: %ld\n", Player.guildxp[MONKS]);
      if (!dump(dumpfile, dump_buf, TRUE)) return FALSE;
    }
		
  if ( Player.rank[ ADEPT ] > 0 ) 
    {
      if ( !dump( dumpfile, "********** An Adept of Omega **********\n", TRUE ) )
        return FALSE;
    }
		
  sprintf( dump_buf, "\n[Verification: %8.8lx]\n\n", dumpcheck );
  if ( !dump( dumpfile, dump_buf, FALSE ) )
    return FALSE;
			
  return TRUE;
}