SlideShare a Scribd company logo
1 of 4
Download to read offline
statistics.cpp
#include <iostream>
#include <fstream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include "statistics.hpp"
#include "tools.hpp"
using std::endl;
Histogram::Histogram(std::vector<double> &v, double t_bin_size)
{
bin_size = t_bin_size;
//Groesstes und kleinstes Element finden
min = *min_element(v.begin(), v.end());
double max = *max_element(v.begin(), v.end());
int num_bins = int((max - min) / bin_size + 1.0);
data.resize(num_bins, 0);
int position;
for (unsigned int i = 0; i < v.size(); i++)
{
position = int((v[i] - min) / bin_size);
data[position] += 1;
}
}
Histogram::~Histogram() {}
/*-----------------------------------------------*/
void Statistics::Init(int* t_grid_size, int* t_bin_size,
int* t_num_iterations, int* t_num_customers, int* t_num_salesman) {
grid_size = t_grid_size;
log_field.resize((*grid_size) * (*grid_size), 0);
bin_size = t_bin_size;
num_iterations = t_num_iterations;
num_customers = t_num_customers;
num_salesman = t_num_salesman;
log_p.clear(); log_p.resize(*num_salesman);
log_earn.clear(); log_earn.resize(*num_salesman); last_earn.clear();
last_earn.resize(*num_salesman, 0);
log_sales.clear(); log_sales.resize(*num_salesman); last_sales.clear();
last_sales.resize(*num_salesman, 0);
log_visits.clear(); log_visits.resize(*num_salesman);
Seite 1
statistics.cpp
last_visits.clear(); last_visits.resize(*num_salesman, 0);
path = "./output/";
prefix = "out";
}
void Statistics::LogField(int x, int y) {
log_field[x + y * (*grid_size)]++;
}
void Statistics::LogSalesman(int salesm_id, double earnings, double p, int
sales, int visits) {
log_p[salesm_id].push_back(p);
log_earn[salesm_id].push_back(earnings - last_earn[salesm_id]);
log_sales[salesm_id].push_back(sales - last_sales[salesm_id]);
log_visits[salesm_id].push_back(visits - last_visits[salesm_id]);
last_earn[salesm_id] = earnings;
last_sales[salesm_id] = sales;
last_visits[salesm_id] = visits;
}
void Statistics::WriteLogSalesman(std::string name) {
if (name == "") name = prefix;
Write2dVector(log_earn, path + name + "_earn.dat");
Write2dVector(log_p, path + name + "_p.dat");
Write2dVector(log_sales, path + name + "_sales.dat");
Write2dVector(log_visits, path + name + "_visits.dat");
}
void Statistics::Write2dVector(std::vector<std::vector<double> > &v, std::string
filename) {
std::ofstream write(filename.c_str());
for (unsigned int i = 0; i < v[0].size(); i++)
{
write << (i + 1) * (*bin_size) - 1;
for (unsigned int j = 0; j < v.size(); j++) {
write << "t" << v[j][i];
}
write << endl;
}
}
void Statistics::DivideData(std::vector<double> &v, double divisor) {
for (unsigned int i = 0; i < v.size(); i++) {
v[i] = v[i] / divisor;
}
}
Seite 2
statistics.cpp
void Statistics::Smoothing(std::vector<double> &v) {
int N = v.size();
std::vector<double> tmp(N, 0);
for (int i = 0; i < N; i++) {
tmp[i] += 0.4 * v[i];
if (i > 0) tmp[i] += 0.3 * v[i-1];
else tmp[i] += 0.3 * v[i];
if (i < N-1) tmp[i] += 0.3 * v[i+1];
else tmp[i] += 0.3 * v[i];
}
v = tmp;
}
void Statistics::MSmoothing(std::vector<double> &v, int n) {
for (int i = 0; i < n; i++) {
Smoothing(v);
}
}
double Statistics::Midpoint(std::vector<double> &v) {
double sum = 0; unsigned int size = v.size();
for (unsigned int i = 0; i < size; i++) {
sum = sum + v[i];
}
return sum/size;
}
double Statistics::Variance(std::vector<double> &v) {
double midpoint = Midpoint(v);
double sum = 0; unsigned int size = v.size();
for (unsigned int i = 0; i < size; i++) {
sum = sum + (v[i] - midpoint) * (v[i] - midpoint);
}
return sum/(size - 1);
}
void Statistics::WriteHistogram(std::vector<double> &v, double bin_size,
std::string filename) {
filename = path + prefix + "_" + filename;
std::ofstream write(filename.c_str());
Histogram histo(v, bin_size);
Seite 3
statistics.cpp
for (unsigned int i = 0; i < histo.data.size(); i++)
{
write << (i*bin_size + histo.min) << "t" << histo.data[i] <<
endl;
}
}
void Statistics::WriteFields(std::string filename) {
filename = path + prefix + "_" + filename;
std::ofstream write(filename.c_str());
int fx, fy;
for (unsigned int i = 0; i < log_field.size(); i++)
{
fx = i % (*grid_size);
fy = (i - fx) / (*grid_size);
write << fx << "t" << fy << "t" << log_field[i] << endl;
}
}
void Statistics::WriteFieldsDistance(std::string filename, int x, int y) {
filename = path + prefix + "_" + filename;
std::ofstream write(filename.c_str());
int fx, fy;
for (unsigned int i = 0; i < log_field.size(); i++)
{
fx = i % (*grid_size);
fy = (i - fx) / (*grid_size);
write << Distance(x, y, fx, fy, *grid_size) << "t" <<
log_field[i] << endl;
}
}
Seite 4

