OpendTect  6.6
statrand.h
Go to the documentation of this file.
1 #pragma once
2 /*+
3 ________________________________________________________________________
4 
5  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
6  Author: Bert Bril
7  Date: Sep 2006
8  RCS: $Id$
9 ________________________________________________________________________
10 
11 -*/
12 
13 #include "algomod.h"
14 #include "gendefs.h"
15 #include "odset.h"
16 
17 namespace Stats
18 {
19 
23 {
24 public:
25 
26  virtual ~RandomGenerator() {}
27  virtual void init(int seed);
28  // seed != 0 gives repeatable numbers
29 
30  virtual double get() const = 0; // returns in [0,1]
31 
32 };
33 
34 
38 {
39 public:
40 
42 
43  virtual double get() const;
45  int getInt() const;
47  int getInt(int min, int max) const;
49  int getIndex(int sz) const;
51  int getIndexFast(int sz,int seed) const;
57 
58  template <class T,class SzTp>
59  void subselect(T*,SzTp sz,SzTp targetsz) const;
63  template <class T>
64  void subselect(T&,od_int64 targetsz) const;
67 
68 private:
69 
70  int seed_;
71 
72 };
73 
74 
76 
77 
79 {
80 public:
81 
83 
84  virtual double get() const;
85  float get(float expect,float stdev) const;
86  double get(double expect,double stdev) const;
87 
88 protected:
89 
90  mutable bool useothdrawn_;
91  mutable double othdrawn_;
92 
93 };
94 
95 
96 template <class T,class SzTp>
97 inline void Stats::RandGen::subselect( T* arr, SzTp sz, SzTp targetsz ) const
98 {
99  for ( SzTp idx=sz-1; idx>=targetsz; idx-- )
100  {
101  const SzTp notselidx = getIndex( idx );
102  if ( notselidx != idx )
103  Swap( arr[notselidx], arr[idx] );
104  }
105 }
106 
107 
108 template <class ODSET>
109 inline void Stats::RandGen::subselect( ODSET& ods, od_int64 targetsz ) const
110 {
111  typedef typename ODSET::size_type size_type;
112  const size_type sz = ods.size();
113  if ( sz <= targetsz ) return;
114 
115  for ( size_type idx=sz-1; idx>=targetsz; idx-- )
116  {
117  const size_type notselidx = getIndex( idx );
118  if ( notselidx != idx )
119  ods.swap( notselidx, idx );
120  }
121 
122  removeRange( ods, (size_type)targetsz, sz-1 );
123 }
124 
125 }; // namespace Stats
126 
127 
Swap
void Swap(T &a, T &b)
Definition: commondefs.h:46
Stats::RandGen::getIndex
int getIndex(int sz) const
random index in the range [0,sz>
mGlobal
#define mGlobal(module)
Definition: commondefs.h:180
od_int64
#define od_int64
Definition: plftypes.h:35
Stats::RandomGenerator::init
virtual void init(int seed)
mExpClass
#define mExpClass(module)
Definition: commondefs.h:177
Stats::RandGen::getInt
int getInt(int min, int max) const
random int in the range [min,max]>
odset.h
Stats::RandGen::seed_
int seed_
Definition: statrand.h:70
Stats::NormalRandGen::useothdrawn_
bool useothdrawn_
Definition: statrand.h:90
Stats::RandGen::getIndexFast
od_int64 getIndexFast(od_int64 sz, od_int64 seed) const
getIndex using a very simple random generator
Stats::NormalRandGen::get
float get(float expect, float stdev) const
Stats::RandomGenerator::get
virtual double get() const =0
Stats::NormalRandGen::NormalRandGen
NormalRandGen()
Stats::RandGen::getInt
int getInt() const
Uniform int.
Stats::RandGen::get
virtual double get() const
Uniform [0-1].
Stats::RandGen::RandGen
RandGen()
Stats::RandGen::getIndex
od_int64 getIndex(od_int64 sz) const
random index in the range [0,sz>
gendefs.h
Stats::RandGen::subselect
void subselect(T &, od_int64 targetsz) const
Stats::NormalRandGen
Definition: statrand.h:79
Stats::NormalRandGen::othdrawn_
double othdrawn_
Definition: statrand.h:91
Stats::RandomGenerator
Random Generator.
Definition: statrand.h:23
Stats::RandGen
Uniform Random Generator.
Definition: statrand.h:38
Stats::RandomGenerator::~RandomGenerator
virtual ~RandomGenerator()
Definition: statrand.h:26
Stats
Statistics.
Definition: array2dinterpol.h:27
Stats::randGen
RandGen randGen()
Stats::NormalRandGen::get
double get(double expect, double stdev) const
Stats::RandGen::subselect
void subselect(T *, SzTp sz, SzTp targetsz) const
Definition: statrand.h:97
Stats::NormalRandGen::get
virtual double get() const
removeRange
void removeRange(ODSET &inst, size_type start, size_type stop)
Removes a range from the set.
Definition: odset.h:59
Stats::RandGen::getIndexFast
int getIndexFast(int sz, int seed) const
getIndex using a very simple random generator

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B.V. 1995-2021