source: trunk/lib/statistics/Local.h @ 430

Last change on this file since 430 was 430, checked in by Peter, 18 years ago

changed interface of Regression::Local

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
1// $Id: Local.h 430 2005-12-08 22:53:08Z peter $
2
3#ifndef _theplu_statistics_regression_local_
4#define _theplu_statistics_regression_local_
5
6#include <c++_tools/statistics/Kernel.h>
7#include <c++_tools/statistics/OneDimensionalWeighted.h>
8#include <c++_tools/gslapi/vector.h>
9
10#include <iostream>
11
12namespace theplu {
13namespace statistics {
14namespace regression {
15
16  ///
17  /// Class for Locally weighted regression.
18  ///
19  /// Locally weighted regression is an algorithm for learning
20  /// continuous non-linear mappings in a non-parametric manner.  In
21  /// locally weighted regression, points are weighted by proximity to
22  /// the current x in question using a Kernel. A weighted regression
23  /// is then computed using the weighted points and a specific
24  /// Regression method. This procedure is repeated, which results in
25  /// a pointwise approximation of the underlying (unknown) function.
26  ///
27  class Local
28  {
29 
30  public:
31    ///
32    /// Constructor taking type of \a regressor,
33    /// type of \a kernel.
34    ///
35    inline Local(OneDimensionalWeighted& r, Kernel& k) 
36      : kernel_(&k), regressor_(&r) {}
37
38    ///
39    /// Destructor
40    ///
41    virtual ~Local(void) {};
42
43
44    ///
45    /// adding a data point
46    ///
47    inline void add(const double x, const double y) 
48    { data_.push_back(std::make_pair(x,y)); }
49
50    ///
51    /// Function returning predicted values
52    ///
53    inline const gslapi::vector& y_predicted(void) const 
54    { return y_predicted_; }
55
56    ///
57    /// Function returning error of predictions
58    ///
59    inline const gslapi::vector& y_err(void) const { return y_err_; }
60 
61    ///
62    /// Performs the fit in data defined by add using a
63    /// RegressionKernel and a Regression method defined in the
64    /// constructor. For each element in vector \a x a fit is
65    /// performed. The kernel used has width \a width and is
66    /// centralized over the data point \f$ x_i \f$, which means data
67    /// in \f$ [x-width, x+width] is used in the fit.
68    ///
69    void fit(const double width, const gslapi::vector& x);
70
71    ///
72    /// @return x-values where fitting was performed.
73    ///
74    inline const gslapi::vector& x(void) const { return x_; }
75
76  private:
77    ///
78    /// Copy Constructor. (Not implemented)
79    ///
80    Local(const Local&);
81
82    std::vector<std::pair<double, double> > data_;
83    Kernel* kernel_;
84    OneDimensionalWeighted* regressor_;
85    gslapi::vector x_;
86    gslapi::vector y_predicted_; 
87    gslapi::vector y_err_; 
88
89  };
90
91  ///
92  /// The output operator for the RegressionLocal class.
93  ///
94  std::ostream& operator<<(std::ostream&, const Local& );
95
96
97}}} // of namespaces regression, statistics and thep
98
99#endif
Note: See TracBrowser for help on using the repository browser.