source: trunk/yat/regression/Poisson.cc @ 3615

Last change on this file since 3615 was 3615, checked in by Peter, 6 years ago

some trivial tests for regression::Poisson. refs #882

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.5 KB
Line 
1// $Id: Poisson.cc 3615 2017-02-06 02:31:36Z peter $
2
3/*
4  Copyright (C) 2017 Peter Johansson
5
6  This file is part of the yat library, http://dev.thep.lu.se/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 3 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with yat. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include <config.h>
23
24#include "Poisson.h"
25
26#include <yat/utility/Matrix.h>
27#include <yat/utility/Vector.h>
28#include <yat/utility/VectorBase.h>
29#include <yat/utility/VectorConstView.h>
30
31#include <cassert>
32#include <cmath>
33
34namespace theplu {
35namespace yat {
36namespace regression {
37
38  void Poisson::fit(const utility::Matrix& X, const utility::VectorBase& y)
39  {
40    assert(X.rows() == y.size());
41    beta_.resize(X.columns()+1);
42  }
43
44
45  const utility::Vector& Poisson::fit_parameters(void) const
46  {
47    return beta_;
48  }
49
50
51  double Poisson::predict(const utility::VectorBase& x) const
52  {
53    assert(x.size() + 1 == beta_.size());
54    using utility::VectorConstView;
55    double logm = beta_(0) + VectorConstView(beta_, 1, x.size()) * x;
56    return std::exp(logm);
57  }
58
59}}} // of namespaces regression, yat, and theplu
Note: See TracBrowser for help on using the repository browser.