clustering.c
Go to the documentation of this file.
00001 #include <math.h>
00002 
00003 #include "csm_all.h"
00004 
00005 
00006 /*
00007    A very very simple clustering algorithm.
00008    Try threshold = 5*sigma 
00009 */
00010 
00011 void ld_simple_clustering(LDP ld, double threshold) {   
00012         int cluster = -1;
00013         double last_reading = 0; /* I have to initialize it 
00014           explicitely or else gcc complains it might be uninitialized.
00015           Stupid compiler, it cannot even solve the halting problem. */
00016         
00017         int i;
00018         for(i=0;i<ld->nrays;i++) {
00019                 /* Skip if not valid */
00020                 if(!ld_valid_ray(ld,i)) {
00021                         ld->cluster[i] = -1;
00022                         continue;
00023                 }
00024                 /* If this is the first valid point, assign cluster #0 */
00025                 if(-1==cluster) 
00026                         cluster = 0;
00027                 else 
00028                 /* Else, start a new cluster if distance is above threshold */
00029                 if( fabs(last_reading-ld->readings[i]) > threshold)
00030                         cluster++;
00031                                 
00032                 ld->cluster[i] = cluster;
00033                 last_reading = ld->readings[i];
00034         }
00035         
00036         /* TODO: set to -1 the one-point clusters */
00037 }
00038 


csm
Author(s): Andrea Censi
autogenerated on Fri May 17 2019 02:28:33