SmoothingSpline.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2021 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/psrchive/Util/units/SmoothingSpline.h
10 
11 #ifndef __SmoothingSpline_h
12 #define __SmoothingSpline_h
13 
14 #include "Estimate.h"
15 #include <vector>
16 
18 
24 {
25  int current_knot;
26  std::vector<double> knot;
27  std::vector<double> coefficients;
28  std::vector<double> workspace;
29 
30  double smoothing;
31  double effective_nfree;
32  double chi_squared;
33  bool minimize_gcv;
34 
35  unsigned ndat_good;
36 
37 public:
38 
40  SmoothingSpline ();
41 
43  void set_smoothing (double);
44 
46  void set_effective_nfree (double);
47 
49 
55  void set_msre (double);
56 
58  void set_minimize_gcv (bool);
59 
61  void fit (const std::vector< double >& data_x,
62  const std::vector< Estimate<double> >& data_y);
63 
65  unsigned get_ndat_good () const;
66 
67  double get_fit_gcv ();
68  double get_fit_msre ();
69  double get_fit_effective_nfree ();
70  double get_fit_smoothing ();
71  double get_fit_true_mse ();
72  double get_fit_Gauss_Markov_error_variance ();
73 
75  double evaluate (double);
76 };
77 
79 
94 {
95  bool logarithmic; // linearly space smoothing factors on logarithmic scale
96  unsigned ntrial; // number of trial smoothing factors
97  unsigned npartition; // m=40 in Clark (1977)
98  double validation_fraction; // 0.1 in Clark (1977)
99  SmoothingSpline* spline; // the spline implementation
100 
101 public:
102 
104 
105  void set_spline (SmoothingSpline* _spline) { spline = _spline; }
106 
108  void fit ( std::vector< double >& data_x,
109  std::vector< Estimate<double> >& data_y);
110 
112  double get_mean_gof (const std::vector< double >& data_x,
113  const std::vector< Estimate<double> >& data_y);
114 
116  void get_nfree_trials (std::vector<double>& nfree, unsigned ndat);
117 
118 };
119 
120 class BootstrapUncertainty
121 {
122  unsigned nsample;
123  SmoothingSpline* spline; // the spline implementation
124 
125 public:
126 
127  BootstrapUncertainty ();
128 
129  void set_spline (SmoothingSpline* _spline) { spline = _spline; }
130 
131  void get_uncertainty (const std::vector< double >& dat_x,
132  std::vector< Estimate<double> >& dat_y);
133 };
134 
135 #endif
Determines the spline smoothing factor as in Clark (1977)
Definition: SmoothingSpline.h:93
double evaluate(double)
evaluate the spline at the specified argument
Definition: SmoothingSpline.C:220
void fit(std::vector< double > &data_x, std::vector< Estimate< double > > &data_y)
Fit spline to data using current configuration.
Definition: CrossValidatedSmoothing.C:51
void set_smoothing(double)
Set the smoothing factor.
Definition: SmoothingSpline.C:26
A convenient exception handling class.
Definition: Error.h:54
unsigned get_ndat_good() const
Return the number of good data points included in the fit.
Definition: SmoothingSpline.C:79
void get_nfree_trials(std::vector< double > &nfree, unsigned ndat)
Get the trial smoothing factors.
Definition: CrossValidatedSmoothing.C:26
void set_minimize_gcv(bool)
Determine the smoothing factor using generalized cross-validation.
Definition: SmoothingSpline.C:47
void fit(const std::vector< double > &data_x, const std::vector< Estimate< double > > &data_y)
Fit spline to data using current configuration.
Definition: SmoothingSpline.C:81
double get_mean_gof(const std::vector< double > &data_x, const std::vector< Estimate< double > > &data_y)
Return the mean goodness-of-fit for the current smoothing.
Definition: CrossValidatedSmoothing.C:175
void set_msre(double)
Set the mean squared residual error, MSRE (Equation 5)
Definition: SmoothingSpline.C:40
void set_effective_nfree(double)
Set the effective number of freely estimated parameters.
Definition: SmoothingSpline.C:33
SmoothingSpline()
Default constructor.
Definition: SmoothingSpline.C:16
Interface to GCVSPL sub-routine by Herman J. Woltring.
Definition: SmoothingSpline.h:23

Generated using doxygen 1.8.17