Example #1
0
void ds::BinnedData::write(std::string file, bool average) const
{
    tdx::File writeFile(file, tdx::File::out);
    
    //Check for the existence of the file
    if(writeFile.exists())
    {
        std::cout << "WARNING: File.. " << file << " already exists. Overwriting!\n";
    }
    
    std::string output = "";
    output += "\n";
    if(average) output += "#Averaged ";
    else output += "#Summed ";
    output += "data in range (" + 
                std::to_string(min_range()) +
                ", " + std::to_string(max_range()) +
                ") spaced by " + std::to_string(spacing())+ ":\n\n";
    
    for(int bin=0; bin<bins(); bin++)
    {
        double data_point = min_range() + (bin)*spacing();
        double data;
        if(average) data = average_in(bin);
        else data = sum_in(bin);
        output += std::to_string(data_point) + "\t" + std::to_string(data) + "\n";
    }
    
    writeFile << output;
    writeFile.close();
}
Example #2
0
void ds::BinnedData::add_data_at(double data_point, double data_value)
{
    //Find the appropriate bin
    if ( data_point <= max_range() && data_point >= min_range() ) 
    {
        int bin = get_bin_number(data_point);
        if(bin != -1)
        {   
            _data[bin] += data_value;
            _counts[bin]++;
        }
    }
} 
void compute_hash_codes(unsigned int *codes, float *X, int N, 
			int nbins, float *min, 
			float *max){
  
  float range[DIM];
  float qstep;

  int i;
  for(i=0; i<DIM; i++){
    range[i] = fabs(max[i] - min[i]); // The range of the data
    range[i] += 0.01*range[i]; // Add somthing small to avoid having points exactly at the boundaries 
  }

  qstep = max_range(range) / nbins; // The quantization step 
  
  quantize(codes, X, min, qstep, N); // Function that does the quantization
}
Example #4
0
std::string ds::BinnedData::plot_profile(bool average) const
{
    std::string output = "";
    output += "\n";
    if(average) output += "#Averaged ";
    else output += "#Summed ";
    output += "data in range (" + 
                std::to_string(min_range()) +
                ", " + std::to_string(max_range()) +
                ") spaced by " + std::to_string(spacing())+ ":\n\n";
    
    double max_value;
    if(average) 
    {
        max_value = max_averaged_value();
    }
    else 
    {
        max_value = max_summed_value();
    }
    
    double max_points = 100;
    double step_value = max_value/max_points;
    
    for(int bin=0; bin<bins(); bin++)
    {
        double data_point = min_range() + (bin)*spacing();
        
        double data;
        if(average) data = average_in(bin);
        else data = sum_in(bin);
        
        int steps = int(data/step_value);
        output += std::to_string(data_point) + "\t|";
        for(int s=0; s<steps; s++) output += '+';
        output += " (" + std::to_string(data) + ")";
        output +="\n";
    }
    
    return output;
}
Example #5
0
double ds::BinnedData::spacing() const
{
    return (max_range() - min_range())/(bins());
}