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

Last change on this file since 429 was 429, checked in by Peter, 17 years ago

separating weighted and non-weighted regression to different classes.

• 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 429 2005-12-08 19:50:11Z 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
11namespace theplu {
12namespace statistics {
13namespace regression {
14
15  ///
16  /// Class for Locally weighted regression.
17  ///
18  /// Locally weighted regression is an algorithm for learning
19  /// continuous non-linear mappings in a non-parametric manner.  In
20  /// locally weighted regression, points are weighted by proximity to
21  /// the current x in question using a Kernel. A weighted regression
22  /// is then computed using the weighted points and a specific
23  /// Regression method. This procedure is repeated, which results in
24  /// a pointwise approximation of the underlying (unknown) function.
25  ///
26  class Local
27  {
28
29  public:
30    ///
31    /// Constructor taking type of \a regressor,
32    /// type of \a kernel.
33    ///
34    inline Local(OneDimensionalWeighted& r, Kernel& k)
35      : kernel_(&k), regressor_(&r) {}
36
37    ///
38    /// Destructor
39    ///
40    virtual ~Local(void) {};
41
42
43    ///
44    /// adding a data point
45    ///
46    inline void add(const double x, const double y)
47    { data_.push_back(std::make_pair(x,y)); }
48
49    ///
50    /// Function returning the points where to predict
51    ///
52    inline const std::vector<double>& x(void) const { return x_; }
53
54    ///
55    /// Function returning predicted values
56    ///
57    inline const std::vector<double>& y(void) const { return y_; }
58
59    ///
60    /// Function returning error of predictions
61    ///
62    inline const std::vector<double>& y_err(void) const { return y_err_; }
63
64    ///
65    /// Performs the fit in data defined by add using a
66    /// RegressionKernel and a Regression method defined in the
67    /// constructor. The function starts by regressing over the lowest
68    /// x value, followed by stepping forward \a step_size number of
69    /// points, et cetera. The kernel is centralized over the x-value
70    /// in question and the width is set so \a fraction of all points
71    /// are used. The result is sent to ostream \a s, using print
72    /// function in used Regression.
73    ///
74    void fit(std::ostream& s, const double fraction, const u_int step_size=1);
75
76
77  private:
78    ///
79    /// Copy Constructor. (Not implemented)
80    ///
81    Local(const Local&);
82
83    std::vector<std::pair<double, double> > data_;
84    Kernel* kernel_;
85    OneDimensionalWeighted* regressor_;
86    std::vector<double> x_;
87    std::vector<double> y_;
88    std::vector<double> y_err_;
89
90  };
91
92}}} // of namespaces regression, statisitcs and thep
93
94#endif
Note: See TracBrowser for help on using the repository browser.