|
Packit |
67cb25 |
/* movstat/gsl_movstat.h
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* Copyright (C) 2018 Patrick Alken
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* This program is free software; you can redistribute it and/or modify
|
|
Packit |
67cb25 |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
67cb25 |
* the Free Software Foundation; either version 3 of the License, or (at
|
|
Packit |
67cb25 |
* your option) any later version.
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* This program is distributed in the hope that it will be useful, but
|
|
Packit |
67cb25 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
67cb25 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
67cb25 |
* General Public License for more details.
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* You should have received a copy of the GNU General Public License
|
|
Packit |
67cb25 |
* along with this program; if not, write to the Free Software
|
|
Packit |
67cb25 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
#ifndef __GSL_MOVSTAT_H__
|
|
Packit |
67cb25 |
#define __GSL_MOVSTAT_H__
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
#include <gsl/gsl_math.h>
|
|
Packit |
67cb25 |
#include <gsl/gsl_vector.h>
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
#undef __BEGIN_DECLS
|
|
Packit |
67cb25 |
#undef __END_DECLS
|
|
Packit |
67cb25 |
#ifdef __cplusplus
|
|
Packit |
67cb25 |
# define __BEGIN_DECLS extern "C" {
|
|
Packit |
67cb25 |
# define __END_DECLS }
|
|
Packit |
67cb25 |
#else
|
|
Packit |
67cb25 |
# define __BEGIN_DECLS /* empty */
|
|
Packit |
67cb25 |
# define __END_DECLS /* empty */
|
|
Packit |
67cb25 |
#endif
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
__BEGIN_DECLS
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
typedef enum
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
GSL_MOVSTAT_END_PADZERO,
|
|
Packit |
67cb25 |
GSL_MOVSTAT_END_PADVALUE,
|
|
Packit |
67cb25 |
GSL_MOVSTAT_END_TRUNCATE
|
|
Packit |
67cb25 |
} gsl_movstat_end_t;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* accumulator struct
|
|
Packit |
67cb25 |
* size - return number of bytes needed for accumulator with maximum of n elements
|
|
Packit |
67cb25 |
* init - initialize accumulator state
|
|
Packit |
67cb25 |
* insert - insert a single sample into accumulator; if there are already n
|
|
Packit |
67cb25 |
* samples in accumulator, oldest sample is overwritten
|
|
Packit |
67cb25 |
* delete - delete oldest sample from accumulator
|
|
Packit |
67cb25 |
* get - return accumulated value
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
typedef struct
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
size_t (*size) (const size_t n);
|
|
Packit |
67cb25 |
int (*init) (const size_t n, void * vstate);
|
|
Packit |
67cb25 |
int (*insert) (const double x, void * vstate);
|
|
Packit |
67cb25 |
int (*delete) (void * vstate);
|
|
Packit |
67cb25 |
int (*get) (void * params, double * result, const void * vstate);
|
|
Packit |
67cb25 |
} gsl_movstat_accum;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
typedef struct
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
double (* function) (const size_t n, double x[], void * params);
|
|
Packit |
67cb25 |
void * params;
|
|
Packit |
67cb25 |
} gsl_movstat_function;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
#define GSL_MOVSTAT_FN_EVAL(F,n,x) (*((F)->function))((n),(x),(F)->params)
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* workspace for moving window statistics */
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
typedef struct
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
size_t H; /* number of previous samples in window */
|
|
Packit |
67cb25 |
size_t J; /* number of after samples in window */
|
|
Packit |
67cb25 |
size_t K; /* window size K = H + J + 1 */
|
|
Packit |
67cb25 |
double *work; /* workspace, size K */
|
|
Packit |
67cb25 |
void *state; /* state workspace for various accumulators */
|
|
Packit |
67cb25 |
size_t state_size; /* bytes allocated for 'state' */
|
|
Packit |
67cb25 |
} gsl_movstat_workspace;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* alloc.c */
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
gsl_movstat_workspace *gsl_movstat_alloc(const size_t K);
|
|
Packit |
67cb25 |
gsl_movstat_workspace *gsl_movstat_alloc2(const size_t H, const size_t J);
|
|
Packit |
67cb25 |
gsl_movstat_workspace *gsl_movstat_alloc_with_size(const size_t accum_state_size, const size_t H, const size_t J);
|
|
Packit |
67cb25 |
void gsl_movstat_free(gsl_movstat_workspace * w);
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* apply.c */
|
|
Packit |
67cb25 |
int gsl_movstat_apply_accum(const gsl_movstat_end_t endtype, const gsl_vector * x,
|
|
Packit |
67cb25 |
const gsl_movstat_accum * accum, void * accum_params,
|
|
Packit |
67cb25 |
gsl_vector * y, gsl_vector * z,
|
|
Packit |
67cb25 |
gsl_movstat_workspace * w);
|
|
Packit |
67cb25 |
int gsl_movstat_apply(const gsl_movstat_end_t endtype, const gsl_movstat_function * F,
|
|
Packit |
67cb25 |
const gsl_vector * x, gsl_vector * y, gsl_movstat_workspace * w);
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* fill.c */
|
|
Packit |
67cb25 |
size_t gsl_movstat_fill(const gsl_movstat_end_t endtype, const gsl_vector * x, const size_t idx,
|
|
Packit |
67cb25 |
const size_t H, const size_t J, double * window);
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
int gsl_movstat_mean(const gsl_movstat_end_t endtype, const gsl_vector * x, gsl_vector * y, gsl_movstat_workspace * w);
|
|
Packit |
67cb25 |
int gsl_movstat_variance(const gsl_movstat_end_t endtype, const gsl_vector * x, gsl_vector * y, gsl_movstat_workspace * w);
|
|
Packit |
67cb25 |
int gsl_movstat_sd(const gsl_movstat_end_t endtype, const gsl_vector * x, gsl_vector * y, gsl_movstat_workspace * w);
|
|
Packit |
67cb25 |
int gsl_movstat_median(const gsl_movstat_end_t endtype, const gsl_vector * x, gsl_vector * y, gsl_movstat_workspace * w);
|
|
Packit |
67cb25 |
int gsl_movstat_min(const gsl_movstat_end_t endtype, const gsl_vector * x, gsl_vector * y, gsl_movstat_workspace * w);
|
|
Packit |
67cb25 |
int gsl_movstat_max(const gsl_movstat_end_t endtype, const gsl_vector * x, gsl_vector * y, gsl_movstat_workspace * w);
|
|
Packit |
67cb25 |
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);
|
|
Packit |
67cb25 |
int gsl_movstat_mad0(const gsl_movstat_end_t endtype, const gsl_vector * x, gsl_vector * xmedian,
|
|
Packit |
67cb25 |
gsl_vector * xmad, gsl_movstat_workspace * w);
|
|
Packit |
67cb25 |
int gsl_movstat_mad(const gsl_movstat_end_t endtype, const gsl_vector * x, gsl_vector * xmedian,
|
|
Packit |
67cb25 |
gsl_vector * xmad, gsl_movstat_workspace * w);
|
|
Packit |
67cb25 |
int gsl_movstat_qqr(const gsl_movstat_end_t endtype, const gsl_vector * x, const double q,
|
|
Packit |
67cb25 |
gsl_vector * xqqr, gsl_movstat_workspace * w);
|
|
Packit |
67cb25 |
int gsl_movstat_Sn(const gsl_movstat_end_t endtype, const gsl_vector * x,
|
|
Packit |
67cb25 |
gsl_vector * xscale, gsl_movstat_workspace * w);
|
|
Packit |
67cb25 |
int gsl_movstat_Qn(const gsl_movstat_end_t endtype, const gsl_vector * x,
|
|
Packit |
67cb25 |
gsl_vector * xscale, gsl_movstat_workspace * w);
|
|
Packit |
67cb25 |
int gsl_movstat_sum(const gsl_movstat_end_t endtype, const gsl_vector * x, gsl_vector * y, gsl_movstat_workspace * w);
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* accumulator variables */
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_mad;
|
|
Packit |
67cb25 |
GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_max;
|
|
Packit |
67cb25 |
GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_mean;
|
|
Packit |
67cb25 |
GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_median;
|
|
Packit |
67cb25 |
GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_min;
|
|
Packit |
67cb25 |
GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_minmax;
|
|
Packit |
67cb25 |
GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_sd;
|
|
Packit |
67cb25 |
GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_Sn;
|
|
Packit |
67cb25 |
GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_sum;
|
|
Packit |
67cb25 |
GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_Qn;
|
|
Packit |
67cb25 |
GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_qqr;
|
|
Packit |
67cb25 |
GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_userfunc;
|
|
Packit |
67cb25 |
GSL_VAR const gsl_movstat_accum * gsl_movstat_accum_variance;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
__END_DECLS
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
#endif /* __GSL_MOVSTAT_H__ */
|