source: trunk/yat/statistics/VectorFunction.cc @ 1797

Last change on this file since 1797 was 1797, checked in by Peter, 13 years ago

updating copyright statements

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1// $Id: VectorFunction.cc 1797 2009-02-12 18:07:10Z peter $
2
3/*
4  Copyright (C) 2007, 2008 Jari Häkkinen, 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 "VectorFunction.h"
23#include "utility.h"
24
25#include <algorithm>
26#include <cassert>
27#include <numeric>
28#include <vector>
29
30namespace theplu {
31namespace yat {
32namespace statistics { 
33
34  VectorFunction::~VectorFunction(){}
35
36
37  double Max::operator()(const std::vector<double>& vec) const
38  {
39    assert(vec.size());
40    return *(std::max_element(vec.begin(), vec.end()));
41  }
42 
43
44  double Mean::operator()(const std::vector<double>& vec) const
45  {
46    assert(vec.size());
47    return std::accumulate(vec.begin(), vec.end(), 0.0)/vec.size();
48  }
49 
50
51  double Median::operator()(const std::vector<double>& vec) const
52  {
53    assert(vec.size());
54    return median(vec.begin(), vec.end());
55  }
56 
57
58  double Min::operator()(const std::vector<double>& vec) const
59  {
60    assert(vec.size());
61    return *(std::min_element(vec.begin(), vec.end()));
62  }
63 
64
65  Nth_Element::Nth_Element(size_t N)
66    : N_(N) {}
67
68
69  double Nth_Element::operator()(const std::vector<double>& vec) const
70  {
71    assert(N_-1<vec.size());
72    std::vector<double> vec_copy(vec);
73    std::vector<double>::iterator nth = vec_copy.begin()+(N_-1);
74    std::nth_element(vec_copy.begin(), nth, vec_copy.end());
75    return *(nth);
76  }
77 
78
79
80
81}}} // of namespace statistics, yat, and theplu
Note: See TracBrowser for help on using the repository browser.