dune-composites (unstable)

general.hh
1// -*- tab-width: 4; indent-tabs-mode: nil -*-
2// vi: set et ts=4 sw=4 sts=4:
3#ifndef general_h
4#define general_h
5
6namespace Dune{
7 namespace Composites{
8
9
10 double mean(std::vector<double>& Y)
11 {
13 double Yhat = 0.0;
14 for (unsigned int i = 0; i < Y.size(); i++)
15 {
16 Yhat += Y[i];
17 }
18 Yhat /= Y.size();
19 return Yhat;
20 }
21
22 double var(std::vector<double>& Y)
23 {
25 double Yhat = mean(Y);
26 double variance = 0.0;
27 int N = Y.size();
28
29 for (int i = 0; i < N; i++)
30 {
31 variance += (Y[i] - Yhat) * (Y[i] - Yhat);
32 }
33 variance /= (N - 1);
34 return variance;
35 }
36
37 }
38}
39
40
41#endif /* general_h */
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 3, 22:46, 2025)