More Related Content

What's hot (20)

C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
 
Introduction to c part 2
Introduction to c   part  2Introduction to c   part  2
Introduction to c part 2
 
COW
COWCOW
COW
 
week-5x
week-5xweek-5x
week-5x
 
ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions
 
Wap in c to draw a line using DDA algorithm
Wap in c to draw a line using DDA algorithmWap in c to draw a line using DDA algorithm
Wap in c to draw a line using DDA algorithm
 
Gauss in java
Gauss in javaGauss in java
Gauss in java
 
Dvst
DvstDvst
Dvst
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
 
computer graphics practicals
computer graphics practicalscomputer graphics practicals
computer graphics practicals
 
CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017
CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017
CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017
 
Data Visualization with R.ggplot2 and its extensions examples.
Data Visualization with R.ggplot2 and its extensions examples.Data Visualization with R.ggplot2 and its extensions examples.
Data Visualization with R.ggplot2 and its extensions examples.
 
C questions
C questionsC questions
C questions
 
Doubly linklist
Doubly linklistDoubly linklist
Doubly linklist
 
Coding
CodingCoding
Coding
 
Currying in Swift
Currying in SwiftCurrying in Swift
Currying in Swift
 
C Programming :- An Example
C Programming :- An Example C Programming :- An Example
C Programming :- An Example
 
week-20x
week-20xweek-20x
week-20x
 
Conversion of data types in java
Conversion of data types in javaConversion of data types in java
Conversion of data types in java
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 

Viewers also liked

Structure-odor relations: a modern perspective
Structure-odor relations: a modern perspectiveStructure-odor relations: a modern perspective
Structure-odor relations: a modern perspectiveVorname Nachname
 
Electron transport in one dimensional nanosystems
Electron transport in one dimensional nanosystemsElectron transport in one dimensional nanosystems
Electron transport in one dimensional nanosystemsVorname Nachname
 
Smell in real noses: how the environment changes vibrations
Smell in real noses: how the environment changes vibrationsSmell in real noses: how the environment changes vibrations
Smell in real noses: how the environment changes vibrationsVorname Nachname
 
Dynamical symmetry breaking in vibration-assisted transport through nanostruc...
Dynamical symmetry breaking in vibration-assisted transport through nanostruc...Dynamical symmetry breaking in vibration-assisted transport through nanostruc...
Dynamical symmetry breaking in vibration-assisted transport through nanostruc...Vorname Nachname
 
Could humans recognize odor by phonon assisted tunneling
Could humans recognize odor by phonon assisted tunnelingCould humans recognize odor by phonon assisted tunneling
Could humans recognize odor by phonon assisted tunnelingVorname Nachname
 

Viewers also liked (13)

Structure-odor relations: a modern perspective
Structure-odor relations: a modern perspectiveStructure-odor relations: a modern perspective
Structure-odor relations: a modern perspective
 
Statstockprog
StatstockprogStatstockprog
Statstockprog
 
Dpsm simu.hpp
Dpsm simu.hppDpsm simu.hpp
Dpsm simu.hpp
 
Electron transport in one dimensional nanosystems
Electron transport in one dimensional nanosystemsElectron transport in one dimensional nanosystems
Electron transport in one dimensional nanosystems
 
