{{ message }}

Instantly share code, notes, and snippets.

# shubhamjain/SMQT.js

Created Jul 2, 2014
Successive Mean Quantization Transform
 function addUp(a, b, c) { catArr = b.concat(c); for(i = 0; i < catArr.length ; i++) a[i] += catArr[i]; return a; } var max_level = 8; /* Successive Mean Quantization transform. Calculate mean and recursively partion the array into two equal halveson basis of that. */ function SMQT( time_arr, L ) { if( L == max_level + 1) return []; var U = [], one_set, zero_set, sum_samples = 0, avg_samples = 0; one_set = []; zero_set = []; for( i = 0; i < time_arr.length; i++ ) sum_samples += time_arr[i]; avg_samples = sum_samples / time_arr.length; for( i = 0; i < time_arr.length; i++ ) { if( time_arr[i] >= avg_samples ) { U.push(1 << (max_level - L)); // 2 ^ (max_level - L) one_set.push(time_arr[i]); } else { U.push(0); zero_set.push(time_arr[i]); } } return addUp(U, SMQT(one_set, L + 1), SMQT(zero_set, L + 1)); }

### DanielMunozT commented Jan 28, 2015

 I believe that the last line should be (invert zero_set with one_set): return addUp(U, SMQT(zero_set, L + 1), SMQT(one_set, L + 1)); And also the comparison should be (remove equal): if( time_arr[i] > avg_samples ) Is this correct or I'm confused? (I'm new to this algorithm)