Statistics.h 2.85 KB
Newer Older
1
2
3
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2010 ISIS Rutherford Appleton Laboratory UKRI,
4
5
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
7
#pragma once
8

9
#include "MantidKernel/DllConfig.h"
10
#include <vector>
11

12
13
14
15
16
17
namespace Mantid {
namespace Kernel {
namespace Math {
/**
 * Maps a "statistic" to a number
 */
Samuel Jones's avatar
Samuel Jones committed
18
enum StatisticType { FirstValue, LastValue, Minimum, Maximum, Mean, TimeAveragedMean, Median };
LamarMoore's avatar
LamarMoore committed
19
} // namespace Math
20

21
22
/**
   Simple struct to store statistics.
23

24
25
26
27
28
29
30
31
32
33
34
35
36
 */
struct Statistics {
  /// Minimum value
  double minimum;
  /// Maximum value
  double maximum;
  /// Mean value
  double mean;
  /// Median value
  double median;
  /// standard_deviation of the values
  double standard_deviation;
};
37

38
39
40
41
42
43
44
45
46
47
48
49
/// Controls the computation of statisical data
struct StatOptions {
  enum Flag {
    SortedData = 1,        // is the data sorted?
    Mean = 2,              // calculate the mean
    UncorrectedStdDev = 4, // calculate the s.d. using N dofs
    CorrectedStdDev = 8,   // calculate the s.d. using N-1 dofs
    Median = 16,           // calculate the median
    AllStats = (Mean | UncorrectedStdDev | Median)
  };
};

50
/** R factor for powder data analysis
LamarMoore's avatar
LamarMoore committed
51
 */
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
struct Rfactor {
  /// Rwp
  double Rwp;
  /// Rp
  double Rp;
  ///  Foos(int a, int b) : a(a), b(b) {}
  Rfactor(double rwp, double rp) : Rwp(rwp), Rp(rp) {}
  Rfactor() {
    Rwp = -1.0;
    Rp = -1.0;
  }
};

/// Return a statistics object for the given data set
template <typename TYPE>
Samuel Jones's avatar
Samuel Jones committed
67
Statistics getStatistics(const std::vector<TYPE> &data, const unsigned int flags = StatOptions::AllStats);
68
/// Return the Z score values for a dataset
Samuel Jones's avatar
Samuel Jones committed
69
template <typename TYPE> std::vector<double> getZscore(const std::vector<TYPE> &data);
70
template <typename TYPE>
Samuel Jones's avatar
Samuel Jones committed
71
std::vector<double> getWeightedZscore(const std::vector<TYPE> &data, const std::vector<TYPE> &weights);
72
/// Return the modified Z score values for a dataset
73
template <typename TYPE> std::vector<double> getModifiedZscore(const std::vector<TYPE> &data);
74
/// Return the R-factors (Rwp) of a diffraction pattern data
Samuel Jones's avatar
Samuel Jones committed
75
Rfactor MANTID_KERNEL_DLL getRFactor(const std::vector<double> &obsI, const std::vector<double> &calI,
76
77
78
79
                                     const std::vector<double> &obsE);

/// Return the first n-moments of the supplied data.
template <typename TYPE>
Samuel Jones's avatar
Samuel Jones committed
80
std::vector<double> getMomentsAboutOrigin(const std::vector<TYPE> &x, const std::vector<TYPE> &y,
81
82
83
                                          const int maxMoment = 3);
/// Return the first n-moments of the supplied data.
template <typename TYPE>
Samuel Jones's avatar
Samuel Jones committed
84
std::vector<double> getMomentsAboutMean(const std::vector<TYPE> &x, const std::vector<TYPE> &y,
85
86
                                        const int maxMoment = 3);
} // namespace Kernel
87
} // namespace Mantid