Smell in real noses: how the environment changes vibrations
Smell in real noses: how the environment changes vibrationsSmell in real noses: how the environment changes vibrations
Smell in real noses: how the environment changes vibrations
 
Dynamical symmetry breaking in vibration-assisted transport through nanostruc...
Dynamical symmetry breaking in vibration-assisted transport through nanostruc...Dynamical symmetry breaking in vibration-assisted transport through nanostruc...
Dynamical symmetry breaking in vibration-assisted transport through nanostruc...
 
Tools.cpp
Tools.cppTools.cpp
Tools.cpp
 
Main.cpp
Main.cppMain.cpp
Main.cpp
 
Statistics.hpp
Statistics.hppStatistics.hpp
Statistics.hpp
 
Could humans recognize odor by phonon assisted tunneling
Could humans recognize odor by phonon assisted tunnelingCould humans recognize odor by phonon assisted tunneling
Could humans recognize odor by phonon assisted tunneling
 
Tools.hpp
Tools.hppTools.hpp
Tools.hpp
 
Dpsm simu.cpp
Dpsm simu.cppDpsm simu.cpp
Dpsm simu.cpp
 
Econophysics
EconophysicsEconophysics
Econophysics
 

Similar to CPP Stats Tools

DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfaathiauto
 
Questions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdfQuestions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdfapexelectronices01
 
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdfUsing standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdffashiongallery1
 
Some examples of the 64-bit code errors
Some examples of the 64-bit code errorsSome examples of the 64-bit code errors
Some examples of the 64-bit code errorsPVS-Studio
 
Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in CSaket Pathak
 
8 arrays and pointers
8  arrays and pointers8  arrays and pointers
8 arrays and pointersMomenMostafa
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfHIMANSUKUMAR12
 
An object of class StatCalc can be used to compute several simp.pdf
 An object of class StatCalc can be used to compute several simp.pdf An object of class StatCalc can be used to compute several simp.pdf
An object of class StatCalc can be used to compute several simp.pdfaravlitraders2012
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2Mouna Guru
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical FileAshwin Francis
 
program#include iostreamusing namespace std;void calculatio.pdf
program#include iostreamusing namespace std;void calculatio.pdfprogram#include iostreamusing namespace std;void calculatio.pdf
program#include iostreamusing namespace std;void calculatio.pdfinfo382133
 
Pushover analysis force analogy method with force control based on euler bern...
Pushover analysis force analogy method with force control based on euler bern...Pushover analysis force analogy method with force control based on euler bern...
Pushover analysis force analogy method with force control based on euler bern...Salar Delavar Qashqai
 
ParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfChen-Hung Hu
 
C++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerC++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerAndrey Karpov
 
Implement a function in c++ which takes in a vector of integers and .pdf
Implement a function in c++ which takes in a vector of integers and .pdfImplement a function in c++ which takes in a vector of integers and .pdf
Implement a function in c++ which takes in a vector of integers and .pdffeelingspaldi
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! aleks-f
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFTimur Safin
 

Similar to CPP Stats Tools (20)

DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
 
Questions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdfQuestions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdf
 
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdfUsing standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
 
Some examples of the 64-bit code errors
Some examples of the 64-bit code errorsSome examples of the 64-bit code errors
Some examples of the 64-bit code errors
 
Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in C
 
8 arrays and pointers
8  arrays and pointers8  arrays and pointers
8 arrays and pointers
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
 
An object of class StatCalc can be used to compute several simp.pdf
 An object of class StatCalc can be used to compute several simp.pdf An object of class StatCalc can be used to compute several simp.pdf
An object of class StatCalc can be used to compute several simp.pdf
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
 
10 template code program
10 template code program10 template code program
10 template code program
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
program#include iostreamusing namespace std;void calculatio.pdf
program#include iostreamusing namespace std;void calculatio.pdfprogram#include iostreamusing namespace std;void calculatio.pdf
program#include iostreamusing namespace std;void calculatio.pdf
 
Pushover analysis force analogy method with force control based on euler bern...
Pushover analysis force analogy method with force control based on euler bern...Pushover analysis force analogy method with force control based on euler bern...
Pushover analysis force analogy method with force control based on euler bern...
 
ParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdf
 
C++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerC++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical Reviewer
 
Implement a function in c++ which takes in a vector of integers and .pdf
Implement a function in c++ which takes in a vector of integers and .pdfImplement a function in c++ which takes in a vector of integers and .pdf
Implement a function in c++ which takes in a vector of integers and .pdf
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! 
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
 

