/* * HistogramCreatorFunctions.cpp * * Created on: Oct 19, 2012 * Author: rryan */ #ifndef HISTOGRAMCREATORFUNCTIONS_CPP_ #define HISTOGRAMCREATORFUNCTIONS_CPP_ #include "HistogramCreatorFunctions.h" #include #include #include #include #include #include using namespace std; vector gaussianDataInt(int min, int max, int numOfPoints) { double samples = numOfPoints / 2.0; float range = abs((double) max - min); double innerLn; double ln; double squareRt; double normalize; double scale; double shift; vector data; int count = 0; for (int i = 0; i < samples; i++) { if (i == 0) { innerLn = samples / 0.0001; } else { innerLn = samples / (float) i; } ln = log(innerLn); squareRt = sqrt(ln); if (count < numOfPoints) { normalize = (3 + squareRt) / 6.0; scale = normalize * range; shift = scale + min; if (shift > max) { data.push_back(max); } else { data.push_back((int) shift); } count++; } if (count < numOfPoints) { normalize = (3 - squareRt) / 6.0; scale = normalize * range; shift = scale + min; if (shift < min) { data.push_back( min); } else { data.push_back((int) shift); } count++; } } return data; } vector gaussianDataFloat(float min, float max, int numOfPoints) { double samples = numOfPoints / 2.0; float range = abs(max - min); double innerLn; double ln; double squareRt; double normalize; double scale; double shift; vector data; int count = 0; for (int i = 0; i < samples; i++) { if (i == 0) { innerLn = samples / 0.0001; } else { innerLn = samples / (float) i; } ln = log(innerLn); squareRt = sqrt(ln); if (count < numOfPoints) { normalize = (3 + squareRt) / 6.0; scale = normalize * range; shift = scale + min; if (shift > max) { data.push_back((float) max); } else { data.push_back(shift); } count++; } if (count < numOfPoints) { normalize = (3 - squareRt) / 6.0; scale = normalize * range; shift = scale + min; if (shift < min) { data.push_back((float) min); } else { data.push_back(shift); } count++; } } return data; } vector sort(vector vect) { for (int i = 0; i < vect.size() - 1; i++) { for (int j = 0; j < vect.size() - 1 - i; j++) { int temp; if (vect.at(j) > vect.at(j + 1)) { temp = vect.at(j); vect.at(j) = vect.at(j + 1); vect.at(j + 1) = temp; } } } return vect; } vector sort(vector vect) { for (int i = 0; i < vect.size() - 1; i++) { for (int j = 0; j < vect.size() - 1 - i; j++) { float temp; if (vect.at(j) > vect.at(j + 1)) { temp = vect.at(j); vect.at(j) = vect.at(j + 1); vect.at(j + 1) = temp; } } } return vect; } string toString(vector data) { stringstream ss; int i; int count = 0; for (i = 0; i < data.size() - 1; i++) { char in[50]; sprintf(in, "%5i", data.at(i)); ss << in; count++; if (count > 9) { ss << endl; count = 0; } } char in[50]; sprintf(in, "%5i", data.at(i)); ss << in << endl << ends; return ss.str(); } string toString(vector data) { stringstream ss; int i; int count = 0; for (i = 0; i < data.size() - 1; i++) { char in[50]; sprintf(in, "%8.2f", data.at(i)); ss << in; count++; if (count > 9) { ss << endl; count = 0; } } char in[50]; sprintf(in, "%8.2f", data.at(i)); ss << in << endl << ends; return ss.str(); } //int main(int narg, char *argv[]) { // cout << toString(gaussianDataInt(0,10,10)) << endl; // cout << toString(sort(gaussianDataInt(0,10,50))) << endl; // cout << toString(gaussianDataInt(0,20,50)) << endl; // cout << toString(sort(gaussianDataInt(0,20,50))) << endl; // //// cout << toString(gaussianDataFloat(0.0,10.0,50)) << endl; //// cout << toString(sort(gaussianDataFloat(0.0,10.0,50))) << endl; //// cout << toString(gaussianDataFloat(-1.0,13.0,50)) << endl; //// cout << toString(sort(gaussianDataFloat(-1.0,13.0,50))) << endl; //} #endif /* HISTOGRAMCREATORFUNCTIONS_CPP_ */