Main Page | Class List | Directories | File List | Class Members | File Members

vector.h File Reference

operation on Vector More...

#include <stdio.h>
#include <s3types.h>
#include <logmath.h>

Go to the source code of this file.

Classes

struct  arraysize_t
 wrapper of array size More...
struct  point_t
 wrapper of a point in integer More...
struct  fpoint_t
struct  vector_gautbl_t

Typedefs

typedef float32 * vector_t

Functions

void vector_floor (vector_t v, int32 dim, float64 f)
void vector_nz_floor (vector_t v, int32 dim, float64 f)
int32 vector_normalize (vector_t v, uint32 dim)
float64 vector_sum_norm (vector_t v, int32 dim)
S3DECODER_EXPORT void vector_print (FILE *fp, vector_t v, int32 dim)
S3DECODER_EXPORT int32 vector_is_zero (float32 *vec, int32 len)
int32 vector_is_nan (float32 *vec, int32 len)
int32 vector_maxcomp_int32 (int32 *val, int32 len)
int32 vector_mincomp_int32 (int32 *val, int32 len)
int32 vector_maxcomp_float32 (float32 *val, int32 len)
int32 vector_mincomp_float32 (float32 *val, int32 len)
void vector_accum (float32 *dst, float32 *src, int32 len)
int32 vector_cmp (float32 *v1, float32 *v2, int32 len)
int32 vector_mean (float32 *mean, float32 **data, int32 n_vec, int32 n_dim)
float64 vector_dist_eucl (float32 *v1, float32 *v2, int32 len)
float64 vector_maha_precomp (float32 *var, int32 len)
float64 vector_dist_maha (float32 *vec, float32 *mean, float32 *varinv, float64 norm, int32 len)
S3DECODER_EXPORT float64 vector_vqgen (float32 **data, int32 rows, int32 cols, int32 vqrows, float64 epsilon, int32 maxiter, float32 **mean, int32 *map, int32 seed)
int32 vector_vqlabel (float32 *vec, float32 **mean, int32 rows, int32 cols, float64 *sqerr)
float64 vector_pdf_entropy (float32 *p, int32 len)
float64 vector_pdf_cross_entropy (float32 *p1, float32 *p2, int32 len)
void vector_gautbl_alloc (vector_gautbl_t *gautbl, int32 n_gau, int32 veclen, logmath_t *logmath)
void vector_gautbl_free (vector_gautbl_t *gautbl)
void vector_gautbl_var_floor (vector_gautbl_t *gautbl, float64 floor)
void vector_gautbl_maha_precomp (vector_gautbl_t *gau)
void vector_gautbl_eval_logs3 (vector_gautbl_t *gau, int32 offset, int32 count, float32 *x, int32 *scr, logmath_t *logmath)


Detailed Description

operation on Vector


Typedef Documentation

typedef float32* vector_t
 


Function Documentation

void vector_accum float32 *  dst,
float32 *  src,
int32  len
 

Accumulate src into dst

Parameters:
dst  In/Out: dst[i] += src[i]
src  In: See above
len  In: Length of above vectors

int32 vector_cmp float32 *  v1,
float32 *  v2,
int32  len
 

Compare the two given vectors.

Returns:
-1, 0, or +1 depending on v1 <, =, or > v2 (as determined by the earliest unequal component).
Parameters:
v2  In: Vectors to be compared
len  In: Length of each vector

float64 vector_dist_eucl float32 *  v1,
float32 *  v2,
int32  len
 

Return the Euclidean distance (actually, distance^2) between the two given vectors.

Parameters:
v2  In: The two input vectors
len  In: Length of each vector

float64 vector_dist_maha float32 *  vec,
float32 *  mean,
float32 *  varinv,
float64  norm,
int32  len
 

Mahalanobis distance, using some precomputed portions of variance and determinant. (Actually not "distance" at all, but Gaussian density value.) Computed in log domain. Return value: logbase-e(likelihood value).

Parameters:
vec  In: Vector for which distance from mean being computed
mean  In: Mean vector
varinv  In: Variance vector, modified according to vector_maha_precomp()
norm  In: Normalization factor computed by vector_maha_precomp()
len  In: Length of each vector involved

void vector_floor vector_t  v,
int32  dim,
float64  f
 

Floor all elements of v[0..dim-1] to min value of f

Parameters:
v  The vector
dim  The dimension of the vector
f  The floor value

void vector_gautbl_alloc vector_gautbl_t gautbl,
int32  n_gau,
int32  veclen,
logmath_t *  logmath
 

The obvious allocation and free routines for vector_gautbl_t.{mean,var,lrd}. Also sets gautbl->{n_mgau, veclen, distfloor}; the last to the equivalent of S3_LOGPROB_ZERO.

void vector_gautbl_eval_logs3 vector_gautbl_t gau,
int32  offset,
int32  count,
float32 *  x,
int32 *  scr,
logmath_t *  logmath
 

Compare the input vector to the given range of subvector codewords in the given codebook, Enter the computed Mahalanobis distances, converted into logs3 values, into the given score array. (Why bother with the {offset,count} range?? For "blocking" such computation so that cache behaviour is improved.)

Parameters:
gau  In: Table of Gaussians
offset  In: First VQ codeword in the range to be evaluated
count  In: #Codewords to be evaluated (range size)
x  In: Input vector being compared to codewords
scr  Out: Mahalanobis distance scores (logs3 values). Caller must allocate this array. Note that only score[offset..offset+count-1] are updated.

void vector_gautbl_free vector_gautbl_t gautbl  ) 
 

void vector_gautbl_maha_precomp vector_gautbl_t gau  ) 
 

