Cytnx v0.7.4
Loading...
Searching...
No Matches
stat.hpp
Go to the documentation of this file.
1#ifndef _stat_H_
2#define _stat_H_
3
4#include "Type.hpp"
5#include "cytnx_error.hpp"
6#include "Storage.hpp"
7#include "Tensor.hpp"
8#include <algorithm>
9#include <iostream>
10namespace cytnx{
11 namespace stat{
12
14 class Histogram{
15 public:
16 double min;
17 double max;
18 uint64_t bins;
21
22 //std::vector<double> vars;
23 //std::vector<double> x;
24
26
27
31 Histogram(const unsigned long long &Nbins, const double &min_val, const double &max_val);
32
34 Histogram(const Histogram &rhs){
35 this->min = rhs.min;
36 this->max = rhs.max;
37 this->bins = rhs.bins;
38 this->vars = rhs.vars.clone();
39 this->x = rhs.x.clone();
40 this->total_count = rhs.total_count;
41 }
42
43 Histogram& operator=(const Histogram &rhs){
44 this->min = rhs.min;
45 this->max = rhs.max;
46 this->bins = rhs.bins;
47 this->vars = rhs.vars.clone();
48 this->x = rhs.x.clone();
49 this->total_count = rhs.total_count;
50 return *this;
51 }
53
54 void clear_vars(){
55 total_count = 0;
56 memset(this->vars.data(),0,sizeof(double)*this->vars.size());
57 }
58
59 template<class T>
60 void accumulate(const std::vector<T> &data){
61 std::vector<T> tmp = data;
62 std::sort(tmp.begin(),tmp.end());
63
64 uint64_t cntr = 0;
65 double curr_x = 0;
66 double dx = double(max-min)/bins;
67
68 // for each elem in data, compare
69 for(unsigned long long i=0;i<tmp.size();i++){
70 while(cntr<=this->bins){
71 if(tmp[i] < curr_x){
72 if(cntr){ vars.at<double>(cntr-1) += 1; total_count+=1;}
73 break;
74 }
75 cntr++;
76 curr_x = cntr*dx;
77 }
78 }
79 }
80
81 void normalize();
82 void print() const;
83
84 const Storage& get_x()const{
85 //get x
86 return this->x;
87 }
89 //get x
90 return this->x;
91 }
92
94 return this->x.size();
95 }
96
97 };//class histogram
98
99
100
101
102 //function, statistical:
103 //class Boostrap{
104
105
106 //};//class bootstrap
107
108
109
110
111
112
113 }//stat
114}//cytnx
115
116
117#endif
an memeory storage with multi-type/multi-device support
Definition Storage.hpp:934
const unsigned long long & size() const
the size ( no. of elements ) in the Storage
Definition Storage.hpp:1201
Storage clone() const
return a copy of current storage.
Definition Storage.hpp:1192
1D, real value histogram
Definition stat.hpp:14
cytnx::Storage x
Definition stat.hpp:20
cytnx::Storage vars
Definition stat.hpp:19
void clear_vars()
Definition stat.hpp:54
const Storage & get_x() const
Definition stat.hpp:84
Histogram(const unsigned long long &Nbins, const double &min_val, const double &max_val)
initialize a histogram
uint64_t bins
Definition stat.hpp:18
double min
Definition stat.hpp:16
double total_count
Definition stat.hpp:25
void accumulate(const std::vector< T > &data)
Definition stat.hpp:60
cytnx_uint64 size()
Definition stat.hpp:93
double max
Definition stat.hpp:17
Storage & get_x()
Definition stat.hpp:88
Definition Accessor.hpp:12
uint64_t cytnx_uint64
Definition Type.hpp:22