/* Miscellaneous functions and procedures */ /* Last edited on 2007-12-27 01:15:19 by stolfi */ #ifndef pz_proc_H #define pz_proc_H #include int pz_round ( double x ); /* Rounds {x} to the nearest integer; ties are broken by rounding-to-even. */ double fmax ( double x, double y ); double fmin ( double x, double y ); /* Returns maximum and minimum, respectively, of the arguments. */ void pz_reduce_to_period ( double *t, /* IO */ double tLo, double tHi, int *k /* OUT */ ); /* Reduces {*t} to the range {[tLo _ tHi)} by adding to it some integer multiple {kk} of {tHi - tLo}. Returns {kk} in {*k}. */ double pz_squeeze ( double x, double sigma ); /* Maps a variable {x} that has Gaussian distribution with mean zero and deviation {sigma} to a variable that is uniformly distributed n {[-1..+1]}. */ double pz_stretch ( double x, double sigma ); /* The functional inverse of {pz_squeeze}. */ double pz_old_squeeze ( double x, double epsilon, double delta ); /* Returns the {significant} value of {x} assuming it is contaminated by noise of absolute magnitude {epsilon} and relative magnitude {delta}. I.e. the result is approximately {x/epsilon} when {abs(x)} is small, and approximately {SGN(x)*log(abs(x))/delta} when {abs(x)} is large */ double pz_old_stretch ( double x, double epsilon, double delta ); /* The functional inverse of {pz_old_squeeze}. */ double pz_interpolate ( double t, double t0, double p0, double t1, double p1 ); /* Interpolates linearly the value at time {t} between values {p0} and {p1}, assuming they have times {t0} and {t1}. */ double pz_cubic_interpolate ( double t, double t0, double p0, double t1, double p1, double t2, double p2, double t3, double p3 ); /* Interpolates cubically some function at time {t}, assuming it has values {p0,..p3} at times {t0,..t3}. */ bool_vec_t pz_select_all( unsigned n ); /* Returns a vector of {n} booleans, all TRUE. */ double pz_adjust_unit ( double givenUnit, double dev, double big ); /* Adjusts the {givenUnit} for quantization of a variable whose standard deviation is {dev} and whose values range in {[-big..+big]}. Will increase {givenUnit} if needed to avoid overflow, or decrease it to ensure quantization errors less than dev*10^-6. In any case, if {givenUnit} is changed, or no good unit was found, also prints a warning to {stderr}. */ void pz_sort_ok ( int_vec_t *x, bool_vec_t *ok ); /* Returns in {x} a permutation of the indices of {ok} that all elements {x[k]} with {ok[x[i]] == TRUE} are at the beginning. */ /* Copyright © 2001 Universidade Estadual de Campinas (UNICAMP). Authors: Helena C. G. Leitão and Jorge Stolfi. This file can be freely distributed, used, and modified, provided that this copyright and authorship notice is preserved, and that any modified versions are clearly marked as such. This software has NO WARRANTY of correctness or applicability for any purpose. Neither the authors nor their employers chall be held responsible for any losses or damages that may result from its use. */ #endif