pops-core  0.9
PoPS (Pest or Pathogen Spread) Model Core C++ library
statistics.hpp
Go to the documentation of this file.
1 /*
2  * PoPS model - Various statistics computation
3  *
4  * Copyright (C) 2015-2020 by the authors.
5  *
6  * Authors: Anna Petrasova <akratoc gmail com>
7  *
8  * The code contained herein is licensed under the GNU General Public
9  * License. You may obtain a copy of the GNU General Public License
10  * Version 2 or later at the following locations:
11  *
12  * http://www.opensource.org/licenses/gpl-license.html
13  * http://www.gnu.org/copyleft/gpl.html
14  */
15 
16 #ifndef POPS_STATISTICS_HPP
17 #define POPS_STATISTICS_HPP
18 
19 namespace pops {
20 
25 template<typename IntegerRaster>
26 unsigned sum_of_infected(
27  const IntegerRaster& infected, const std::vector<std::vector<int>>& suitable_cells)
28 {
29  unsigned sum = 0;
30  for (auto indices : suitable_cells) {
31  int i = indices[0];
32  int j = indices[1];
33  sum += infected(i, j);
34  }
35  return sum;
36 }
41 template<typename IntegerRaster>
43  const IntegerRaster& infected,
44  double ew_res,
45  double ns_res,
46  const std::vector<std::vector<int>>& suitable_cells)
47 {
48  unsigned cells = 0;
49  for (auto indices : suitable_cells) {
50  int i = indices[0];
51  int j = indices[1];
52  if (infected(i, j) > 0)
53  cells++;
54  }
55  return cells * ew_res * ns_res;
56 }
57 
58 } // namespace pops
59 #endif // POPS_STATISTICS_HPP
pops::sum_of_infected
unsigned sum_of_infected(const IntegerRaster &infected, const std::vector< std::vector< int >> &suitable_cells)
Computes sum of infected hosts from all cells of a raster.
Definition: statistics.hpp:26
indices
Definition: utils.hpp:97
pops
Definition: cauchy_kernel.hpp:25
pops::area_of_infected
double area_of_infected(const IntegerRaster &infected, double ew_res, double ns_res, const std::vector< std::vector< int >> &suitable_cells)
Computes infected area as number of cell > 0 times cell size.
Definition: statistics.hpp:42