Carry out the vector_maha_precomp, above, over all the Gaussians in the given table, updating gau->lrd[] as a result. The needed memory must have been already allocated by the caller.

void vector_gautbl_var_floor vector_gautbl_t gautbl,
float64  floor
 

Floor all the variance values in the given Gaussians table.

Parameters:
gautbl  In/Out: Table to be updated
floor  In: Floor value

int32 vector_is_nan float32 *  vec,
int32  len
 

Return TRUE iff one of the component of the vector is nan

Parameters:
vec  In: Vector to be checked
len  In: Length of above vector

S3DECODER_EXPORT int32 vector_is_zero float32 *  vec,
int32  len
 

Return TRUE iff given vector is all 0.0

Parameters:
vec  In: Vector to be checked
len  In: Length of above vector

float64 vector_maha_precomp float32 *  var,
int32  len
 

Given a Gaussian density with mean vector m and diagonal variance vector v, and some input vector x, all of length n, the Mahalanobis distance of x from the Gaussian mean m is given by: {1/sqrt((2pi)^n * det(v))} * exp{-Sum((x[i] - m[i])^2 / (2v[i]))} To speed up this evaluation, the first sub-expression ({1/sqrt...}) can be precomputed at initialization, and so can 1/2v[i] in the second sub-expression. Secondly, recognition systems work with log-likelihood values, so these distances or likelihood values are computed in log-domain.

Carry out the above precomputations on the given variance vector; update var with 1/2var IN PLACE, and return the value of the first sub-expression as a log value. (The variance values are assumed to be strictly > 0.0.

Parameters:
var  In/Out: Variance vector, modified to 1/2var
len  In: Length of the above vector

int32 vector_maxcomp_float32 float32 *  val,
int32  len
 

int32 vector_maxcomp_int32 int32 *  val,
int32  len
 

Search for the max or min valued component in the given vector. The vector length must be strictly > 0 (val[] must have at least one valid value). If more than one component qualifies, the first one is chosen. Return value: the INDEX of the selected val[] component (not the value itself).

int32 vector_mean float32 *  mean,
float32 **  data,
int32  n_vec,
int32  n_dim
 

Compute the mean vector from the given set of vector data.

Returns:
: 0 if successful, -1 if any error (there shouldn't be any error).
Parameters:
mean  Out: Computed mean; caller should allocate this memory
data  In: Set of data over which mean is computed
n_vec  In: #Vectors in data
n_dim  In: Dimensionality of each vector (and mean)

int32 vector_mincomp_float32 float32 *  val,
int32  len
 

int32 vector_mincomp_int32 int32 *  val,
int32  len
 

int32 vector_normalize vector_t  v,
uint32  dim
 

Normalize the vector.

Parameters:
v  The vector
dim  The dimension of the vector

void vector_nz_floor vector_t  v,
int32  dim,
float64  f
 

Floor all non-0 elements of v[0..dim-1] to min value of f

float64 vector_pdf_cross_entropy float32 *  p1,
float32 *  p2,
int32  len
 

Return cross-entropy of two PDFs; like vector_entropy, but (-sum(p1 * log2(p2))). (The PDF values must be >= 0.0, of course.) The zero elements of p2 are skipped.

Parameters:
p2  In: Zero elements of p2 are skipped

float64 vector_pdf_entropy float32 *  p,
int32  len
 

Treat the given vector as a PDF and compute its entropy (-sum(p * log2(p))). (The PDF values must be >= 0.0, of course.) The zero elements of the PDF are skipped.

Parameters:
p  In: Vector (PDF) whose entropy is to be computed
len  In: Length of p[]

S3DECODER_EXPORT void vector_print FILE *  fp,
vector_t  v,
int32  dim
 

Print vector in one line, in 11.4e format, terminated by newline

float64 vector_sum_norm vector_t  v,
int32  dim
 

Normalize the elements of the given vector so that they sum to 1.0. If the sum is 0.0 to begin with, the vector is left untouched. @ The normalization factor.

S3DECODER_EXPORT float64 vector_vqgen float32 **  data,
int32  rows,
int32  cols,
int32  vqrows,
float64  epsilon,
int32  maxiter,
float32 **  mean,
int32 *  map,
int32  seed
 

Generate a vector quantized table for the input data, using the K-means algorithm, and the Euclidean distance measure. Return value: The squared quantization error of the final result.

Parameters:
data  In: Input Data to be quantized
rows  In: #Rows in input data
cols  In: #Cols in input data (and output VQ table)
vqrows  In: #Rows in vector quantized result
epsilon  In: Convergence limit; stop k-means iterations when the relative reduction in total squared error in successive iterations ((sqerr[t]-sqerr[t+1])/sqerr[t]) is below this value.
maxiter  In: Max #iterations, regardless of convlimit
mean  Out: Vector quantized array of centroids. Caller must allocate this array
map  Out: data->mean mapping; mean[map[i]] is the closest quantized vector corresponding to the input vector data[i]. Caller must allocate this array
seed  In : The seed for a random generator if it is smaller than 0, use the internal mechanism to generate seed. else use the seed to seed the random generator.

int32 vector_vqlabel float32 *  vec,
float32 **  mean,
int32  rows,
int32  cols,
float64 *  sqerr
 

Find the entry (row) of mean that is closest (according to Euclidean distance) to vec. Return value: index of the selected row.

Parameters:
vec  In: Vector to be compared against VQ table
mean  In: Table of centroids
rows  In: #Rows in mean
cols  In: #Cols in mean (and vec)
sqerr  Out: Squared error (distance) between vec and the selected codeword. May be NULL if not needed.


Generated on Sat Apr 11 00:02:30 2009 by  doxygen 1.3.9.1