39 const dof_id_type n = cast_int<dof_id_type>(this->size());
41 normsq += ((*
this)[i] * (*this)[i]);
43 return std::sqrt(normsq);
50 LOG_SCOPE (
"minimum()",
"StatisticsVector");
52 const T
min = *(std::min_element(this->begin(), this->
end()));
63 LOG_SCOPE (
"maximum()",
"StatisticsVector");
65 const T
max = *(std::max_element(this->begin(), this->
end()));
76 LOG_SCOPE (
"mean()",
"StatisticsVector");
78 const dof_id_type n = cast_int<dof_id_type>(this->size());
84 the_mean += (
static_cast<Real>((*this)[i]) - the_mean ) /
85 static_cast<Real>(i + 1);
97 const dof_id_type n = cast_int<dof_id_type>(this->size());
102 LOG_SCOPE (
"median()",
"StatisticsVector");
104 std::sort(this->begin(), this->
end());
114 the_median =
static_cast<Real>((*this)[lhs]);
119 the_median = (
static_cast<Real>((*this)[lhs]) +
120 static_cast<Real>((*
this)[rhs]) ) / 2.0;
129 template <
typename T>
140 template <
typename T>
143 const dof_id_type n = cast_int<dof_id_type>(this->size());
145 LOG_SCOPE (
"variance()",
"StatisticsVector");
147 Real the_variance = 0;
151 const Real delta = (
static_cast<Real>((*this)[i]) - mean_in );
152 the_variance += (delta * delta - the_variance) /
153 static_cast<Real>(i + 1);
157 the_variance *=
static_cast<Real>(n) / static_cast<Real>(n - 1);
163 template <
typename T>
166 const dof_id_type n = cast_int<dof_id_type>(this->size());
167 const Real max = this->maximum();
170 (*
this)[i] =
static_cast<T
>((*this)[i] /
max);
177 template <
typename T>
182 libmesh_assert (n_bins>0);
184 const dof_id_type n = cast_int<dof_id_type>(this->size());
186 std::sort(this->begin(), this->
end());
192 Real bin_size = (
max -
min) / static_cast<Real>(n_bins);
194 LOG_SCOPE (
"histogram()",
"StatisticsVector");
196 std::vector<Real> bin_bounds(n_bins+1);
197 for (std::size_t i=0; i<bin_bounds.size(); i++)
198 bin_bounds[i] =
min +
Real(i) * bin_size;
203 bin_bounds.back() += 1.e-6 * bin_size;
206 bin_members.resize(n_bins);
209 for (std::size_t j=0; j<bin_members.size(); j++)
216 Real current_val =
static_cast<Real>( (*this)[i] );
221 if (current_val <
min)
230 if (current_val > bin_bounds[j+1])
250 const dof_id_type n_binned = std::accumulate(bin_members.begin(),
253 std::plus<dof_id_type>());
257 libMesh::out <<
"Warning: The number of binned entries, n_binned=" 259 <<
", did not match the total number of entries, n=" 260 << n <<
"." << std::endl;
269 template <
typename T>
271 const std::string & filename,
275 std::vector<dof_id_type> bin_members;
276 this->histogram(bin_members, n_bins);
279 T
min = this->minimum();
280 T
max = this->maximum();
281 T bin_size = (
max -
min) / static_cast<T>(n_bins);
286 std::ofstream out_stream (filename.c_str());
288 out_stream <<
"clear all\n";
289 out_stream <<
"clf\n";
294 for (std::size_t i=0; i<bin_members.size(); ++i)
296 out_stream <<
min + (
Real(i)+0.5)*bin_size <<
" ";
298 out_stream <<
"];\n";
301 for (std::size_t i=0; i<bin_members.size(); ++i)
303 out_stream << bin_members[i] <<
" ";
305 out_stream <<
"];\n";
306 out_stream <<
"bar(x,y);\n";
312 template <
typename T>
314 unsigned int n_bins)
const 318 return sv.
histogram(bin_members, n_bins);
324 template <
typename T>
327 LOG_SCOPE (
"cut_below()",
"StatisticsVector");
329 const dof_id_type n = cast_int<dof_id_type>(this->size());
331 std::vector<dof_id_type> cut_indices;
332 cut_indices.reserve(n/2);
336 if ((*
this)[i] < cut)
338 cut_indices.push_back(i);
348 template <
typename T>
351 LOG_SCOPE (
"cut_above()",
"StatisticsVector");
353 const dof_id_type n = cast_int<dof_id_type>(this->size());
355 std::vector<dof_id_type> cut_indices;
356 cut_indices.reserve(n/2);
359 if ((*
this)[i] > cut)
360 cut_indices.push_back(i);
372 #ifdef LIBMESH_DEFAULT_TRIPLE_PRECISION virtual T maximum() const
virtual Real mean() const
virtual Real l2_norm() const
uint8_t processor_id_type
A std::vector derived class for implementing simple statistical algorithms.
virtual std::vector< dof_id_type > cut_above(Real cut) const
long double max(long double a, double b)
void plot_histogram(const processor_id_type my_procid, const std::string &filename, unsigned int n_bins)
virtual void histogram(std::vector< dof_id_type > &bin_members, unsigned int n_bins=10)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual std::vector< dof_id_type > cut_below(Real cut) const
virtual T minimum() const
OStreamProxy out(std::cout)
long double min(long double a, double b)
virtual Real variance() const