More from Vorname Nachname (12)

Leni souza
Leni souzaLeni souza
Leni souza
 
Alien life forms
Alien life formsAlien life forms
Alien life forms
 
Spaceengine2
Spaceengine2Spaceengine2
Spaceengine2
 
Structural Language
Structural LanguageStructural Language
Structural Language
 
Language
LanguageLanguage
Language
 
Spaceengine2
Spaceengine2Spaceengine2
Spaceengine2
 
Spaceengine
SpaceengineSpaceengine
Spaceengine
 
Topology and Electrostatics
Topology and Electrostatics Topology and Electrostatics
Topology and Electrostatics
 
calculation of currents in nanowires
calculation of currents in nanowirescalculation of currents in nanowires
calculation of currents in nanowires
 
Summerpoject 2005
Summerpoject 2005Summerpoject 2005
Summerpoject 2005
 
Aspelmeyer
AspelmeyerAspelmeyer
Aspelmeyer
 
Arndt matter wave interferometry
Arndt matter wave interferometry Arndt matter wave interferometry
Arndt matter wave interferometry
 

Recently uploaded

Zoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfZoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfSumit Kumar yadav
 
Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfSumit Kumar yadav
 
Forensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfForensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfrohankumarsinghrore1
 
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptxUnlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptxanandsmhk
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPirithiRaju
 
fundamental of entomology all in one topics of entomology
fundamental of entomology all in one topics of entomologyfundamental of entomology all in one topics of entomology
fundamental of entomology all in one topics of entomologyDrAnita Sharma
 
Raman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral Analysis
Raman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral AnalysisRaman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral Analysis
Raman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral AnalysisDiwakar Mishra
 
Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)PraveenaKalaiselvan1
 
Botany krishna series 2nd semester Only Mcq type questions
Botany krishna series 2nd semester Only Mcq type questionsBotany krishna series 2nd semester Only Mcq type questions
Botany krishna series 2nd semester Only Mcq type questionsSumit Kumar yadav
 
VIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PVIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PPRINCE C P
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTSérgio Sacani
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )aarthirajkumar25
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Lokesh Kothari
 
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceuticsPulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceuticssakshisoni2385
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...RohitNehra6
 
GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)Areesha Ahmad
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...anilsa9823
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksSérgio Sacani
 
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCRStunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCRDelhi Call girls
 

Recently uploaded (20)

Zoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfZoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdf
 
Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdf
 
Forensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfForensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdf
 
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptxUnlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
 
fundamental of entomology all in one topics of entomology
fundamental of entomology all in one topics of entomologyfundamental of entomology all in one topics of entomology
fundamental of entomology all in one topics of entomology
 
Raman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral Analysis
Raman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral AnalysisRaman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral Analysis
Raman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral Analysis
 
Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)
 
Botany krishna series 2nd semester Only Mcq type questions
Botany krishna series 2nd semester Only Mcq type questionsBotany krishna series 2nd semester Only Mcq type questions
Botany krishna series 2nd semester Only Mcq type questions
 
VIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PVIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C P
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOST
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
 
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceuticsPulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...
 
GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disks
 
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCRStunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
 
CELL -Structural and Functional unit of life.pdf
CELL -Structural and Functional unit of life.pdfCELL -Structural and Functional unit of life.pdf
CELL -Structural and Functional unit of life.pdf
 

