Ejemplo n.º 1
0
//Function to Call the above Initialization Function in the Proper Order so as to assure that all inter-dependencies between successive calls are met. The argument defines which branch will be initialized
void PairInitializer::MakeProperInitializations(int branch, IntMatRef Homologies) {
    //A. Make General Initializations in proper order to ensure proper tree construction and parameters intialization //{
        //1. Initialize the Parameters from the Parameters File
        InitParameters();

        //2. Initialize the Rand Number Generator Engine by creating a new instance of the BoostRandomGenerator class
        InitRandomGenerator();

        //3. Initialize the Number of Steps that the left-right subtree resampling will be performed (from the previously created Parameters instance)
        InitNumOfSteps();

        //4. Initialize the Sequences (i.e. Bare Seqeunces, Initial Alignment, Sequence Headers etc) from the Corresponding Input Files
        InitSequences();

        //5. Initialize the AlignmentHomologies based on the previously read initial alignment
        InitAlignmentHomologies(Homologies);

        //6. Initialize (create) the Felsenstein Tree structure based on the red sequences and parameters
        InitTree();

        //7. Now that the tree structure is ready, Initialize ALL the Substitution Matrices for EVERY possible length of the Tree (and based on the defined - by the parameters - substitution model)
        InitOverallSubstitutionMatrices();

        //8.In a same way as before, now that the tree structure is ready, Initialize ALL the Felsenstein Pruning Tables for EVERY Node of the tree
        InitTreeFPTables();

    //}

    //B. Proceed to Make Proper Initializations for the variables and parameters concerning ONLY the subtree of interest (i.e. either the left or the right subtree) //{
        //1. Initialize the Subtree parameter to be aware of which subtree is being resampled
        InitBranch(branch);

        //2. Initialize the corresponding SubtreeIdxs for the current subtree
        InitBranchIdxs();

        //3. Initialize the Lengths corresponding only to the current subtree
        InitLengths();

        //4. Initialize the FPTables corresponding only to the current subtree
        InitFPTables();

        //5. Initialize (calculate) the Corresponding RegionHomologies based on the AlignmentHomologies corresponding only to the current fragment
        InitRegionHomologies();

        //6. Initialize the Start and End Indices for the current subtree
        InitStartAndEndIndices();

        //7. Initialize the Substitution Matrices corresponding only to the current subtree (and equivalently to the current subtree's lengths)
        InitSubstitutionMatrices();

        //8. Initialize the Dimensions (based on the previously estimated EndIdxs) corresponding  to the current subtree
        InitDimensions();

        //9. Now that everything is properly initialized, proceed to resample the whole alignment region (considering the given homologies) in order to come up with an evolution history, the Soans, the SoansIdxs and the Tihls for EVERY positon of the Root node (defined by the current subtree)
        ResampleHistoryGivenHomologies();

    //}

}
	ERMsg CBioSIMModelBase::Execute()
	{
		ERMsg msg;

		try
		{
			ASSERT(VerifyData(m_weather));

			//set default timestep
			if (msg)
				m_timeStep = m_weather.IsHourly() ? 1 : 4;

			//automatically generate random number		
			InitRandomGenerator(m_info.m_seed);
			Randomize((unsigned int)m_info.m_seed);//init old random number just in case


			switch (m_info.m_TM.Type())
			{
			case CTRef::HOURLY: msg = OnExecuteHourly(); break;
			case CTRef::DAILY: msg = OnExecuteDaily(); break;
			case CTRef::MONTHLY: msg = OnExecuteMonthly(); break;
			case CTRef::ANNUAL: msg = OnExecuteAnnual(); break;
			case CTRef::ATEMPORAL: msg = OnExecuteAtemporal(); break;
			default: msg = GetErrorMessage(ERROR_REF_NOT_SUPPORT);
			}
		}
		catch (ERMsg e)
		{
			msg = e;
		}
		catch (char* e)
		{
			msg.ajoute(e);
		}
		catch (...)
		{
			msg = GetErrorMessage(0);
		}

		return msg;
	}
