21 #ifndef __SOLVER_VARIABLE_STORAGE_STD_DEVIATION_H__
22 #define __SOLVER_VARIABLE_STORAGE_STD_DEVIATION_H__
27 using HighPrecision =
long double;
29 namespace Antares::Solver::Variable::R::AllYears
31 template<
class NextT = Empty,
int FileFilter = Variable::Category::FileLevel::allFile>
43 categoryFile = NextT::categoryFile | Variable::Category::FileLevel::allFile,
55 return "std deviation";
61 stdDeviationHourly.assign(HOURS_PER_YEAR, 0.);
62 stdDeviationDaily.assign(DAYS_PER_YEAR, 0.);
63 stdDeviationWeekly.assign(WEEKS_PER_YEAR, 0.);
64 stdDeviationMonthly.assign(MONTHS_PER_YEAR, 0.);
66 NextType::initializeFromStudy(study);
68 yearsWeight = study.parameters.getYearsWeight();
69 yearsWeightSum = study.parameters.getYearsWeightSum();
75 stdDeviationHourly.assign(HOURS_PER_YEAR, 0.);
76 stdDeviationDaily.assign(DAYS_PER_YEAR, 0.);
77 stdDeviationWeekly.assign(WEEKS_PER_YEAR, 0.);
78 stdDeviationMonthly.assign(MONTHS_PER_YEAR, 0.);
79 stdDeviationYear = 0.;
87 double pRatio = (double)yearsWeight[year] / (
double)yearsWeightSum;
91 for (i = 0; i != HOURS_PER_YEAR; ++i)
93 stdDeviationHourly[i] += rhs.
hour[i] * rhs.
hour[i] * pRatio;
96 for (i = 0; i != DAYS_PER_YEAR; ++i)
98 stdDeviationDaily[i] += rhs.
day[i] * rhs.
day[i] * pRatio;
101 for (i = 0; i != WEEKS_PER_YEAR; ++i)
103 stdDeviationWeekly[i] += rhs.
week[i] * rhs.
week[i] * pRatio;
106 for (i = 0; i != MONTHS_PER_YEAR; ++i)
108 stdDeviationMonthly[i] += rhs.
month[i] * rhs.
month[i] * pRatio;
111 stdDeviationYear += rhs.
year * rhs.
year * pRatio;
114 NextType::merge(year, rhs);
117 template<
class S,
class VCardT>
118 void buildSurveyReport(SurveyResults& report,
124 if (!(fileLevel & Category::FileLevel::id))
128 case Category::hourly:
129 InternalExportValues<S, HOURS_PER_YEAR, VCardT, Category::hourly>(
132 stdDeviationHourly.data());
134 case Category::daily:
135 InternalExportValues<S, DAYS_PER_YEAR, VCardT, Category::daily>(
138 stdDeviationDaily.data());
140 case Category::weekly:
141 InternalExportValues<S, WEEKS_PER_YEAR, VCardT, Category::weekly>(
144 stdDeviationWeekly.data());
146 case Category::monthly:
147 InternalExportValues<S, MONTHS_PER_YEAR, VCardT, Category::monthly>(
150 stdDeviationMonthly.data());
152 case Category::annual:
153 InternalExportValues<S, 1, VCardT, Category::annual>(report,
160 NextType::template buildSurveyReport<S, VCardT>(report,
168 std::vector<HighPrecision> stdDeviationMonthly;
169 std::vector<HighPrecision> stdDeviationWeekly;
170 std::vector<HighPrecision> stdDeviationDaily;
171 std::vector<HighPrecision> stdDeviationHourly;
172 HighPrecision stdDeviationYear = 0;
175 template<
class S,
unsigned int Size,
class VCardT,
int PrecisionT>
176 void InternalExportValues(SurveyResults& report,
178 const HighPrecision* array)
const
180 assert(report.data.columnIndex < report.maxVariables &&
"Column index out of bounds");
183 report.captions[0][report.data.columnIndex] = report.variableCaption;
184 report.captions[1][report.data.columnIndex] = report.variableUnit;
185 report.captions[2][report.data.columnIndex] =
"std";
188 report.precision[report.data.columnIndex] = PrecisionToPrintfFormat<
189 VCardT::decimal>::Value();
192 report.nonApplicableStatus[report.data.columnIndex] = *report.isCurrentVarNA;
195 double* target = report.values[report.data.columnIndex];
198 auto squareRootChecked = [](
double d) {
return d >= 0 ? std::sqrt(d) : 0.; };
202 case Category::hourly:
204 for (
unsigned int i = 0; i != Size; ++i)
206 double v = results.avgdata.hourly[i];
208 target[i] = squareRootChecked(a - v * v);
212 case Category::daily:
214 for (
unsigned int i = 0; i != Size; ++i)
216 double v = results.avgdata.daily[i];
218 target[i] = squareRootChecked(a - v * v);
222 case Category::weekly:
224 for (
unsigned int i = 0; i != Size; ++i)
226 double v = results.avgdata.weekly[i];
228 target[i] = squareRootChecked(a - v * v);
232 case Category::monthly:
234 for (
unsigned int i = 0; i != Size; ++i)
236 double v = results.avgdata.monthly[i];
238 target[i] = squareRootChecked(a - v * v);
242 case Category::annual:
244 const double d = *array - results.avgdata.allYears * results.avgdata.allYears;
245 *target = squareRootChecked(d);
251 ++report.data.columnIndex;
254 template<
class S,
unsigned int Size,
class VCardT,
int PrecisionT,
class A>
255 void InternalExportValuesMC(SurveyResults& report,
const S& ,
const A& array)
const
257 if (not(PrecisionT & Category::annual))
261 assert(report.data.columnIndex < report.maxVariables &&
"Column index out of bounds");
264 report.captions[0][report.data.columnIndex] = report.variableCaption;
265 report.captions[1][report.data.columnIndex] = report.variableUnit;
266 report.captions[2][report.data.columnIndex] =
"std";
269 report.precision[report.data.columnIndex] = PrecisionToPrintfFormat<
270 VCardT::decimal>::Value();
273 report.nonApplicableStatus[report.data.columnIndex] = *report.isCurrentVarNA;
275 (void)::memcpy(report.data.matrix[report.data.columnIndex], array, Size *
sizeof(
double));
278 ++report.data.columnIndex;
282 std::vector<float> yearsWeight;
283 float yearsWeightSum;
Definition: stdDeviation.h:47
Definition: stdDeviation.h:33
@ count
The count if item in the list.
Definition: stdDeviation.h:41
static const char * Name()
Name of the filter.
Definition: stdDeviation.h:53
NextT NextType
Type of the net item in the list.
Definition: stdDeviation.h:36