57 #define vN(data,i) (data+v->elements*i)
65 float val=(a[
i]-b[
i]);
84 float av=*((
float *)a);
85 float bv=*((
float *)b);
86 return (av<bv)-(av>bv);
91 float min=-1.f,
max=-1.f,mean=0.f,acc=0.f;
99 sprintf(buff,
"cellspace%d.m",v->
it);
100 cells=fopen(buff,
"w");
111 if(v->
assigned[k] && (localmin==-1 ||
this<localmin))
128 localmin=v->
max[
j]+localmin/2;
129 if(min==-1 || localmin<min)min=localmin;
134 spacings[count++]=localmin;
138 fprintf(stderr,
"cell diameter: %.03g::%.03g::%.03g (%ld unused/%ld dup)\n",
139 min,mean/acc,
max,unused,dup);
144 fprintf(cells,
"%g\n",spacings[i]);
171 float maxquant=((1<<q->
quant)-1);
175 mindel=maxdel=
_now(v,0)[0];
180 if(mindel>
_now(v,j)[k]-last)mindel=
_now(v,j)[
k]-last;
181 if(maxdel<
_now(v,j)[k]-last)maxdel=
_now(v,j)[
k]-last;
191 delta=(maxdel-mindel)/((1<<q->
quant)-1.5f);
203 float now=rint((val-last-mindel)/delta);
208 fprintf(stderr,
"fault; quantized value<0\n");
214 fprintf(stderr,
"fault; quantized value>max\n");
217 if(q->
sequencep)last=(now*delta)+mindel+last;
232 float now=
_now(v,j)[
k];
233 now=
fabs(now)*delta+last+mindel;
241 float (*metric)(
vqgen *,
float *,
float *),
274 for(k=0;k<v->
aux;k++)
301 if(((sortit++)&0xfff)==0)
spinnit(
"sorting mesh...",sortit);
302 return(memcmp(a,b,sortsize));
325 fprintf(stderr,
"\r%ld training points remining out of %ld"
326 " after density mesh (%ld%%)\n",march,v->
points,march*100/v->
points);
351 sprintf(buff,
"cells%d.m",v->
it);
352 cells=fopen(buff,
"w");
353 sprintf(buff,
"assig%d.m",v->
it);
354 assig=fopen(buff,
"w");
355 sprintf(buff,
"bias%d.m",v->
it);
356 bias=fopen(buff,
"w");
361 fprintf(stderr,
"generation requires at least two entries\n");
390 if(firstmetric>secondmetric){
391 float temp=firstmetric;
392 firstmetric=secondmetric;
400 if(thismetric<secondmetric){
401 if(thismetric<firstmetric){
402 secondmetric=firstmetric;
403 secondentry=firstentry;
404 firstmetric=thismetric;
407 secondmetric=thismetric;
416 float thismetric,localmetric;
417 float *nearbiasptr=nearbias+desired2*
j;
425 thismetric=secondmetric-localmetric;
428 thismetric=firstmetric-localmetric;
437 nearbiasptr[
k]=thismetric;
444 }
else if(thismetric>nearbiasptr[desired-1]){
445 nearbiasptr[
k]=thismetric;
460 float *nearbiasptr=nearbias+desired2*
i;
465 if(nearcount[i]>desired)
468 v->
bias[
i]=nearbiasptr[desired-1];
485 if(thismetric<firstmetric){
486 firstmetric=thismetric;
494 fprintf(cells,
"%g %g\n%g %g\n\n",
499 firstmetric-=v->
bias[
j];
500 meterror+=firstmetric;
506 vN(
new,j)[
k]+=ppt[
k];
507 if(firstmetric>v->
max[j])v->
max[
j]=firstmetric;
511 v->
max[
j]=firstmetric;
517 if(
vN(
new,j)[k]>ppt[k])
vN(
new,j)[
k]=ppt[
k];
518 if(
vN(new2,j)[k]<ppt[k])
vN(new2,j)[
k]=ppt[
k];
520 if(firstmetric>v->
max[firstentry])v->
max[
j]=firstmetric;
524 vN(new2,j)[
k]=ppt[
k];
526 v->
max[firstentry]=firstmetric;
535 fprintf(assig,
"%ld\n",v->
assigned[j]);
536 fprintf(bias,
"%g\n",v->
bias[j]);
550 asserror/=(v->
entries*fdesired);
552 fprintf(stderr,
"Pass #%d... ",v->
it);
553 fprintf(stderr,
": dist %g(%g) metric error=%g \n",
554 asserror,fdesired,meterror/v->
points);
GLuint const GLfloat * val
void _vqgen_seed(vqgen *v)
static float * _now(codebook *c, int i)
void vqgen_unquantize(vqgen *v, quant_meta *q)
GLboolean GLboolean GLboolean GLboolean a
GLuint GLuint GLfloat weight
float _float32_unpack(long val)
void vqgen_quantize(vqgen *v, quant_meta *q)
float _dist(vqgen *v, float *a, float *b)
void spinnit(char *s, int n)
long _float32_pack(float val)
void vqgen_init(vqgen *v, int elements, int aux, int entries, float mindist, float(*metric)(vqgen *, float *, float *), float *(*weight)(vqgen *, float *), int centroid)
float *(* weight_func)(struct vqgen *v, float *point)
float(* metric_func)(struct vqgen *v, float *entry, float *point)
float vqgen_iterate(vqgen *v, int biasp)
void vqgen_addpoint(vqgen *v, float *p, float *a)
GLdouble GLdouble GLdouble GLdouble q
int directdsort(const void *a, const void *b)
void vqgen_cellmetric(vqgen *v)
GLdouble GLdouble GLdouble b
static float * _point(vqgen *v, long ptr)
static int meshcomp(const void *a, const void *b)
void vqgen_sortmesh(vqgen *v)
float * _weight_null(vqgen *v, float *a)
void qsort(void *base, size_t nmemb, size_t size, int(*compare)(const void *, const void *))