Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:03:51

0001 /* movstat/gsl_movstat.h
0002  * 
0003  * Copyright (C) 2018 Patrick Alken
0004  * 
0005  * This program is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation; either version 3 of the License, or (at
0008  * your option) any later version.
0009  * 
0010  * This program is distributed in the hope that it will be useful, but
0011  * WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * General Public License for more details.
0014  * 
0015  * You should have received a copy of the GNU General Public License
0016  * along with this program; if not, write to the Free Software
0017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0018  */
0019 
0020 #ifndef __GSL_MOVSTAT_H__
0021 #define __GSL_MOVSTAT_H__
0022 
0023 #include <gsl/gsl_math.h>
0024 #include <gsl/gsl_vector.h>
0025 
0026 #undef __BEGIN_DECLS
0027 #undef __END_DECLS
0028 #ifdef __cplusplus
0029 # define __BEGIN_DECLS extern "C" {
0030 # define __END_DECLS }
0031 #else
0032 # define __BEGIN_DECLS /* empty */
0033 # define __END_DECLS /* empty */
0034 #endif
0035 
0036 __BEGIN_DECLS
0037 
0038 typedef enum
0039 {
0040   GSL_MOVSTAT_END_PADZERO,
0041   GSL_MOVSTAT_END_PADVALUE,
0042   GSL_MOVSTAT_END_TRUNCATE
0043 } gsl_movstat_end_t;
0044 
0045 /* accumulator struct
0046  * size          - return number of bytes needed for accumulator with maximum of n elements
0047  * init          - initialize accumulator state
0048  * insert        - insert a single sample into accumulator; if there are already n
0049  *                 samples in accumulator, oldest sample is overwritten
0050  * delete_oldest - delete oldest sample from accumulator
0051  * get           - return accumulated value
0052  */
0053 typedef struct
0054 {
0055   size_t (*size) (const size_t n);
0056   int (*init) (const size_t n, void * vstate);
0057   int (*insert) (const double x, void * vstate);
0058   int (*delete_oldest) (void * vstate);
0059   int (*get) (void * params, double * result, const void * vstate);
0060 } gsl_movstat_accum;
0061 
0062 typedef struct
0063 {
0064   double (* function) (const size_t n, double x[], void * params);
0065   void * params;
0066 } gsl_movstat_function;
0067 
0068 #define GSL_MOVSTAT_FN_EVAL(F,n,x) (*((F)->function))((n),(x),(F)->params)
0069 
0070 /* workspace for moving window statistics */
0071 
0072 typedef struct
0073 {
0074   size_t H;          /* number of previous samples in window */
0075   size_t J;          /* number of after samples in window */
0076   size_t K;          /* window size K = H + J + 1 */
0077   double *work;      /* workspace, size K */
0078   void *state;       /* state workspace for various accumulators */
0079   size_t state_size; /* bytes allocated for 'state' */
0080 } gsl_movstat_workspace;
0081 
0082 /* alloc.c */
0083 
0084 gsl_movstat_workspace *gsl_movstat_alloc(const size_t K);
0085 gsl_movstat_workspace *gsl_movstat_alloc2(const size_t H, const size_t J);
0086 gsl_movstat_workspace *gsl_movstat_alloc_with_size(const size_t accum_state_size, const size_t H, const size_t J);
0087 void gsl_movstat_free(gsl_movstat_workspace * w);
0088 
0089 /* apply.c */
0090 int gsl_movstat_apply_accum(const gsl_movstat_end_t endtype, const gsl_vector * x,
0091                             const gsl_movstat_accum * accum, void * accum_params,
0092                             gsl_vector * y, gsl_vector * z,
0093                             gsl_movstat_workspace * w);
0094 int gsl_movstat_apply(const gsl_movstat_end_t endtype, const gsl_movstat_function * F,
0095                       const gsl_vector * x, gsl_vector * y, gsl_movstat_workspace * w);
0096 
0097 /* fill.c */
0098 size_t gsl_movstat_fill(const gsl_movstat_end_t endtype, const gsl_vector * x, const size_t idx,
0099                         const size_t H, const size_t J, double * window);
0100 
0101 int gsl_movstat_mean(const gsl_movstat_end_t endtype, const gsl_vector * x, gsl_vector * y, gsl_movstat_workspace * w);
0102 int gsl_movstat_variance(const gsl_movstat_end_t endtype, const gsl_vector * x, gsl_vector * y, gsl_movstat_workspace * w);
0103 int gsl_movstat_sd(const gsl_movstat_end_t endtype, const gsl_vector * x, gsl_vector * y, gsl_movstat_workspace * w);
0104 int gsl_movstat_median(const gsl_movstat_end_t endtype, const gsl_vector * x, gsl_vector * y, gsl_movstat_workspace * w);
0105 int gsl_movstat_min(const gsl_movstat_end_t endtype, const gsl_vector * x, gsl_vector * y, gsl_movstat_workspace * w);
0106 int gsl_movstat_max(const gsl_movstat_end_t endtype, const gsl_vector * x, gsl_vector * y, gsl_movstat_workspace * w);
0107 int gsl_movstat_minmax(const gsl_movstat_end_t endtype, const gsl_vector * x, gsl_vector * y_min, gsl_vector * y_max, gsl_movstat_workspace * w);
0108 int gsl_movstat_mad0(const gsl_movstat_end_t endtype, const gsl_vector * x, gsl_vector * xmedian,
0109                      gsl_vector * xmad, gsl_movstat_workspace * w);
0110 int gsl_movstat_mad(const gsl_movstat_end_t endtype, const gsl_vector * x, gsl_vector * xmedian,
0111                     gsl_vector * xmad, gsl_movstat_workspace * w);
0112 int gsl_movstat_qqr(const gsl_movstat_end_t endtype, const gsl_vector * x, const double q,
0113                     gsl_vector * xqqr, gsl_movstat_workspace * w);
0114 int gsl_movstat_Sn(const gsl_movstat_end_t endtype, const gsl_vector * x,
0115                    gsl_vector * xscale, gsl_movstat_workspace * w);
0116 int gsl_movstat_Qn(const gsl_movstat_end_t endtype, const gsl_vector * x,
0117                    gsl_vector * xscale, gsl_movstat_workspace * w);
0118 int gsl_movstat_sum(const gsl_movstat_end_t endtype, const gsl_vector * x, gsl_vector * y, gsl_movstat_workspace * w);
0119 
0120 /* accumulator variables */
0121 
0122 GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_mad;
0123 GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_max;
0124 GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_mean;
0125 GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_median;
0126 GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_min;
0127 GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_minmax;
0128 GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_sd;
0129 GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_Sn;
0130 GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_sum;
0131 GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_Qn;
0132 GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_qqr;
0133 GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_userfunc;
0134 GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_variance;
0135 
0136 __END_DECLS
0137 
0138 #endif /* __GSL_MOVSTAT_H__ */