Ejemplo n.º 3
0
void KG_GenerateEcdsaParameters(const char* encryptiontemplate, char* private_text, char* basepoint_text, char* public_x_text, char* public_y_text)
{
    EC_PARAMETER Base;
    EC_KEYPAIR Signer;
    ECC_POINT temp;
    char encryption_template[512];
    char rndinitstring[1024];
    unsigned long i[4];
    unsigned int basepointinit;
    BigInt test = BigInt_Create();
    BigInt secretkeyhash = BigInt_Create();
    BigInt prime_order = BigInt_Create();
    CookText(encryption_template, encryptiontemplate);
    md5(i, encryption_template, strlen(encryption_template));
    basepointinit = i[0];
    sprintf(basepoint_text, "%u", basepointinit);
    ECC_InitializeTable();
    BigInt_FromString(ECC_PRIMEORDER, 10, prime_order);
    BigIntToField(prime_order, &Base.pnt_order);
    Field_Clear(&Base.cofactor);
    Base.cofactor.e[ECC_NUMWORD] = 2;
    Base.crv.form = 1;
    Field_Set(&Base.crv.a2);
    Field_Set(&Base.crv.a6);
    InitRandomGenerator(basepointinit);
    ECC_RandomPoint(&temp, &Base.crv);
    ECC_PointDouble(&temp, &Base.pnt, &Base.crv);
    strcpy(rndinitstring, encryption_template);
    strcat(rndinitstring, "PVTKEY");
    BigInt_Hash(rndinitstring, strlen(rndinitstring), secretkeyhash);
    ECC_KeyGenerationPrimitive(&Base, &Signer, secretkeyhash);
    FieldToBigInt(&Signer.pblc_key.x, test);
    BigInt_ToString(test, 10, public_x_text);
    FieldToBigInt(&Signer.pblc_key.y, test);
    BigInt_ToString(test, 10, public_y_text);
    FieldToBigInt(&Signer.prvt_key, test);
    BigInt_ToString(test, 10, private_text);
    BigInt_Destroy(test);
    BigInt_Destroy(secretkeyhash);
    BigInt_Destroy(prime_order);
}
Ejemplo n.º 4
0
CBaseSimCtrl::CBaseSimCtrl(CBaseSimParams d) : SimulationParameters(d) {
    int currentId = MPI::COMM_WORLD.Get_rank();
    ProcCount = MPI::COMM_WORLD.Get_size();
    ManagerProcId = ProcCount - 1;
    ChildProcCount = ProcCount - 1;

    Cycles = 0;
    epsLine = 1;

    InitRandomGenerator();
    for (size_t i = 0; i < SimulationParameters.PtCount; i++) {
        auto pt = getPt(i);
        particles_new.push_back(pt);
        particles_old.push_back(pt);
        particles_init.push_back(pt);
    }

    PerProcCount = SimulationParameters.PtCount / ProcCount;

    CreateDataMapping();
}
	void CBioSIMModelBase::GetFValue(const std::vector<double>& paramArray, CStatisticXY& stat)
	{
		Randomize((unsigned int)m_info.m_seed);
		InitRandomGenerator(m_info.m_seed);

		for (size_t i = 0, j = 0; i < m_info.m_inputParameters.size() && j < paramArray.size(); i++)
		{
			if (m_info.m_inputParameters[i].IsVariable())
			{
				std::string value;
				value = ToString(paramArray[j]);
				m_info.m_inputParameters[i].SetString(value);
				j++;
			}
		}

		ProcessParameters(m_info.m_inputParameters);

		InitializeStat(stat);

		for (size_t i = 0; i < m_info.m_repCounter.GetTotal(); i++)
		{
			CStatisticXY statTmp;

			switch (m_info.m_TM.Type())
			{
			case CTM::HOURLY: GetFValueHourly(statTmp); break;
			case CTM::DAILY: GetFValueDaily(statTmp); break;
			case CTM::MONTHLY: GetFValueMonthly(statTmp); break;
			case CTM::ANNUAL: GetFValueAnnual(statTmp); break;
			case CTM::ATEMPORAL: GetFValueAtemporal(statTmp); break;
			default: _ASSERTE(false);
			}

			stat += statTmp;
		}


		FinalizeStat(stat);
	}
