int main (int argc, char *argv[]) { // srand(time(NULL)); // rand_generator.seed (rand()); rand_generator.seed (time(NULL)); //prepare the transcriptome transcriptome custom_transtome; pool_fragment custom_pool; long num_fragment_selected, num_fragment_selected_prev; custom_transtome.input_transcripts_gaf("trans.gaf", output_folder); custom_pool.generate_orig_pool(&custom_transtome); custom_pool.output_stat(output_folder, 0, &custom_transtome); num_fragment_selected_prev = 0; // for (int seq_round = 1; seq_round <= const_max_sequencing_round; ++seq_round) // { // custom_pool.random_fragmentation(const_num_cut_per_round); // num_fragment_selected = custom_pool.size_selection(const_size_window_low, const_size_window_high); // custom_pool.output_stat(output_folder, seq_round, &custom_transtome); // // if (num_fragment_selected > const_desired_num_reads) // break; // if (num_fragment_selected < num_fragment_selected_prev) // break; // num_fragment_selected_prev = num_fragment_selected; // } int seq_round; for (seq_round = 1; seq_round <= const_max_sequencing_round; ++seq_round) { cout << seq_round << "\t"; double cur_ratio_frag_in_target = custom_pool.random_fragmentation(const_num_cut_per_round); if (cur_ratio_frag_in_target > const_thresh_fragment_in_target_ratio) { break; } } num_fragment_selected = custom_pool.size_selection(const_size_window_low, const_size_window_high); custom_pool.output_stat(output_folder, seq_round, &custom_transtome); string filename = output_folder + "stat.txt"; ofstream stat_file(filename.c_str(), fstream::app); stat_file << "simulation finished" << endl << endl << endl; stat_file.close(); return 0; }
int main (int argc, char** argv) { // Set up random number generation randomNumberGenerator.seed( time(0) ); // Get the world settings if ( argc > 1 ) { getSettingsFromFile(argv[1]); } else { worldSize = 64; vectorLength = 1024; alpha = 0.1; lambda = 0.5; discount = 0.9; epsilon = 0.05; } eligibility.resize(vectorLength); weights.resize(vectorLength); hrrEngine.setVectorSize(vectorLength); // Set up a log file ofstream Log; Log.open("results.log"); // Set up a final report file ofstream FinalReport; FinalReport.open("final.log"); // Initialize the world array with states for (int i = 0; i < worldSize; i++) { // Create a new state and add it to the world array State newState(0, vectorLength, i); world.push_back(newState); } // Initialize weight vector for (double& weight : weights) { weight = 0.0; } // Set up statistical variables averageNumberOfSteps = 0; maxNumberOfSteps = 0; minNumberOfSteps = IntMax; // Set up a location for the goal goalLocation = randomNumberGenerator() % worldSize; world[goalLocation].setReward(1.0); // Main loop of program. Run episodes until task is learned for (int i = 0; i < numberOfRuns; i++) { // Set up a location for the agent agentLocation = randomNumberGenerator() % worldSize; // Initialize Episode statistical variables int numberOfSteps = 0; // Reset the eligibility vector fill(eligibility.begin(), eligibility.end(), 0); State* thisState; // Movement through an episode do { // Set up a variable for the previous state thisState = &world[agentLocation]; cout << "Goal Location: " << goalLocation << "\tCurrent State: " << thisState->isAt() << "\n"; // Update the eligibility of the current state updateEligibility(thisState->getHRR()); // If we are at the goal, calculate the td error differently, since // there are no future steps if (thisState->isAt() == goalLocation) { cout << "Goal reached in " << numberOfSteps << " steps.\n"; State G = *thisState; HRR a = G.getHRR(); double TDError = r(G) - V(G); cout << "\n\nr(G) = " << r(G) << "\tV(G) = " << V(G) << "\n\n"; cout << "TDError: " << TDError << "\n"; for ( int x = 0; x < weights.size(); x++ ) { weights[x] += alpha * TDError * a[x]; } break; } else { // Choose a movement for the agent Move movement = chooseMovement( world[getLeftLocation( agentLocation )], world[agentLocation], world[getRightLocation( agentLocation )] ); // Perform the movement switch (movement) { case Left: agentLocation = getLeftLocation(agentLocation); break; case Right: agentLocation = getRightLocation(agentLocation); break; default: agentLocation = getLeftLocation(agentLocation); break; } State* nextState = &world[agentLocation]; // Update the weights State s = *thisState; State sPlus1 = *nextState; HRR a = s.getHRR(); double TDError = ( r(s) + discount * V(sPlus1) ) - V(s); cout << "r(s) = " << r(s) << "\tV(s+1) = " << V(sPlus1) << "\tV(s) = " << V(s) << "\n"; cout << "TDError: " << TDError << '\n'; cout << "Run: " << i << ", Step: " << numberOfSteps << ", Location: " << agentLocation << ", Goal: " << goalLocation << "\n"; for ( int x = 0; x < vectorLength; x++ ) { weights[x] += alpha * TDError * a[x]; } } numberOfSteps++; } while ( numberOfSteps <= 100 ); } //cout << "The size of the hrrs is: " << hrrEngine.getVectorSize() << "\n"; //cout << "The size of the eligibility vector is: " << eligibility.size() << "\n"; //cout << "The size of the weight vector is: " << weights.size() << "\n"; cout << "Values of each state:\n"; for (int i = 0; i < worldSize; i++) { cout << "\tV(" << i << ") = " << V(world[i]) << "\n"; } return 0; }