Iterator1 last = a + size;
while (a < last) {
- if (* b != 0) {
+ if ( *a != 0 && *b != 0 ) {
ResultType ratio = (ResultType)(*a / *b);
if (ratio>0) {
result += *a * log(ratio);
inline ResultType accum_dist(const U& a, const V& b, int) const
{
ResultType result = ResultType();
- if( *b != 0 ) {
+ if( a != 0 && b != 0 ) {
ResultType ratio = (ResultType)(a / b);
if (ratio>0) {
result = a * log(ratio);
*
* Params:
* node = the node to use
- * indices = the indices of the points belonging to the node
+ * indices = array of indices of the points belonging to the node
+ * indices_length = number of indices in the array
*/
void computeNodeStatistics(KMeansNodePtr node, int* indices, int indices_length)
{
memset(mean,0,veclen_*sizeof(DistanceType));
- for (size_t i=0; i<size_; ++i) {
+ for (size_t i=0; i<(size_t)indices_length; ++i) {
ElementType* vec = dataset_[indices[i]];
for (size_t j=0; j<veclen_; ++j) {
mean[j] += vec[j];
};
/**
- * Randomized kd-tree index
+ * Locality-sensitive hashing index
*
- * Contains the k-d trees and other information for indexing a set of points
+ * Contains the tables and other information for indexing a set of points
* for nearest-neighbor matching.
*/
template<typename Distance>
{
std::cerr << "LSH is not implemented for that type" << std::endl;
assert(0);
- return 1;
+ return 0;
}
/** Get statistics about the table
#endif
{
// Check for duplicate indices
- int j = i - 1;
- while ((j >= 0) && (dists[j] == dist)) {
+ for (int j = i; dists[j] == dist && j--;) {
if (indices[j] == index) {
return;
}
- --j;
}
break;
}