CPP Stats Tools

  • 1. statistics.cpp #include <iostream> #include <fstream> #include <cmath> #include <vector> #include <algorithm> #include <string> #include "statistics.hpp" #include "tools.hpp" using std::endl; Histogram::Histogram(std::vector<double> &v, double t_bin_size) { bin_size = t_bin_size; //Groesstes und kleinstes Element finden min = *min_element(v.begin(), v.end()); double max = *max_element(v.begin(), v.end()); int num_bins = int((max - min) / bin_size + 1.0); data.resize(num_bins, 0); int position; for (unsigned int i = 0; i < v.size(); i++) { position = int((v[i] - min) / bin_size); data[position] += 1; } } Histogram::~Histogram() {} /*-----------------------------------------------*/ void Statistics::Init(int* t_grid_size, int* t_bin_size, int* t_num_iterations, int* t_num_customers, int* t_num_salesman) { grid_size = t_grid_size; log_field.resize((*grid_size) * (*grid_size), 0); bin_size = t_bin_size; num_iterations = t_num_iterations; num_customers = t_num_customers; num_salesman = t_num_salesman; log_p.clear(); log_p.resize(*num_salesman); log_earn.clear(); log_earn.resize(*num_salesman); last_earn.clear(); last_earn.resize(*num_salesman, 0); log_sales.clear(); log_sales.resize(*num_salesman); last_sales.clear(); last_sales.resize(*num_salesman, 0); log_visits.clear(); log_visits.resize(*num_salesman); Seite 1
  • 2. statistics.cpp last_visits.clear(); last_visits.resize(*num_salesman, 0); path = "./output/"; prefix = "out"; } void Statistics::LogField(int x, int y) { log_field[x + y * (*grid_size)]++; } void Statistics::LogSalesman(int salesm_id, double earnings, double p, int sales, int visits) { log_p[salesm_id].push_back(p); log_earn[salesm_id].push_back(earnings - last_earn[salesm_id]); log_sales[salesm_id].push_back(sales - last_sales[salesm_id]); log_visits[salesm_id].push_back(visits - last_visits[salesm_id]); last_earn[salesm_id] = earnings; last_sales[salesm_id] = sales; last_visits[salesm_id] = visits; } void Statistics::WriteLogSalesman(std::string name) { if (name == "") name = prefix; Write2dVector(log_earn, path + name + "_earn.dat"); Write2dVector(log_p, path + name + "_p.dat"); Write2dVector(log_sales, path + name + "_sales.dat"); Write2dVector(log_visits, path + name + "_visits.dat"); } void Statistics::Write2dVector(std::vector<std::vector<double> > &v, std::string filename) { std::ofstream write(filename.c_str()); for (unsigned int i = 0; i < v[0].size(); i++) { write << (i + 1) * (*bin_size) - 1; for (unsigned int j = 0; j < v.size(); j++) { write << "t" << v[j][i]; } write << endl; } } void Statistics::DivideData(std::vector<double> &v, double divisor) { for (unsigned int i = 0; i < v.size(); i++) { v[i] = v[i] / divisor; } } Seite 2
  • 3. statistics.cpp void Statistics::Smoothing(std::vector<double> &v) { int N = v.size(); std::vector<double> tmp(N, 0); for (int i = 0; i < N; i++) { tmp[i] += 0.4 * v[i]; if (i > 0) tmp[i] += 0.3 * v[i-1]; else tmp[i] += 0.3 * v[i]; if (i < N-1) tmp[i] += 0.3 * v[i+1]; else tmp[i] += 0.3 * v[i]; } v = tmp; } void Statistics::MSmoothing(std::vector<double> &v, int n) { for (int i = 0; i < n; i++) { Smoothing(v); } } double Statistics::Midpoint(std::vector<double> &v) { double sum = 0; unsigned int size = v.size(); for (unsigned int i = 0; i < size; i++) { sum = sum + v[i]; } return sum/size; } double Statistics::Variance(std::vector<double> &v) { double midpoint = Midpoint(v); double sum = 0; unsigned int size = v.size(); for (unsigned int i = 0; i < size; i++) { sum = sum + (v[i] - midpoint) * (v[i] - midpoint); } return sum/(size - 1); } void Statistics::WriteHistogram(std::vector<double> &v, double bin_size, std::string filename) { filename = path + prefix + "_" + filename; std::ofstream write(filename.c_str()); Histogram histo(v, bin_size); Seite 3
  • 4. statistics.cpp for (unsigned int i = 0; i < histo.data.size(); i++) { write << (i*bin_size + histo.min) << "t" << histo.data[i] << endl; } } void Statistics::WriteFields(std::string filename) { filename = path + prefix + "_" + filename; std::ofstream write(filename.c_str()); int fx, fy; for (unsigned int i = 0; i < log_field.size(); i++) { fx = i % (*grid_size); fy = (i - fx) / (*grid_size); write << fx << "t" << fy << "t" << log_field[i] << endl; } } void Statistics::WriteFieldsDistance(std::string filename, int x, int y) { filename = path + prefix + "_" + filename; std::ofstream write(filename.c_str()); int fx, fy; for (unsigned int i = 0; i < log_field.size(); i++) { fx = i % (*grid_size); fy = (i - fx) / (*grid_size); write << Distance(x, y, fx, fy, *grid_size) << "t" << log_field[i] << endl; } } Seite 4