Example #1
0
void GlobalGrid::makeBalanceWeights(){
        int num_tensors = tensorList->getNumIndexes();
        if ( tensor_weights != 0 ){ delete[] tensor_weights; }
        tensor_weights = new int[ num_tensors ]; tzero( num_tensors, tensor_weights );
        int max_level = computeMaxLevel();
        for( int l = max_level; l>=0; l-- ){
                for( int i=0; i<num_tensors; i++ ){
                        const int *iList = tensorList->getIndexList(i);
                        if ( tsum( num_dimensions, iList ) == l ){ // set the current level
                                tensor_weights[i] = 1 - tensor_weights[i];
                                for( int j=0; j<num_tensors; j++ ){
                                        if ( (i!=j) && (isSubset(tensorList->getIndexList(j), iList)) ){
                                                tensor_weights[j] += tensor_weights[i];
                                        }
                                }
                        }
                }
        }
}
Example #2
0
void GlobalGrid::reset( int dimensions, int outputs, int depth, TypeDepth type, TypeOneDRule oned, const int *anisotropic_weights, const double *alpha_beta ){
        clear();
        ruleType = oned;

        num_dimensions = dimensions;
        num_outputs = outputs;

        if ( (oned == rule_gaussgegenbauer) || (oned == rule_gausslaguerre) || (oned == rule_gausshermite) ){
                alpha = alpha_beta[0];
        }
        if ( (oned == rule_gaussjacobi) ){
                alpha = alpha_beta[0];
                beta  = alpha_beta[1];
        }

        if ( anisotropic_weights != 0 ){
                anisotropic = new int[num_dimensions+1];
                tcopy( num_dimensions, anisotropic_weights, anisotropic );
                anisotropic[num_dimensions] = tsum( num_dimensions, anisotropic_weights );
        }

        if ( type == type_level ){
                makeOnedRule( depth );
        }else if ( type == type_basis ){
                makeOnedRule( 3 );
                makeOnedRule( getLevelNeededForBasis( depth ) );
        }else{
                makeOnedRule( getLevelNeededForHyperbolic( depth ) );
        }

        makeTensorList( depth, type );

        makeTensorsArray();

        makeBalanceWeights();

        makePoints();
}
Example #3
0
//-----------------------------------------------------------------
void model::obs_pdf(double err){
   obs_err_pdf.clear();
   obs_err_cdf.clear();
   log_obs_err_cdf.clear();
   obs_err_pdf.resize(x.size());
   obs_err_cdf.resize(x.size());
   log_obs_err_cdf.resize(x.size());
   obs_err = err;
   vector<double> wgts_y;

   double fac = 1./(obs_err*sqrt(2*3.14159265359));
   long zero_ind=99999999999, ct=0;
   long num_ind=0;
   double diff_val=0;
   for(int i =0;i<(long)x.size();i++){
//cout<<x[i]<<endl;
      if(x[i]-x[0] > 5*obs_err){
         num_ind = i;
         diff_val = x[i]-x[0];
         break;
      }
   }
   for(double xx= -diff_val;xx<diff_val+log(pow(10,step))*.98; xx+=log(pow(10,step))){  
          if(fabs(xx) < 1e-8) zero_ind=ct;
          ct++;
          wgts_y.push_back(fac*exp(-0.5*(xx*xx)/(obs_err*obs_err)));
   }
//exit(10);
   double pdf_tmp, cdf_tmp;
   long xsz = (long) x.size();
   long wgts_ysz = (long) wgts_y.size();
   long wgts_wing = wgts_ysz - zero_ind-1;
   if(wgts_ysz != wgts_wing*2+1){
     cout<<"model::obs_pdf wgts is not the right dimension.. logic bug"<<endl;
     cout<<wgts_ysz<<"\t"<<wgts_wing<<"\t"<<zero_ind<<endl;
     exit(1);
   }
   double sum=0;
   for(int i=0; i<(long)x.size();i++){
       sum=0;
       pdf_tmp=0;
       cdf_tmp=0;
       for(int j= max((long)0,i-wgts_wing); j< min(i+wgts_wing, xsz-1); j++){
           //cout<<j-i+zero_ind<<"\t"<<j<<"\t"<<i<<"\t"<<zero_ind<<endl;
           sum += wgts_y[j-i+zero_ind];
           pdf_tmp+=wgts_y[j-i+zero_ind]*pdf[j];
           cdf_tmp+=wgts_y[j-i+zero_ind]*cdf[j];
       }
       obs_err_pdf[i]=(pdf_tmp/sum);
       obs_err_cdf[i]=(cdf_tmp/sum);
   }
   long last = (long)x.size()-1;
   double sum2 =tsum(x, obs_err_pdf);
   for(int i=0; i<(long)x.size();i++){
       obs_err_pdf[i] /= sum2;
//have to do pdf first
       obs_err_cdf[i] /= obs_err_cdf[last];
       log_obs_err_cdf[i] = log(obs_err_cdf[i]);
   }
 
   
}
Example #4
0
//-----------------------------------------------------------------
vector<double> model::sfr_pdf(double sfr){
    vector<double> out;
    out.resize(x.size());
    double expr =0;
    //double buffer =0;
    double nhat = f_c*length*pow(10., sfr)/mean_m;
      double tmp_log_nhat;
//cout<<sfr<<"\t"<<nhat<<"\t"<<f_c<<"\t"<<length<<"\t"<<pow(10., sfr)<<"\t"<<mean_m<<endl;
    if(nhat < 100){
    //if nhat is less than 100 then we can just brute force 300 iterations
    //to get the full distribution
    //I assume at least 1 cluser in each galaxy looked at because if there
    // wasn't a cluster it probably wasn't included in this study
    // THis is why the for loop starts at 1.... I will thus have to renormalize
      tmp_log_nhat = log(nhat);
      double jm1, tmp_fac;
      for(double j=1; j<300;j+=1){
//           j=floor(jj + 0.5); //round
           jm1=j-1;
           tmp_fac= j*exp( tmp_log_nhat*j-  lgamma(j+1)-nhat);
           for(int i=0;i<(long)x.size(); i++){
              expr = exp( log_obs_err_cdf[i]*(jm1))*obs_err_pdf[i]*
                          tmp_fac;
              if(expr != expr) expr=0;
              out[i]+=expr;
           }
       }
       //case of no clusters
cout<<exp(-nhat)<<endl;
       out[0] += exp(-nhat);


     /*   for(int i=0;i<(long)x.size(); i++){
           buffer = 0;
//           tmp_log_obs_err_cdf = log(obs_err_cdf[i]);
           tmp_log_nhat = log(nhat);
           for(int j=1;j < 300; j++){
               expr = j*exp( log_obs_err_cdf[i]*(j-1))*obs_err_pdf[i]*
                     exp( tmp_log_nhat*j-  lgamma(j+1)-nhat);
              if(expr != expr) expr=0;
              buffer += expr;
           }
           out[i]=buffer;
        }*/

    } else {
//majority of the code lives in this loop!!!!
      double sigma=sqrt(nhat);
      double sig_step=sigma/10.;
      double j=0;
      double tmp_log_nhat, tmp_fac, jm1;
      tmp_log_nhat = log(nhat);
      for(double jj=nhat-5*sigma; jj<( nhat+5*sigma);jj+=sig_step){
           j=floor(jj + 0.5); //round
           jm1=j-1;
           tmp_fac= j*exp( tmp_log_nhat*j-  lgamma(j+1)-nhat);
           for(int i=0;i<(long)x.size(); i++){
              expr = exp( log_obs_err_cdf[i]*(jm1))*obs_err_pdf[i]*
			  tmp_fac;
              if(expr != expr) expr=0;
              out[i]+=expr;
           }
       }
    }

 double sum = tsum(x, out);
 for(int i = 0;i<(long)x.size();i++) out[i] /= sum;
//cout<<out.size()<<endl;
 return(out);
}
Example #5
-1
int GlobalGrid::computeMaxLevel() const{
        int max_level = 0;
        for( int i=0; i<tensorList->getNumIndexes(); i++ ){
                int sum = tsum( num_dimensions, tensorList->getIndexList(i) );
                max_level = ( sum > max_level ) ? sum : max_level;
        }
        return max_level;
}