Classes | Typedefs | Functions
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:
dstIn/Out: dst[i] += src[i]
srcIn: See above
lenIn: 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:
v2In: Vectors to be compared
lenIn: 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:
v2In: The two input vectors
lenIn: 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:
vecIn: Vector for which distance from mean being computed
meanIn: Mean vector
varinvIn: Variance vector, modified according to vector_maha_precomp()
normIn: Normalization factor computed by vector_maha_precomp()
lenIn: Length of each vector involved
void vector_floor ( vector_t  v,
int32  dim,
float64  f 
)

The reason for some of the "trivial" routines below is that they could be OPTIMIZED for SPEED at some point. Floor all elements of v[0..dim-1] to min value of f

Parameters:
vThe vector
dimThe dimension of the vector
fThe 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:
gauIn: Table of Gaussians
offsetIn: First VQ codeword in the range to be evaluated
countIn: #Codewords to be evaluated (range size)
xIn: Input vector being compared to codewords
scrOut: 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)

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:
gautblIn/Out: Table to be updated
floorIn: Floor value
int32 vector_is_nan ( float32 *  vec,
int32  len 
)

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

Parameters:
vecIn: Vector to be checked
lenIn: Length of above vector
S3DECODER_EXPORT int32 vector_is_zero ( float32 *  vec,
int32  len 
)

Return TRUE iff given vector is all 0.0

Parameters:
vecIn: Vector to be checked
lenIn: Length of above vector

Referenced by main(), and mgau_var_nzvec_floor().

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:
varIn/Out: Variance vector, modified to 1/2var
lenIn: 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:
meanOut: Computed mean; caller should allocate this memory
dataIn: Set of data over which mean is computed
n_vecIn: #Vectors in data
n_dimIn: 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:
vThe vector
dimThe 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:
p2In: 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:
pIn: Vector (PDF) whose entropy is to be computed
lenIn: 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

Referenced by main().

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:
dataIn: Input Data to be quantized
rowsIn: #Rows in input data
colsIn: #Cols in input data (and output VQ table)
vqrowsIn: #Rows in vector quantized result
epsilonIn: 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.
maxiterIn: Max #iterations, regardless of convlimit
meanOut: Vector quantized array of centroids. Caller must allocate this array
mapOut: data->mean mapping; mean[map[i]] is the closest quantized vector corresponding to the input vector data[i]. Caller must allocate this array
seedIn : 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.

Referenced by main().

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:
vecIn: Vector to be compared against VQ table
meanIn: Table of centroids
rowsIn: #Rows in mean
colsIn: #Cols in mean (and vec)
sqerrOut: Squared error (distance) between vec and the selected codeword. May be NULL if not needed.