File: statistics.h

package info (click to toggle)
embree 3.12.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 27,412 kB
  • sloc: cpp: 173,822; xml: 3,737; ansic: 2,955; python: 1,628; sh: 480; makefile: 193; csh: 42
file content (83 lines) | stat: -rw-r--r-- 2,172 bytes parent folder | download
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2009-2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "../default.h"
#include <algorithm>

namespace embree
{
  /* calculates min/avg/max and sigma */
  struct Statistics
  {
  public:
    Statistics() 
      : v(0.0f), v2(0.0f), vmin(pos_inf), vmax(neg_inf), N(0) {}

    void add(float a) 
    {
      v += a;
      v2 += a*a;
      vmin = min(vmin,a);
      vmax = max(vmax,a);
      N++;
    }

    float getSigma() const 
    {
      if (N == 0) return 0.0f;
      else return (float) sqrt(max(0.0,v2/N - sqr(v/N)));
    }

    float getAvgSigma() const // standard deviation of average
    {
      if (N == 0) return 0.0f;
      else return getSigma()/sqrt(float(N));
    }

    float getMin() const { return vmin; }
    float getMax() const { return vmax; }
    float getAvg() const { return float(v/N); }

  private:
    double v;   // sum of all values
    double v2;  // sum of squares of all values
    float vmin; // min of all values
    float vmax; // max of all values
    size_t N;   // number of values
  };

  /* filters outlyers out */
  struct FilteredStatistics
  {
  public:
    FilteredStatistics(float fskip_small, float fskip_large) 
      : fskip_small(fskip_small), fskip_large(fskip_large) {}

    void add(float a) 
    {
      v.push_back(a);
      std::sort(v.begin(),v.end(),std::less<float>());
      size_t skip_small = (size_t) floor(0.5*fskip_small*double(v.size()));
      size_t skip_large = (size_t) floor(0.5*fskip_large*double(v.size()));

      stat = Statistics();
      for (size_t i=skip_small; i<v.size()-skip_large; i++)
        stat.add(v[i]);
    }

    float getSigma() const { return stat.getSigma(); }
    float getAvgSigma() const { return stat.getAvgSigma(); }
    float getMin() const { return stat.getMin(); }
    float getMax() const { return stat.getMax(); }
    float getAvg() const { return stat.getAvg(); }
    Statistics getStatistics() const { return stat; }

  private:
    float fskip_small; // fraction of small outlyers to filter out
    float fskip_large; // fraction of large outlyers to filter out
    std::vector<float> v;
    Statistics stat;
  };
}