haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Quintiq file version 2.0
#parent: #root
Function CalcStatistics
{
  Description: 'Calculate the "summary statistics" for the values collected by the owning `LibOpt_Statistic` of this `LibOpt_StatisticSummary`.'
  TextBody:
  [*
    if( this.Statistic().NrElements() > 0 )
    {
      values := RealVector::Construct( this.Statistic().ValuesAsRealVector() ).AsValues();
      
      // Sort the values for correct calculations of the following attributes:
      // - `Q1`, `Median`, `Q3`, `Max`, `Min`
      values_sorted := values.Sort();
      
      // Set attributes for numerical statistics.
      this.Q1( LibOpt_Utility::GetRealByPercentile( 0.25, values_sorted ) );
      this.Median( LibOpt_Utility::GetRealByPercentile( 0.5, values_sorted ) );
      this.Q3( LibOpt_Utility::GetRealByPercentile( 0.75, values_sorted ) );
      this.Average( average( values_sorted, Elements, value, true, value ) );
      this.Max( values_sorted.Element( values_sorted.Size() - 1 ) );
      this.Min( values_sorted.Element( 0 ) );
      this.StandardDeviation( stddev( values_sorted, Elements, value, true, value )
                              // Make adjustments to get the population-based standard deviation as Quintiq's built-in `stddev` quantor is sample-based.
                              * ( values.Size() - 1)
                              / values.Size()
                            );
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}