pspp-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pspp-cvs] experimental/src/math/ts acf.h arma-optimizer.h...


From: Jason H Stover
Subject: [Pspp-cvs] experimental/src/math/ts acf.h arma-optimizer.h...
Date: Wed, 24 Jan 2007 17:28:43 +0000

CVSROOT:        /sources/pspp
Module name:    experimental
Changes by:     Jason H Stover <jstover>        07/01/24 17:28:43

Added files:
        src/math/ts    : acf.h arma-optimizer.h arma.h innovations.h 
                         ts-coefficient.h 

Log message:
        initial version

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/experimental/src/math/ts/acf.h?cvsroot=pspp&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/experimental/src/math/ts/arma-optimizer.h?cvsroot=pspp&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/experimental/src/math/ts/arma.h?cvsroot=pspp&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/experimental/src/math/ts/innovations.h?cvsroot=pspp&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/experimental/src/math/ts/ts-coefficient.h?cvsroot=pspp&rev=1.1

Patches:
Index: acf.h
===================================================================
RCS file: acf.h
diff -N acf.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ acf.h       24 Jan 2007 17:28:43 -0000      1.1
@@ -0,0 +1,42 @@
+/*
+  src/math/ts/acf.h
+  
+  Copyright (C) 2006 Free Software Foundation, Inc. Written by Jason H. Stover.
+  
+  This program is free software; you can redistribute it and/or modify it under
+  the terms of the GNU General Public License as published by the Free
+  Software Foundation; either version 2 of the License, or (at your option)
+  any later version.
+  
+  This program is distributed in the hope that it will be useful, but WITHOUT
+  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+  more details.
+  
+  You should have received a copy of the GNU General Public License along with
+  this program; if not, write to the Free Software Foundation, Inc., 51
+  Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
+ */
+#ifndef ACF_H
+#define ACF_H
+#include <gsl/gsl_math.h>
+#include <gsl/gsl_linalg.h>
+#include <stdlib.h>
+#include <libpspp/alloc.h>
+#include <libpspp/compiler.h>
+#include <math/ts/arma-optimizer.h>
+#include <math/ts/arma.h>
+/*
+  Find the coefficients for the infinite-order MA process.
+ */
+gsl_vector * pspp_ts_get_inf_ma_coef (pspp_arma *);
+void get_matrix_elements (gsl_matrix *, const pspp_arma *);
+void set_inf_ma_coef (struct pspp_arma_state *);
+void pspp_acf_vector (struct pspp_arma_state *);
+double d_reparam_acf_d_ar (struct pspp_arma_state *, int, 
+                          int, int);
+double get_next_acf (pspp_arma *, gsl_vector *);
+void copy_acf (pspp_arma *, gsl_vector *);
+double d_reparam_acf_d_ma (struct pspp_arma_state *, int, 
+                          int, int);
+#endif

