예제 #1
0
long double pdf::get_likelihood(long double theta) {
	// returns the value of the likelihood function for a given theta
	// assumes that a sample has already been generated
       	long double llh = 1.0;
       	for(int i=0; i<sample.size(); i++) 	
		llh*=get_pdf(sample.at(i), theta);	
	return llh;
}
예제 #2
0
long double pdf::get_loglikelihood(long double theta) {
	// returns the logarithm of the likelihood function
        // assumes that a sample has already been generated 
        long double logllh = 0.0;
        for(int i=0; i<sample.size(); i++) { 
		long double val = get_pdf(sample.at(i), theta);
                logllh+=log(val);
        }
        return logllh;
}
예제 #3
0
model::model(double in_t0, double in_t1, double in_mmin, 
                    double in_mmax, double in_cmfslope,
                    double in_gamma_min, double in_gamma_max, 
                    double in_eta, double in_ageslope,
                    double in_start, double in_stop, double in_step, 
		    double in_length, double in_fc){
    f_c = in_fc;
    length = in_length;
    t0 = in_t0;
    t1 = in_t1;
    mmin = in_mmin;
    mmax = in_mmax;
    cmf_slope = in_cmfslope;
    cmf_slope1 = cmf_slope + 1.;
    eta = in_eta;
    gamma_min = in_gamma_min;
    gamma_max = in_gamma_max;
    age_slope = in_ageslope;
    start = in_start;
    stop = in_stop;
    step = in_step;
//make array of luminosity convertying to ln L
    for(double v =log(pow(10,start)); v<log(pow(10,stop));v+=log(pow(10,step))){
          x.push_back(v);
    }
//cout<<x.size()<<endl;
//exit(1);
    omega = (age_slope + 1.)/eta - cmf_slope1;
    if (cmf_slope == -1){
      mean_m=(pow(mmax,cmf_slope+2)-pow(mmin,cmf_slope+2))/(cmf_slope+2);
      mean_m/=log(mmax/mmin);
    } else if( cmf_slope == -2){
      mean_m=log(mmax/mmin);
      mean_m/=(pow(mmax,cmf_slope+1)-pow(mmin,cmf_slope+1))/(cmf_slope+1);
    }else{
      mean_m=(pow(mmax,cmf_slope+2)-pow(mmin,cmf_slope+2))/(cmf_slope+2);
      mean_m/=(pow(mmax,cmf_slope+1)-pow(mmin,cmf_slope+1))/(cmf_slope+1);
    }
//for(int i=0;i<(long)x.size();i++)cout<<x[i]<<endl;
    get_cdf();   //CDF needs to be first to get normalization right
    get_pdf();

/*    sfr_grid.push_back(x);
    sfr_grid.push_back(x);
    sfr_grid.push_back(x);
    sfr_grid.push_back(x);
    cout<<x[0]<<"\t"<<x[1]<<endl;
    cout<<sfr_grid[0][0]<<"\t"<<sfr_grid[0][1]<<endl;
    cout<<sfr_grid[1][0]<<"\t"<<sfr_grid[1][1]<<endl;
    cout<<sfr_grid[2][0]<<"\t"<<sfr_grid[2][1]<<endl;
    cout<<sfr_grid[3][0]<<"\t"<<sfr_grid[3][1]<<endl;
exit(1);*/
}