Пример #1
0
//Constructor
Organism::Organism()
{
	//Keep track of id numbers
	static unsigned long int next_id = 0;
	id = next_id;
	++next_id;

	//First and Last name lengths
	int fNameLen = GetDistribution(std::uniform_int_distribution<int>(3, 8));
	int lNameLen = GetDistribution(std::uniform_int_distribution<int>(4, 12));

	//Generate name
	for (int i = 0; i < fNameLen; ++i) {
		fName += static_cast<char>(GetDistribution( std::uniform_int_distribution<int>(65, 90) ));
	}

	for (int i = 0; i < lNameLen; ++i) {
		lName += static_cast<char>(GetDistribution( std::uniform_int_distribution<int>(65, 90) ));
	}

	//Organism is not asleep at creation
	asleep = false;
	asleepSince = -1.0;

	//Organisms begin with energy normally distributed around 50% of their maximum
	energy = std::max(unsigned int(GetDistribution(std::normal_distribution<float>(maxEnergy() / 2, maxEnergy() / 10))), maxEnergy());

	//In case above energy distribution does not work out
	//energy = GetDistribution(std::uniform_int_distribution<int>(0, maxEnergy() ));

	age = 0.0;
}
Пример #2
0
void run_lda()
{
	cout << "Start LDA Module..." << endl;
	ReadDocument();
	cout<<"Reading Document Done."<<endl;
	
	env_inst.AllocHeap();
	cout<<env_inst<<endl;
	
	BuildLdaGraph("./graph/graph_lda/graph_lda");
        cout << "Generating Graph Data Done. " << endl;
    	
	graph_type lda_graph;
	lda_graph.load_format("./graph/graph_lda/graph_lda");
	cout <<"Loading Graph Done."<<endl;
	
	
	cout<<"LDA Start..."<<endl;	
	saedb::IEngine<lda_init> *engine_init = new saedb::EngineDelegate<lda_init>(lda_graph);	
	engine_init->signalAll();
	engine_init->start();
	delete engine_init;
	cout<<"Init done"<<endl;
	
	
	for(int i=0;i<env_inst.NROUNDS;i++)
	{
		cout<<"ROUNDS "<<i+1<<" is running!"<<endl;
		saedb::IEngine<lda_gibbs> *engine_gibbs = new saedb::EngineDelegate<lda_gibbs>(lda_graph);
		engine_gibbs->signalAll();			
		engine_gibbs->start();
		delete engine_gibbs;
		if ((i > env_inst.BURN_IN) && (env_inst.SAMPLE_LAG > 0) && (i % env_inst.SAMPLE_LAG == 0)) {
			saedb::IEngine<lda_update> *engine_update = new saedb::EngineDelegate<lda_update>(lda_graph);
			engine_update->signalAll();			
			engine_update->start();
			delete engine_update;
			env_inst.numstats++;
        	}
	}
	
	GetDistribution();
	cout<<"LDA Finished."<<endl;

	OutputLda();
	cout<<"Output Distribution Done."<<endl;
	
	//release resources
	for (auto i = 0; i < lda_graph.num_local_vertices(); i ++) {
	    	vertex_data v= lda_graph.vertex(i).parse<vertex_data>();
            	v.ReleaseHeap();
	}
	env_inst.ReleaseHeap();
        cout << "End LDA Module." << endl;
}
Пример #3
0
  /**
   * Called by SetUp to initialize the weights associated with any top blobs in
   * the loss function. Store non-zero loss weights in the diff blob.
   */
  inline void SetLossWeights(const vector<Blob<Dtype>*>& top) {
    const int num_loss_weights = layer_param_.loss_weight_size();
    if (num_loss_weights) {
      CHECK_EQ(top.size(), num_loss_weights) << "loss_weight must be "
          "unspecified or specified once per top blob.";
      for (int top_id = 0; top_id < top.size(); ++top_id) {
#ifdef USE_MLSL
        const Dtype loss_weight = layer_param_.loss_weight(top_id) /
          GetDistribution().get_data_parts();
#else
        const Dtype loss_weight = layer_param_.loss_weight(top_id);
#endif
        if (loss_weight == Dtype(0)) { continue; }
        this->set_loss(top_id, loss_weight);
        const int count = top[top_id]->count();
        Dtype* loss_multiplier = top[top_id]->mutable_cpu_diff();
        caffe_set(count, loss_weight, loss_multiplier);
      }
    }
  }