Lines Matching refs:v
57 #define vN(data,i) (data+v->elements*i)
60 float _dist(vqgen *v,float *a, float *b){ in _dist() argument
62 int el=v->elements; in _dist()
71 float *_weight_null(vqgen *v,float *a){ in _weight_null() argument
76 void _vqgen_seed(vqgen *v){ in _vqgen_seed() argument
78 for(i=0;i<v->entries;i++) in _vqgen_seed()
79 memcpy(_now(v,i),_point(v,i),sizeof(float)*v->elements); in _vqgen_seed()
80 v->seeded=1; in _vqgen_seed()
89 void vqgen_cellmetric(vqgen *v){ in vqgen_cellmetric() argument
96 float spacings[v->entries]; in vqgen_cellmetric()
99 sprintf(buff,"cellspace%d.m",v->it); in vqgen_cellmetric()
104 for(j=0;j<v->entries;j++){ in vqgen_cellmetric()
107 for(k=0;k<v->entries;k++){ in vqgen_cellmetric()
109 float this=_dist(v,_now(v,j),_now(v,k)); in vqgen_cellmetric()
111 if(v->assigned[k] && (localmin==-1 || this<localmin)) in vqgen_cellmetric()
121 if(k<v->entries)continue; in vqgen_cellmetric()
123 if(v->assigned[j]==0){ in vqgen_cellmetric()
128 localmin=v->max[j]+localmin/2; /* this gives us rough diameter */ in vqgen_cellmetric()
165 void vqgen_quantize(vqgen *v,quant_meta *q){ in vqgen_quantize() argument
175 mindel=maxdel=_now(v,0)[0]; in vqgen_quantize()
177 for(j=0;j<v->entries;j++){ in vqgen_quantize()
179 for(k=0;k<v->elements;k++){ in vqgen_quantize()
180 if(mindel>_now(v,j)[k]-last)mindel=_now(v,j)[k]-last; in vqgen_quantize()
181 if(maxdel<_now(v,j)[k]-last)maxdel=_now(v,j)[k]-last; in vqgen_quantize()
182 if(q->sequencep)last=_now(v,j)[k]; in vqgen_quantize()
199 for(j=0;j<v->entries;j++){ in vqgen_quantize()
201 for(k=0;k<v->elements;k++){ in vqgen_quantize()
202 float val=_now(v,j)[k]; in vqgen_quantize()
205 _now(v,j)[k]=now; in vqgen_quantize() local
224 void vqgen_unquantize(vqgen *v,quant_meta *q){ in vqgen_unquantize() argument
229 for(j=0;j<v->entries;j++){ in vqgen_unquantize()
231 for(k=0;k<v->elements;k++){ in vqgen_unquantize()
232 float now=_now(v,j)[k]; in vqgen_unquantize()
235 _now(v,j)[k]=now; in vqgen_unquantize() local
240 void vqgen_init(vqgen *v,int elements,int aux,int entries,float mindist, in vqgen_init() argument
243 memset(v,0,sizeof(vqgen)); in vqgen_init()
245 v->centroid=centroid; in vqgen_init()
246 v->elements=elements; in vqgen_init()
247 v->aux=aux; in vqgen_init()
248 v->mindist=mindist; in vqgen_init()
249 v->allocated=32768; in vqgen_init()
250 v->pointlist=_ogg_malloc(v->allocated*(v->elements+v->aux)*sizeof(float)); in vqgen_init()
252 v->entries=entries; in vqgen_init()
253 v->entrylist=_ogg_malloc(v->entries*v->elements*sizeof(float)); in vqgen_init()
254 v->assigned=_ogg_malloc(v->entries*sizeof(long)); in vqgen_init()
255 v->bias=_ogg_calloc(v->entries,sizeof(float)); in vqgen_init()
256 v->max=_ogg_calloc(v->entries,sizeof(float)); in vqgen_init()
258 v->metric_func=metric; in vqgen_init()
260 v->metric_func=_dist; in vqgen_init()
262 v->weight_func=weight; in vqgen_init()
264 v->weight_func=_weight_null; in vqgen_init()
266 v->asciipoints=tmpfile(); in vqgen_init()
270 void vqgen_addpoint(vqgen *v, float *p,float *a){ in vqgen_addpoint() argument
272 for(k=0;k<v->elements;k++) in vqgen_addpoint()
273 fprintf(v->asciipoints,"%.12g\n",p[k]); in vqgen_addpoint()
274 for(k=0;k<v->aux;k++) in vqgen_addpoint()
275 fprintf(v->asciipoints,"%.12g\n",a[k]); in vqgen_addpoint()
277 if(v->points>=v->allocated){ in vqgen_addpoint()
278 v->allocated*=2; in vqgen_addpoint()
279 v->pointlist=_ogg_realloc(v->pointlist,v->allocated*(v->elements+v->aux)* in vqgen_addpoint()
283 memcpy(_point(v,v->points),p,sizeof(float)*v->elements); in vqgen_addpoint()
284 if(v->aux)memcpy(_point(v,v->points)+v->elements,a,sizeof(float)*v->aux); in vqgen_addpoint()
287 if(v->mindist>0.f){ in vqgen_addpoint()
289 for(k=0;k<v->elements+v->aux;k++) in vqgen_addpoint()
290 _point(v,v->points)[k]= in vqgen_addpoint() local
291 rint(_point(v,v->points)[k]/v->mindist)*v->mindist; in vqgen_addpoint()
293 v->points++; in vqgen_addpoint()
294 if(!(v->points&0xff))spinnit("loading... ",v->points); in vqgen_addpoint()
305 void vqgen_sortmesh(vqgen *v){ in vqgen_sortmesh() argument
307 if(v->mindist>0.f){ in vqgen_sortmesh()
311 sortsize=(v->elements+v->aux)*sizeof(float); in vqgen_sortmesh()
312 qsort(v->pointlist,v->points,sortsize,meshcomp); in vqgen_sortmesh()
315 for(i=1;i<v->points;i++){ in vqgen_sortmesh()
316 if(memcmp(_point(v,i),_point(v,i-1),sortsize)){ in vqgen_sortmesh()
318 if(i>march)memcpy(_point(v,march),_point(v,i),sortsize); in vqgen_sortmesh()
321 spinnit("eliminating density... ",v->points-i); in vqgen_sortmesh()
326 " after density mesh (%ld%%)\n",march,v->points,march*100/v->points); in vqgen_sortmesh()
327 v->points=march; in vqgen_sortmesh()
330 v->sorted=1; in vqgen_sortmesh()
333 float vqgen_iterate(vqgen *v,int biasp){ in vqgen_iterate() argument
351 sprintf(buff,"cells%d.m",v->it); in vqgen_iterate()
353 sprintf(buff,"assig%d.m",v->it); in vqgen_iterate()
355 sprintf(buff,"bias%d.m",v->it); in vqgen_iterate()
360 if(v->entries<2){ in vqgen_iterate()
365 if(!v->sorted)vqgen_sortmesh(v); in vqgen_iterate()
366 if(!v->seeded)_vqgen_seed(v); in vqgen_iterate()
368 fdesired=(float)v->points/v->entries; in vqgen_iterate()
371 new=_ogg_malloc(sizeof(float)*v->entries*v->elements); in vqgen_iterate()
372 new2=_ogg_malloc(sizeof(float)*v->entries*v->elements); in vqgen_iterate()
373 nearcount=_ogg_malloc(v->entries*sizeof(long)); in vqgen_iterate()
374 nearbias=_ogg_malloc(v->entries*desired2*sizeof(float)); in vqgen_iterate()
378 memset(nearcount,0,sizeof(long)*v->entries); in vqgen_iterate()
379 memset(v->assigned,0,sizeof(long)*v->entries); in vqgen_iterate()
381 for(i=0;i<v->points;i++){ in vqgen_iterate()
382 float *ppt=v->weight_func(v,_point(v,i)); in vqgen_iterate()
383 float firstmetric=v->metric_func(v,_now(v,0),ppt)+v->bias[0]; in vqgen_iterate()
384 float secondmetric=v->metric_func(v,_now(v,1),ppt)+v->bias[1]; in vqgen_iterate()
388 if(!(i&0xff))spinnit("biasing... ",v->points+v->points+v->entries-i); in vqgen_iterate()
398 for(j=2;j<v->entries;j++){ in vqgen_iterate()
399 float thismetric=v->metric_func(v,_now(v,j),ppt)+v->bias[j]; in vqgen_iterate()
414 for(j=0;j<v->entries;j++){ in vqgen_iterate()
420 localmetric=v->metric_func(v,_now(v,j),ppt); in vqgen_iterate()
440 spinnit("biasing... ",v->points+v->points+v->entries-i); in vqgen_iterate()
448 spinnit("biasing... ",v->points+v->points+v->entries-i); in vqgen_iterate()
459 for(i=0;i<v->entries;i++){ in vqgen_iterate()
462 spinnit("biasing... ",v->points+v->entries-i); in vqgen_iterate()
468 v->bias[i]=nearbiasptr[desired-1]; in vqgen_iterate()
472 memset(v->bias,0,v->entries*sizeof(float)); in vqgen_iterate()
476 for(i=0;i<v->points;i++){ in vqgen_iterate()
477 float *ppt=v->weight_func(v,_point(v,i)); in vqgen_iterate()
478 float firstmetric=v->metric_func(v,_now(v,0),ppt)+v->bias[0]; in vqgen_iterate()
481 if(!(i&0xff))spinnit("centering... ",v->points-i); in vqgen_iterate()
483 for(j=0;j<v->entries;j++){ in vqgen_iterate()
484 float thismetric=v->metric_func(v,_now(v,j),ppt)+v->bias[j]; in vqgen_iterate()
495 _now(v,j)[0],_now(v,j)[1], in vqgen_iterate()
499 firstmetric-=v->bias[j]; in vqgen_iterate()
502 if(v->centroid==0){ in vqgen_iterate()
504 if(v->assigned[j]++){ in vqgen_iterate()
505 for(k=0;k<v->elements;k++) in vqgen_iterate()
507 if(firstmetric>v->max[j])v->max[j]=firstmetric; in vqgen_iterate()
509 for(k=0;k<v->elements;k++) in vqgen_iterate()
511 v->max[j]=firstmetric; in vqgen_iterate()
515 if(v->assigned[j]++){ in vqgen_iterate()
516 for(k=0;k<v->elements;k++){ in vqgen_iterate()
520 if(firstmetric>v->max[firstentry])v->max[j]=firstmetric; in vqgen_iterate()
522 for(k=0;k<v->elements;k++){ in vqgen_iterate()
526 v->max[firstentry]=firstmetric; in vqgen_iterate()
533 for(j=0;j<v->entries;j++){ in vqgen_iterate()
535 fprintf(assig,"%ld\n",v->assigned[j]); in vqgen_iterate()
536 fprintf(bias,"%g\n",v->bias[j]); in vqgen_iterate()
538 asserror+=fabs(v->assigned[j]-fdesired); in vqgen_iterate()
539 if(v->assigned[j]){ in vqgen_iterate()
540 if(v->centroid==0){ in vqgen_iterate()
541 for(k=0;k<v->elements;k++) in vqgen_iterate()
542 _now(v,j)[k]=vN(new,j)[k]/v->assigned[j]; in vqgen_iterate() local
544 for(k=0;k<v->elements;k++) in vqgen_iterate()
545 _now(v,j)[k]=(vN(new,j)[k]+vN(new2,j)[k])/2.f; in vqgen_iterate() local
550 asserror/=(v->entries*fdesired); in vqgen_iterate()
552 fprintf(stderr,"Pass #%d... ",v->it); in vqgen_iterate()
554 asserror,fdesired,meterror/v->points); in vqgen_iterate()
555 v->it++; in vqgen_iterate()