Index: arma-optimizer.h
===================================================================
RCS file: arma-optimizer.h
diff -N arma-optimizer.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ arma-optimizer.h    24 Jan 2007 17:28:43 -0000      1.1
@@ -0,0 +1,79 @@
+/*
+  src/math/ts/arma.h
+  
+  Copyright (C) 2006 Free Software Foundation, Inc. Written by Jason H. Stover.
+  
+  This program is free software; you can redistribute it and/or modify it under
+  the terms of the GNU General Public License as published by the Free
+  Software Foundation; either version 2 of the License, or (at your option)
+  any later version.
+  
+  This program is distributed in the hope that it will be useful, but WITHOUT
+  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+  more details.
+  
+  You should have received a copy of the GNU General Public License along with
+  this program; if not, write to the Free Software Foundation, Inc., 51
+  Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
+ */
+#ifndef ARMA_OPTIMIZER_H
+#define ARMA_OPTIMIZER_H
+#include "arma.h"
+#include <stdbool.h>
+#include <gsl/gsl_math.h>
+#include <gsl/gsl_vector.h>
+#include <gsl/gsl_matrix.h>
+
+/*
+  Structure for storing information relevant to
+  the estimation of the ARMA parameters, including
+  the infinite-order moving average representation
+  and its gradients.
+ */
+struct pspp_arma_state
+{
+  gsl_vector *inf_ma_coeff; /* Coefficients from the infinite-oreder
+                              representation of the ARMA process. 
+                           */
+  gsl_matrix *d_inf_ma_d_ar; /* Gradient of the infinite-order
+                               moving average with respect to
+                               the autoregressive parameters.
+                               Element i,j contains the partial derivative
+                               of the ith coefficient with respect to the
+                               jth autoregressive parameter.
+                            */
+  gsl_matrix *d_inf_ma_d_ma; /* Gradient of the infinite-order
+                               moving average with respect to
+                               the moving average parameters.
+                               Element i,j contains the partial derivative
+                               of the ith coefficient with respect to the
+                               jth moving average parameter.
+                            */
+  gsl_matrix *d_acf_d_phi; /* Partial derivatives of the autocovarince
+                             function with respect to the
+                             autregressive parameter. Row i contains
+                             the partial derivatives of the acf with
+                             respect to the ith parameter.
+                           */
+  gsl_matrix *d_acf_d_ma; /* Partial derivatives of the autocovarince
+                            function with respect to the
+                            moving average parameter. Row i contains
+                            the partial derivatives of the acf with
+                            respect to the ith parameter.
+                         */
+  struct innovations_estimate *in; /* This should be the reparameterized
+                                     innovations estimate used during fitting.
+                                  */
+  gsl_vector *residuals;
+  gsl_vector *data;
+  pspp_arma *arma;
+  gsl_vector *scale;
+};
+void pspp_arma_likelihood_gradient (struct pspp_arma_state *, gsl_vector *);
+double pspp_arma_log_likelihood (const gsl_vector *, struct 
innovations_estimate *);
+void pspp_d_acf_d_ar (struct pspp_arma_state *);
+void pspp_d_acf_d_ma (struct pspp_arma_state *);
+void set_d_psi_d_ar (struct pspp_arma_state *);
+void set_d_psi_d_ma (struct pspp_arma_state *);
+#endif

Index: arma.h
===================================================================
RCS file: arma.h
diff -N arma.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ arma.h      24 Jan 2007 17:28:43 -0000      1.1
@@ -0,0 +1,111 @@
+/*
+  src/math/ts/arma.h
+  
+  Copyright (C) 2006 Free Software Foundation, Inc. Written by Jason H. Stover.
+  
+  This program is free software; you can redistribute it and/or modify it under
+  the terms of the GNU General Public License as published by the Free
+  Software Foundation; either version 2 of the License, or (at your option)
+  any later version.
+  
+  This program is distributed in the hope that it will be useful, but WITHOUT
+  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+  more details.
+  
+  You should have received a copy of the GNU General Public License along with
+  this program; if not, write to the Free Software Foundation, Inc., 51
+  Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
+ */
+#ifndef ARMA_H
+#define ARMA_H
+#include <stdbool.h>
+#include <gsl/gsl_math.h>
+#include <gsl/gsl_vector.h>
+#include <gsl/gsl_matrix.h>
+#include <data/variable.h>
+#include <data/value.h>
+/*
+  Find ARMA coefficients via re-paramaterization and conjugate gradients.
+
+  Reference:
+
+  P. J. Brockwell and R. A. Davis. Time Series: Theory and
+  Methods. Second edition. Springer. New York. 1991. ISBN
+  0-387-97429-6. Sections 5.2, 8.3 and 8.4.
+ */
+
+/*
+  Options describing what special values should be computed.
+ */
+struct pspp_arma_opts_struct
+{
+  int *get_depvar_mean_std;
+  int ar_order;
+  int ma_order;
+};
+typedef struct pspp_arma_opts_struct pspp_arma_opts;
+
+/*
+  Find the maximum likelihood estimate for the causal, invertible
+  ARMA(p,q) process:
+
+  Y_t - \phi_1 * Y_{t-1} - ... - \phi_p * Y_{t-p} =
+  Z_t + \theta_1 * Z_{t-1} + ... + Z_{t-q}
+
+  where Z_t, Z_{t-1}, ... are white noise.
+*/
+struct pspp_arma_struct
+{
+  size_t n_obs;
+  size_t ar_order;
+  size_t ma_order;
+  
+  /*
+     The variable struct is ignored during estimation. It is here so
+     the calling procedure can find the variable used in the model.
+   */
+  const struct variable *depvar;
+
+  gsl_vector *ar_coeff;
+  gsl_vector *ma_coeff;
+  
+  gsl_vector *acf; /* The model store the autocovariance function
+                     up to lag ar_coeff. */
+
+  double mean;
+  double std;
+  double mse; /* Variance of the innovations. */
+
+  /*
+     Covariance matrix of the parameter estimates.
+   */
+  gsl_matrix *cov;
+
+  double (*predict) (const struct variable **, const union value **,
+                     const void *, int);
+  double (*residual) (const struct variable **,
+                      const union value **,
+                      const union value *, const void *, int);
+  /*
+     Returns pointers to the variables used in the model.
+   */
+  int (*get_vars) (const void *, struct variable **);
+  struct variable *resid;
+  struct variable *pred;
+
+};
+
+typedef struct pspp_arma_struct pspp_arma;
+
+pspp_arma *pspp_arma_alloc (size_t, size_t, size_t);
+bool pspp_arma_free (pspp_arma *);
+double arma_get_ar_est (const pspp_arma *, size_t);
+double arma_get_ma_est (const pspp_arma *, size_t);
+pspp_arma * pspp_arma_fit (gsl_vector *, size_t, size_t);
+double pspp_arma_loglikelihood (const gsl_vector *, void *);
+void pspp_arma_d_loglikelihood (const gsl_vector *, void *, gsl_vector *);
+void pspp_arma_l_dl (const gsl_vector *, void *, double *, gsl_vector *);
+double pspp_arma_acf (const pspp_arma *, int);
+double reparam_acf (size_t, size_t, void *);
+#endif

