21 #include<odindata/data.h>
22 #include<odindata/utils.h>
78 template<
typename T,
int N_rank>
91 ODINLOG(odinlog,errorLog) <<
"size mismatch (ensemble.shape()=" << ensemble.shape() <<
") != (mask.shape()=" << mask->shape() <<
")" << STD_endl;
96 int n=ensemble.numElements();
101 TinyVector<int,N_rank> index;
102 for(
int i=0; i<n; i++) {
105 if(mask && (*mask)(index)==0.0) include=
false;
107 float val=ensemble(index);
111 result.
min=result.
max=val;
113 if(val<result.
min) result.
min=val;
114 if(val>result.
max) result.
max=val;
121 for(
int i=0; i<n; i++) {
124 if(mask && (*mask)(index)==0.0) include=
false;
126 double diff=result.
mean-ensemble(index);
127 result.
stdev+=diff*diff;
131 if(nvals>1) result.
stdev=sqrt(result.
stdev/
double(nvals-1));
132 else result.
stdev=0.0;
145 template<
typename T,
int N_rank>
146 T
median(
const Array<T,N_rank>& ensemble,
const Array<T,N_rank>* mask=0) {
150 int n=ensemble_copy.numElements();
151 if(!n)
return result;
152 TinyVector<int,N_rank> index;
153 for(
int i=0; i<n; i++) {
156 if(mask && (*mask)(index)==0.0) include=
false;
157 if(include) vallist.push_back(ensemble_copy(index));
166 result=0.5*(vec[n/2]+vec[n/2-1]);
179 template<
typename T,
int N_rank>
180 T
weightmean(
const Array<T,N_rank>& ensemble,
const Array<float,N_rank>& weight) {
187 if(ensemble.shape()!=weight.shape()) {
188 ODINLOG(odinlog,errorLog) <<
"size mismatch (ensemble.shape()=" << ensemble.shape() <<
") != (weight.shape()=" << weight.shape() <<
")" << STD_endl;
193 TinyVector<int,N_rank> index;
194 for(
unsigned int i=0; i<ensemble_copy.numElements(); i++) {
196 float w=fabs(weight(index));
197 result+=w*ensemble_copy(index);
200 if(weightsum) result/=weightsum;
TinyVector< int, N_rank > create_index(unsigned long index) const
T median(const Array< T, N_rank > &ensemble, const Array< T, N_rank > *mask=0)
T weightmean(const Array< T, N_rank > &ensemble, const Array< float, N_rank > &weight)
bool same_shape(const Array< T, N_rank > &a1, const Array< T, N_rank > &a2, const TinyVector< int, N_rank > &dimmask=1)
statisticResult statistics(const Array< T, N_rank > &ensemble, const Array< T, N_rank > *mask=0)
STD_vector< T > list2vector(const STD_list< T > &src)
double secureDivision(double numerator, double denominator)
friend STD_ostream & operator<<(STD_ostream &s, statisticResult stats)