Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Change convergence condition to DBL_EPSILON.

Previsou coding is bad since comparison between two 0.0 floating points
are not necessarily possible.
  • Loading branch information...
commit d6a57eda9e4908ef5768ad2a5c70bd92d0abb3ae 1 parent ae0411f
Hitoshi Harada authored

Showing 1 changed file with 2 additions and 1 deletion. Show diff stats Hide diff stats

  1. +2 1  kmeans.c
3  kmeans.c
... ... @@ -1,5 +1,6 @@
1 1 #include "postgres.h"
2 2
  3 +#include <float.h>
3 4 #include <math.h>
4 5
5 6 #include "fmgr.h"
@@ -285,7 +286,7 @@ calc_kmeans(myvector inputs, int dim, int N, int k, myvector mean, int *r)
285 286 * if all the classification stay, diff must be 0.0,
286 287 * which means we can go out!
287 288 */
288   - if (target == new_target)
  289 + if (fabs(target - new_target) < DBL_EPSILON)
289 290 break;
290 291 target = new_target;
291 292 }

0 comments on commit d6a57ed

Please sign in to comment.
Something went wrong with that request. Please try again.