36 #ifndef SHARK_ALGORITHMS_JAAKKOLAHEURISTIC_H 37 #define SHARK_ALGORITHMS_JAAKKOLAHEURISTIC_H 43 #include <boost/range/adaptor/filtered.hpp> 71 template<
class InputType>
75 typedef typename ConstProxyReference<InputType const>::type Element;
76 Elements elements = dataset.
elements();
77 if(!nearestFalseNeighbor) {
78 for(
typename Elements::iterator it = elements.begin(); it != elements.end(); ++it){
79 Element x = it->input;
80 typename Elements::iterator itIn = it;
82 for (; itIn != elements.end(); itIn++) {
83 if (itIn->label == it->label)
continue;
84 Element y = itIn->input;
85 double dist = distanceSqr(x,y);
86 m_stat.push_back(dist);
94 std::fill(m_stat.begin(),m_stat.end(), std::numeric_limits<double>::max());
95 std::size_t blockStart = 0;
96 for(std::size_t c = 0; c != classes; ++c){
98 typename Elements::iterator leftIt = elements.begin();
99 typename Elements::iterator end = elements.end();
100 while(leftIt != end){
104 std::size_t leftElements = 0;
105 while(leftElements < 512 && leftIt != end){
106 if(leftIt->label == c){
107 row(leftBatch,leftElements) = leftIt->input;
113 typename Elements::iterator rightIt = elements.begin();
114 while(rightIt != end){
116 std::size_t rightElements = 0;
117 while(rightElements < 512 && rightIt != end){
118 if(rightIt->label != c){
119 row(rightBatch,rightElements) = rightIt->input;
126 RealMatrix distances = distanceSqr(leftBatch,rightBatch);
127 for(std::size_t i = 0; i != leftElements;++i){
128 m_stat[blockStart+i]=std::min(min(subrange(row(distances,i),0,rightElements)),m_stat[blockStart+i]);
131 blockStart+= leftElements;
149 std::sort(m_stat.begin(), m_stat.end());
157 std::size_t ic = m_stat.size();
160 std::sort(m_stat.begin(), m_stat.end());
165 return std::sqrt(m_stat[0]);
170 return std::sqrt(m_stat[ic-1]);
175 double t = quantile * (ic - 1);
176 std::size_t i = (std::size_t)floor(t);
178 return ((1.0 - rest) * std::sqrt(m_stat[i]) + rest * std::sqrt(m_stat[i+1]));
188 double s =
sigma(quantile);
189 return 0.5 / (s * s);
195 std::vector<double> m_stat;