********************************************************************
function: utility functions for loading .vqh and .vqd files
- last mod: $Id: bookutil.c,v 1.1 2000/01/05 10:14:54 xiphmont Exp $
+ last mod: $Id: bookutil.c,v 1.2 2000/01/05 15:04:55 xiphmont Exp $
********************************************************************/
int gotline=0;
while(!gotline){
- if(sofar>=lbufsize){
+ if(sofar+1>=lbufsize){
if(!lbufsize){
lbufsize=1024;
linebuffer=malloc(lbufsize);
********************************************************************
function: function call to do simple data cascading
- last mod: $Id: cascade.c,v 1.1 2000/01/05 10:14:55 xiphmont Exp $
+ last mod: $Id: cascade.c,v 1.2 2000/01/05 15:04:56 xiphmont Exp $
********************************************************************/
#include "bookutil.h"
+void process_preprocess(codebook *b,char *basename){
+}
+void process_postprocess(codebook *b,char *basename){
+}
+
void process_vector(codebook *b,double *a){
int entry=codebook_entry(b,a);
double *e=b->valuelist+b->dim*entry;
********************************************************************
function: generic euclidian distance metric for VQ codebooks
- last mod: $Id: genericdata.c,v 1.1 2000/01/05 10:14:55 xiphmont Exp $
+ last mod: $Id: genericdata.c,v 1.2 2000/01/05 15:04:57 xiphmont Exp $
********************************************************************/
double val=p[i]-e[i];
acc+=val*val;
}
- return acc;
+ return sqrt(acc/v->elements);
}
void vqext_addpoint_adj(vqgen *v,double *b,int start,int dim,int cols){
}
+
+
+
+
********************************************************************
function: metrics and quantization code for LSP VQ codebooks
- last mod: $Id: lspdata.c,v 1.7 1999/12/30 07:27:00 xiphmont Exp $
+ last mod: $Id: lspdata.c,v 1.8 2000/01/05 15:04:58 xiphmont Exp $
********************************************************************/
double val=(p[i]-e[i])*FUDGE;
acc+=val*val;
}
- return acc;
+ return sqrt(acc/v->elements);
}
/* Data files are line-vectors, starting with zero. If we want to
********************************************************************
function: utility main for loading and operating on codebooks
- last mod: $Id: run.c,v 1.4 2000/01/05 10:14:55 xiphmont Exp $
+ last mod: $Id: run.c,v 1.5 2000/01/05 15:04:59 xiphmont Exp $
********************************************************************/
*/
-extern void process_vector(codebook *b,double *a,char *basename);
+extern void process_preprocess(codebook *b,char *basename);
+extern void process_postprocess(codebook *b,char *basename);
+extern void process_vector(codebook *b,double *a);
extern void process_usage(void);
int main(int argc,char *argv[]){
dot=strchr(basename,'.');
if(dot)*dot='\0';
}
+
+ process_preprocess(b,basename);
while(*argv){
/* only input files */
reset_next_value();
while(get_vector(b,in,a)!=-1)
- process_vector(b,a,basename);
+ process_vector(b,a);
fclose(in);
}
if((S_IFIFO|S_IFREG|S_IFSOCK)&st.st_mode){
reset_next_value();
while(get_vector(b,stdin,a)!=-1)
- process_vector(b,a,basename);
+ process_vector(b,a);
}
}
+
+ process_postprocess(b,basename);
+
return 0;
}
********************************************************************
function: utility main for training codebooks
- last mod: $Id: train.c,v 1.12 2000/01/05 10:14:56 xiphmont Exp $
+ last mod: $Id: train.c,v 1.13 2000/01/05 15:05:00 xiphmont Exp $
********************************************************************/
}
{
int i;
- double *b=malloc(cols*sizeof(double));
+ double b[cols];
if(start*num+dim>cols){
fprintf(stderr,"ran out of columns reading %s\n",file);
exit(1);
for(i=0;i<num;i++)
vqext_addpoint_adj(&v,b,start+i*dim,dim,cols);
- free(b);
}
}
fclose(in);
********************************************************************
function: train a VQ codebook
- last mod: $Id: vqgen.c,v 1.26 2000/01/05 10:14:57 xiphmont Exp $
+ last mod: $Id: vqgen.c,v 1.27 2000/01/05 15:05:01 xiphmont Exp $
********************************************************************/
#define vN(data,i) (data+v->elements*i)
/* default metric; squared 'distance' from desired value. */
-double _dist_sq(vqgen *v,double *a, double *b){
+double _dist(vqgen *v,double *a, double *b){
int i;
int el=v->elements;
double acc=0.;
double val=(a[i]-b[i]);
acc+=val*val;
}
- return acc;
+ return sqrt(acc);
}
double *_weight_null(vqgen *v,double *a){
if(metric)
v->metric_func=metric;
else
- v->metric_func=_dist_sq;
+ v->metric_func=_dist;
if(weight)
v->weight_func=weight;
else
double *new=malloc(sizeof(double)*v->entries*v->elements);
long *nearcount=malloc(v->entries*sizeof(long));
double *nearbias=malloc(v->entries*desired2*sizeof(double));
+ #ifdef NOISY
+ char buff[80];
+ FILE *assig;
+ FILE *bias;
+ FILE *cells;
+ sprintf(buff,"cells%d.m",v->it);
+ cells=fopen(buff,"w");
+ sprintf(buff,"assig%d.m",v->it);
+ assig=fopen(buff,"w");
+ sprintf(buff,"bias%d.m",v->it);
+ bias=fopen(buff,"w");
+ #endif
+
if(v->entries<2){
fprintf(stderr,"generation requires at least two entries\n");
}
}
}
+
+ j=firstentry;
+#ifdef NOISY
+ fprintf(cells,"%g %g\n%g %g\n\n",
+ _now(v,j)[0],_now(v,j)[1],
+ ppt[0],ppt[1]);
+#endif
+
j=firstentry;
- meterror+=sqrt(_dist_sq(v,_now(v,j),ppt)/v->elements);
+ meterror+=firstmetric-v->bias[firstentry];
/* set up midpoints for next iter */
if(v->assigned[j]++)
for(k=0;k<v->elements;k++)
/* assign midpoints */
for(j=0;j<v->entries;j++){
+#ifdef NOISY
+ fprintf(assig,"%ld\n",v->assigned[j]);
+ fprintf(bias,"%g\n",v->bias[j]);
+#endif
asserror+=fabs(v->assigned[j]-fdesired);
if(v->assigned[j])
for(k=0;k<v->elements;k++)
********************************************************************
function: build a VQ codebook and the encoding decision 'tree'
- last mod: $Id: vqsplit.c,v 1.9 2000/01/05 10:14:59 xiphmont Exp $
+ last mod: $Id: vqsplit.c,v 1.10 2000/01/05 15:05:02 xiphmont Exp $
********************************************************************/
}
/* grab it from vqgen.c */
-extern double _dist_sq(vqgen *v,double *a, double *b);
+extern double _dist(vqgen *v,double *a, double *b);
/* goes through the split, but just counts it and returns a metric*/
void vqsp_count(vqgen *v,long *membership,
for(i=0;i<points;i++){
double *ppt=_point(v,pointindex[i]);
long firstentry=0;
- double firstmetric=_dist_sq(v,_now(v,entryindex[0]),ppt);
+ double firstmetric=_dist(v,_now(v,entryindex[0]),ppt);
if(points*entries>64*1024)spinnit(spinbuf,entries);
for(j=1;j<entries;j++){
- double thismetric=_dist_sq(v,_now(v,entryindex[j]),ppt);
+ double thismetric=_dist(v,_now(v,entryindex[j]),ppt);
if(thismetric<firstmetric){
firstmetric=thismetric;
firstentry=j;
for(j=0;j<entries;j++){
if(j!=i){
- double this=_dist_sq(v,q,_now(v,entryindex[j]));
+ double this=_dist(v,q,_now(v,entryindex[j]));
if(ref_j==-1 || this<ref_best){
ref_best=this;
ref_j=entryindex[j];
for(i=0;i<v->points;i++){
double *ppt=_point(v,i);
long firstentry=0;
- double firstmetric=_dist_sq(v,_now(v,0),ppt);
+ double firstmetric=_dist(v,_now(v,0),ppt);
for(j=1;j<v->entries;j++){
- double thismetric=_dist_sq(v,_now(v,j),ppt);
+ double thismetric=_dist(v,_now(v,j),ppt);
if(thismetric<firstmetric){
firstmetric=thismetric;
firstentry=j;