Ejemplo n.º 6
0
// --------------------------------------------------------------------------------//
// MAIN	                                                                           //
// --------------------------------------------------------------------------------//
int main(int argc, char* argv[]) 
{
  // process command-line arguments
  if (argc<2) { Usage(); exit(1); }
  char *method = argv[1];
  CmdLine *cmdLine = InitCmdLine(method);



  //--------------------------------------------------------------------------------------//
  // OPTION -permute: permute rows                                                        //
  //--------------------------------------------------------------------------------------//
  if (strcmp(method,"-permute")==0) { 
    // read options
    cmdLine->Read(argv+1,argc-1);
    MESSAGES(VERBOSE);

    // initialize random generator
    unsigned long int seed = RND_SEED+getpid()+time(NULL);
    gsl_rng *RANDOM_GENERATOR = InitRandomGenerator(seed);

    // read input
    long int n_lines;
    char **L;
    FILE *fp = LoadStdIn(&n_lines,BUFFER_SIZE);
    if (n_lines==0) return 0;
    ALLOCATE1D(L,n_lines,char *);
    FileBufferText *buffer = new FileBufferText(fp,BUFFER_SIZE);
    Progress PRG("Reading input rows...",n_lines);
    for (long int n=0; n<n_lines; n++) {
      L[n] = StrCopy(buffer->Next());
      PRG.Check();
    }
    PRG.Done();
    
    // permute
    long int *seq;
    ALLOCATE1D(seq,n_lines,long int);
    for (long int k=0; k<n_lines; k++) seq[k] = k;
    gsl_ran_shuffle(RANDOM_GENERATOR,seq,n_lines,sizeof(long int));

    // print output
    Progress PRG1("Printing output rows...",n_lines);
    for (long int n=0; n<n_lines; n++) {
      printf("%s\n", L[seq[n]]);
      PRG1.Check();
    }
    PRG1.Done();

    // cleanup
    FREE1D(seq);
    delete RANDOM_GENERATOR;
    delete buffer;
  }


  //--------------------------------------------------------------------------------------//
  // OPTION -resample: resample rows                                                      //
  //--------------------------------------------------------------------------------------//
  else if (strcmp(method,"-resample")==0) { 
    // read options
    cmdLine->Read(argv+1,argc-1);
    MESSAGES(VERBOSE);

    // initialize random generator
    unsigned long int seed = (RND_SEED==0)?(getpid()+time(NULL)):RND_SEED;
    gsl_rng *RANDOM_GENERATOR = InitRandomGenerator(seed);

    // read input
    long int n_lines;
    char **L;
    FILE *fp = LoadStdIn(&n_lines,BUFFER_SIZE);
    if (n_lines==0) return 0;
    ALLOCATE1D(L,n_lines,char *);
    FileBufferText *buffer = new FileBufferText(fp,BUFFER_SIZE);
    Progress PRG("Reading input rows...",n_lines);
    for (long int n=0; n<n_lines; n++) {
      L[n] = StrCopy(buffer->Next());
      PRG.Check();
    }
    PRG.Done();
    
    // print output
    if (N_SAMPLES<=0) N_SAMPLES = n_lines;
    Progress PRG1("Printing output rows...",N_SAMPLES);
    for (long int n=0; n<N_SAMPLES; n++) {
      long int k = gsl_rng_uniform_int(RANDOM_GENERATOR,n_lines);
      printf("%s\n", L[k]);
      PRG1.Check();
    }
    PRG1.Done();

    // cleanup
    delete RANDOM_GENERATOR;
    delete buffer;
  }


  //--------------------------------------------------------------------------------------//
  // OPTION -number: do row numbering                                                     //
  //--------------------------------------------------------------------------------------//
  else if (strcmp(method,"-number")==0) { 
    // read options
    cmdLine->Read(argv+1,argc-1);
    MESSAGES(VERBOSE);

    // read input
    FileBufferText buffer((char*)NULL,BUFFER_SIZE);
    Progress PRG("Reading input rows...",1);
    long int id = HEADER?0:1;
    for (char *inp=buffer.Next(); inp!=NULL; inp=buffer.Next()) {
      if (id==0) printf("\t");
      else printf("%s%012ld\t", PREFIX, id);
      printf("%s\n", inp);
      id++;
      PRG.Check();
    }
    PRG.Done();    
  }


  //--------------------------------------------------------------------------------------//
  // OTHER OPTIONS                                                                        //
  //--------------------------------------------------------------------------------------//
  else {
    // read options
    int next_arg = cmdLine->Read(argv,argc);
    MESSAGES(VERBOSE);
  
    // allocate buffer
    char *BUFFER = (char *) malloc(BUFFER_SIZE*sizeof(char));
    if (BUFFER==NULL) { fprintf(stderr, "Out of memory!\n"); exit(1); }

    Sequence rows = strlen(ROW_FILE)==0 ? GetRows(&argv[next_arg],argc-next_arg) : LoadRows(ROW_FILE);

    // option 1: use period
    if (PERIOD>0) {
      int choose = MERGE ? -1 : atoi(argv[next_arg]);
      //printf("(PERIOD,NEXTARG,CHOOSE) = (%i,%i,%i)\n", PERIOD, next_arg, choose);
      for (int n=0; ; n++) {
        if (fgets(BUFFER,BUFFER_SIZE,stdin)==NULL) break;
        if (BUFFER[strlen(BUFFER)-1]!='\n') { 
          fprintf(stderr, "Error: line was only partially read (max chars=%i)!\n", BUFFER_SIZE); exit(1);
        }
        if (BUFFER[strlen(BUFFER)-1]=='\n') BUFFER[strlen(BUFFER)-1] = 0;
        if (MERGE) printf("%s%s", BUFFER, n%PERIOD==PERIOD-1?"\n":SEPARATOR); 
        else if (n%PERIOD==choose) printf("%s\n", BUFFER); 
      }
    }

    // option 2: choose rows
    else {
      if (EXCLUDE==true) {
        for (long int n=0,k=1; k<=rows[0]; n++) {
          fgets(BUFFER,BUFFER_SIZE,stdin);
          if (feof(stdin)) break;
          if (BUFFER[strlen(BUFFER)-1]!='\n') { fprintf(stderr, "Error: line was only partially read (max chars=%i)!\n", BUFFER_SIZE); exit(1); }
          if (n<rows[k]) printf("%s", BUFFER);
	  else { ++k; if (EMPTY) printf("\n"); }
        }
        while (true) {
          fgets(BUFFER,BUFFER_SIZE,stdin);
          if (feof(stdin)) break;
          if (BUFFER[strlen(BUFFER)-1]!='\n') { fprintf(stderr, "Error: line was only partially read (max chars=%i)!\n", BUFFER_SIZE); exit(1); }
          printf("%s", BUFFER);
        }
      }
      else {
        for (long int n=0,k=1; k<=rows[0]; n++) {
          fgets(BUFFER,BUFFER_SIZE,stdin);
          if (feof(stdin)) break;
          if (BUFFER[strlen(BUFFER)-1]!='\n') { fprintf(stderr, "Error: line was only partially read (max chars=%i)!\n", BUFFER_SIZE); exit(1); }
          if (n==rows[k]) { printf("%s", BUFFER); k++; }
	  else if (EMPTY) printf("\n"); 
        }
        if (EMPTY) {
          while (true) {
            fgets(BUFFER,BUFFER_SIZE,stdin);
            if (feof(stdin)) break;
            if (BUFFER[strlen(BUFFER)-1]!='\n') { fprintf(stderr, "Error: line was only partially read (max chars=%i)!\n", BUFFER_SIZE); exit(1); }
            printf("\n");
          }
        }
      }
    }

    // clean up
    FREE1D(rows);
    FREE1D(BUFFER);
  }


  // clean up
  delete cmdLine;

  
  return 0;
}