Changeset 3917
- Timestamp:
- May 31, 2020, 7:26:09 AM (3 years ago)
- Location:
- trunk/yat/statistics
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/statistics/Makefile.am
r3792 r3917 40 40 yat/statistics/SAMScore.cc yat/statistics/Score.cc \ 41 41 yat/statistics/Smoother.cc yat/statistics/SNRScore.cc \ 42 yat/statistics/Spearman.cc yat/statistics/tScore.cc \ 42 yat/statistics/Spearman.cc \ 43 yat/statistics/TukeyBiweightEstimator.cc \ 44 yat/statistics/tScore.cc \ 43 45 yat/statistics/tTest.cc \ 44 46 yat/statistics/utility.cc yat/statistics/VectorFunction.cc \ -
trunk/yat/statistics/TukeyBiweightEstimator.h
r3875 r3917 65 65 { 66 66 public: 67 /** 68 \since New in yat 0.18 69 */ 70 class Stopper 71 { 72 public: 73 /** 74 Default constructor sets max epochs to 1000 75 */ 76 Stopper(size_t max_epochs=1000); 77 /** 78 \return true if \a current is sufficiently close to \a previous 79 */ 80 virtual bool operator()(double current, double previous) const=0; 81 protected: 82 /// \return number of epochs 83 size_t epochs(void) const; 84 /// \return number of max epochs 85 size_t max_epochs(void) const; 86 private: 87 size_t epochs_; 88 size_t max_epochs_; 89 friend TukeyBiweightEstimator; 90 bool stop(double current, double previous); 91 }; 92 67 93 /** 68 94 \brief Constructor … … 91 117 RandomAccessIterator last) const; 92 118 119 /** 120 \since New in yat 0.18 121 */ 122 template<typename RandomAccessIterator> 123 double operator()(RandomAccessIterator first, 124 RandomAccessIterator last, 125 Stopper& stopper) const; 126 93 127 private: 94 128 double cutoff_; … … 97 131 template<typename RandomAccessIterator> 98 132 double estimate(RandomAccessIterator first, 99 RandomAccessIterator last) const; 133 RandomAccessIterator last, 134 Stopper& stopper) const; 100 135 101 136 template<typename InputIterator> 102 137 double estimate(InputIterator first, InputIterator last, 103 138 double center, double spread) const; 139 140 class DefaultStopper : public Stopper 141 { 142 public: 143 bool operator()(double current, double previous) const; 144 }; 104 145 }; 146 105 147 106 148 template<typename RandomAccessIterator> 107 149 double TukeyBiweightEstimator::operator()(RandomAccessIterator first, 108 150 RandomAccessIterator last) const 151 { 152 TukeyBiweightEstimator::DefaultStopper stopper; 153 return (*this)(first, last, stopper); 154 } 155 156 157 template<typename RandomAccessIterator> 158 double 159 TukeyBiweightEstimator::operator()(RandomAccessIterator first, 160 RandomAccessIterator last, 161 TukeyBiweightEstimator::Stopper& stopper) const 109 162 { 110 163 using boost_concepts::RandomAccessTraversal; … … 114 167 115 168 if (sorted_) 116 return estimate(first, last );169 return estimate(first, last, stopper); 117 170 118 171 // if not sorted, create a sorted copy … … 120 173 std::vector<typename traits::value_type> vec(first, last); 121 174 std::sort(vec.begin(), vec.end()); 122 return estimate(vec.begin(), vec.end() );175 return estimate(vec.begin(), vec.end(), stopper); 123 176 } 124 177 125 178 126 179 template<typename RandomAccessIterator> 127 double TukeyBiweightEstimator::estimate(RandomAccessIterator first, 128 RandomAccessIterator last) const 180 double 181 TukeyBiweightEstimator::estimate(RandomAccessIterator first, 182 RandomAccessIterator last, 183 TukeyBiweightEstimator::Stopper& stopper) const 129 184 { 130 185 const double scale = mad(first, last, true); … … 136 191 return m; 137 192 double m0 = m+1.0; 138 size_t epoch = 0; 139 // FIXME: let user define convergence requirement 140 while (m!=m0) { 193 while (!stopper.stop(m, m0)) { 141 194 m0 = m; 142 195 m = estimate(first, last, m, scale); 143 ++epoch;144 // FIXME: let user define maximal epochs145 if (epoch>1000)146 utility::runtime_error("TukeyBiweightIterator: too many epochs");147 196 } 148 197 return m;
Note: See TracChangeset
for help on using the changeset viewer.