source: trunk/yat/regression/Local.h @ 1486

Last change on this file since 1486 was 1486, checked in by Jari Häkkinen, 13 years ago

Addresses #436.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1#ifndef _theplu_yat_regression_local_
2#define _theplu_yat_regression_local_
3
4// $Id: Local.h 1486 2008-09-09 21:17:19Z jari $
5
6/*
7  Copyright (C) 2004 Peter Johansson
8  Copyright (C) 2005, 2006, 2007 Jari Häkkinen, Peter Johansson
9  Copyright (C) 2008 Peter Johansson
10
11  This file is part of the yat library, http://dev.thep.lu.se/yat
12
13  The yat library is free software; you can redistribute it and/or
14  modify it under the terms of the GNU General Public License as
15  published by the Free Software Foundation; either version 3 of the
16  License, or (at your option) any later version.
17
18  The yat library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  General Public License for more details.
22
23  You should have received a copy of the GNU General Public License
24  along with this program; if not, write to the Free Software
25  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26  02111-1307, USA.
27*/
28
29#include "yat/utility/Vector.h"
30
31#include <iostream>
32
33namespace theplu {
34namespace yat {
35namespace regression {
36
37  class Kernel;
38  class OneDimensionalWeighted;
39
40  ///
41  /// @brief Class for Locally weighted regression.
42  ///
43  /// Locally weighted regression is an algorithm for learning
44  /// continuous non-linear mappings in a non-parametric manner.  In
45  /// locally weighted regression, points are weighted by proximity to
46  /// the current x in question using a Kernel. A weighted regression
47  /// is then computed using the weighted points and a specific
48  /// Regression method. This procedure is repeated, which results in
49  /// a pointwise approximation of the underlying (unknown) function.
50  ///
51  class Local
52  {
53 
54  public:
55    ///
56    /// @brief Constructor taking type of \a regressor,
57    /// type of \a kernel.
58    ///
59    Local(OneDimensionalWeighted& r, Kernel& k);
60
61    ///
62    /// @brief The destructor
63    ///
64    virtual ~Local(void);
65
66    ///
67    /// adding a data point
68    ///
69    void add(const double x, const double y);
70
71    ///
72    /// @param step_size Size of step between each fit
73    /// @param nof_points Number of points used in each fit
74    ///
75    /// \throw std::runtime_error if step_size is 0, nof_points is
76    /// less than 3, or step_size is larger than number of added data
77    /// points.
78    void fit(const size_t step_size, const size_t nof_points);
79
80    /**
81       \brief Set everything to zero
82
83       \since New in yat 0.5
84     */
85    void reset(void);
86
87    ///
88    /// @return x-values where fitting was performed.
89    ///
90    const utility::Vector& x(void) const;
91
92    ///
93    /// Function returning predicted values
94    ///
95    const utility::Vector& y_predicted(void) const;
96
97    ///
98    /// Function returning error of predictions
99    ///
100    const utility::Vector& y_err(void) const;
101
102  private:
103    ///
104    /// Copy Constructor. (Not implemented)
105    ///
106    Local(const Local&);
107
108    std::vector<std::pair<double, double> > data_;
109    Kernel* kernel_;
110    OneDimensionalWeighted* regressor_;
111    utility::Vector x_;
112    utility::Vector y_predicted_; 
113    utility::Vector y_err_; 
114  };
115
116  ///
117  /// The output operator for the Regression::Local class.
118  ///
119  std::ostream& operator<<(std::ostream&, const Local& );
120
121}}} // of namespaces regression, yat, and theplu
122
123#endif
Note: See TracBrowser for help on using the repository browser.