Index: innovations.h
===================================================================
RCS file: innovations.h
diff -N innovations.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ innovations.h       24 Jan 2007 17:28:43 -0000      1.1
@@ -0,0 +1,50 @@
+/*
+  src/math/ts/innovations.h
+  
+  Copyright (C) 2006 Free Software Foundation, Inc. Written by Jason H. Stover.
+  
+  This program is free software; you can redistribute it and/or modify it under
+  the terms of the GNU General Public License as published by the Free
+  Software Foundation; either version 2 of the License, or (at your option)
+  any later version.
+  
+  This program is distributed in the hope that it will be useful, but WITHOUT
+  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+  more details.
+  
+  You should have received a copy of the GNU General Public License along with
+  this program; if not, write to the Free Software Foundation, Inc., 51
+  Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
+ */
+/*
+  Find preliminary ARMA coefficients via the innovations algorithm.
+  Also compute the sample mean and covariance matrix for each series.
+
+  Reference:
+
+  P. J. Brockwell and R. A. Davis. Time Series: Theory and
+  Methods. Second edition. Springer. New York. 1991. ISBN
+  0-387-97429-6. Sections 5.2, 8.3 and 8.4.
+ */
+#ifndef INNOVATIONS_H
+#define INNOVATIONS_H
+#include <gsl/gsl_matrix.h>
+
+struct innovations_estimate
+{
+  const struct variable *variable;
+  double mean;
+  gsl_matrix *cov;
+  gsl_vector *scale;
+  size_t n_obs;
+  gsl_matrix *coeff;
+};
+struct innovations_estimate * pspp_innovations (const gsl_vector *, 
+                                               double  (*) (size_t, size_t, 
void *), void *);
+gsl_vector * pspp_innovations_predicted_values (struct innovations_estimate *, 
+                                               gsl_vector *);
+gsl_vector * pspp_innovations_residuals (struct innovations_estimate *, 
+                                        const gsl_vector *);
+void pspp_innovations_free (struct innovations_estimate *);
+#endif

Index: ts-coefficient.h
===================================================================
RCS file: ts-coefficient.h
diff -N ts-coefficient.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ ts-coefficient.h    24 Jan 2007 17:28:43 -0000      1.1
@@ -0,0 +1,25 @@
+/*
+  src/math/ts/ts-coefficient.h
+  
+  Copyright (C) 2006 Free Software Foundation, Inc. Written by Jason H. Stover.
+  
+  This program is free software; you can redistribute it and/or modify it under
+  the terms of the GNU General Public License as published by the Free
+  Software Foundation; either version 2 of the License, or (at your option)
+  any later version.
+  
+  This program is distributed in the hope that it will be useful, but WITHOUT
+  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+  more details.
+  
+  You should have received a copy of the GNU General Public License along with
+  this program; if not, write to the Free Software Foundation, Inc., 51
+  Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
+ */
+#ifndef TS_COEFFICIENT_H
+#define TS_COEFFICIENT_H
+struct pspp_ts_coefficient
+{
+  
+#endif




reply via email to

[Prev in Thread] Current Thread [Next in Thread]