SlideShare ist ein Scribd-Unternehmen logo
1 von 4
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Gauss in java
Gauss in javaGauss in java
Gauss in java
baxter89
 

Was ist angesagt? (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
 

Andere mochten auch (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
 

Ähnlich wie Statistics.cpp

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
aathiauto
 
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
apexelectronices01
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
HIMANSUKUMAR12
 
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
aravlitraders2012
 
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
feelingspaldi
 
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
 

Ähnlich wie Statistics.cpp (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
 

Mehr von Vorname Nachname

Mehr von 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
 

Kürzlich hochgeladen

Module for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learningModule for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learning
levieagacer
 
Seismic Method Estimate velocity from seismic data.pptx
Seismic Method Estimate velocity from seismic  data.pptxSeismic Method Estimate velocity from seismic  data.pptx
Seismic Method Estimate velocity from seismic data.pptx
AlMamun560346
 
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
Sérgio Sacani
 
biology HL practice questions IB BIOLOGY
biology HL practice questions IB BIOLOGYbiology HL practice questions IB BIOLOGY
biology HL practice questions IB BIOLOGY
1301aanya
 
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 bAsymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Sérgio Sacani
 

Kürzlich hochgeladen (20)

Forensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfForensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdf
 
Factory Acceptance Test( FAT).pptx .
Factory Acceptance Test( FAT).pptx       .Factory Acceptance Test( FAT).pptx       .
Factory Acceptance Test( FAT).pptx .
 
Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.
 
Module for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learningModule for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learning
 
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRL
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRLKochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRL
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRL
 
Seismic Method Estimate velocity from seismic data.pptx
Seismic Method Estimate velocity from seismic  data.pptxSeismic Method Estimate velocity from seismic  data.pptx
Seismic Method Estimate velocity from seismic data.pptx
 
Zoology 5th semester notes( Sumit_yadav).pdf
Zoology 5th semester notes( Sumit_yadav).pdfZoology 5th semester notes( Sumit_yadav).pdf
Zoology 5th semester notes( Sumit_yadav).pdf
 
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
 
Clean In Place(CIP).pptx .
Clean In Place(CIP).pptx                 .Clean In Place(CIP).pptx                 .
Clean In Place(CIP).pptx .
 
GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)
 
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
 
Unit5-Cloud.pptx for lpu course cse121 o
Unit5-Cloud.pptx for lpu course cse121 oUnit5-Cloud.pptx for lpu course cse121 o
Unit5-Cloud.pptx for lpu course cse121 o
 
Locating and isolating a gene, FISH, GISH, Chromosome walking and jumping, te...
Locating and isolating a gene, FISH, GISH, Chromosome walking and jumping, te...Locating and isolating a gene, FISH, GISH, Chromosome walking and jumping, te...
Locating and isolating a gene, FISH, GISH, Chromosome walking and jumping, te...
 
biology HL practice questions IB BIOLOGY
biology HL practice questions IB BIOLOGYbiology HL practice questions IB BIOLOGY
biology HL practice questions IB BIOLOGY
 
pumpkin fruit fly, water melon fruit fly, cucumber fruit fly
pumpkin fruit fly, water melon fruit fly, cucumber fruit flypumpkin fruit fly, water melon fruit fly, cucumber fruit fly
pumpkin fruit fly, water melon fruit fly, cucumber fruit fly
 
Feature-aligned N-BEATS with Sinkhorn divergence (ICLR '24)
Feature-aligned N-BEATS with Sinkhorn divergence (ICLR '24)Feature-aligned N-BEATS with Sinkhorn divergence (ICLR '24)
Feature-aligned N-BEATS with Sinkhorn divergence (ICLR '24)
 
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryFAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
 
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 bAsymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
 
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Alandi Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance Booking
 
GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)
 

Statistics.cpp

  • 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