vmmlib  1.7.0
 All Classes Namespaces Functions Pages
tensor_stats.hpp
1 /*
2  * Copyright (c) 2006-2014, Visualization and Multimedia Lab,
3  * University of Zurich <http://vmml.ifi.uzh.ch>,
4  * Eyescale Software GmbH,
5  * Blue Brain Project, EPFL
6  *
7  * This file is part of VMMLib <https://github.com/VMML/vmmlib/>
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * Redistributions of source code must retain the above copyright notice, this
13  * list of conditions and the following disclaimer. Redistributions in binary
14  * form must reproduce the above copyright notice, this list of conditions and
15  * the following disclaimer in the documentation and/or other materials provided
16  * with the distribution. Neither the name of the Visualization and Multimedia
17  * Lab, University of Zurich nor the names of its contributors may be used to
18  * endorse or promote products derived from this software without specific prior
19  * written permission.
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /* @author Rafael Ballester
34  *
35  * Class for encapsulating several tensor experimental properties, so that they can be easily returned, manipulated and printed (approximation error, decomposition and reconstruction times, etc.).
36  *
37  */
38 #include <string>
39 
40 #ifndef __VMML__TENSOR_STATS__HPP__
41 #define __VMML__TENSOR_STATS__HPP__
42 
43 namespace vmml {
44 
45  class tensor_stats {
46  public:
47 
48  tensor_stats() {
49  ranks = n_iterations = error = nnz = dec_time = rec_time = 0;
50  }
51 
52  tensor_stats(const tensor_stats& other) {
53  description = other.description;
54  ranks = other.ranks;
55  n_iterations = other.n_iterations;
56  error = other.error;
57  nnz = other.nnz;
58  dec_time = other.dec_time;
59  rec_time = other.rec_time;
60  }
61 
62  inline tensor_stats operator+(const tensor_stats& other) const {
63  tensor_stats result(*this);
64  result += other;
65  return result;
66  }
67 
68  void operator+=(const tensor_stats& other) {
69  ranks += other.ranks;
70  n_iterations += other.n_iterations;
71  error += other.error;
72  nnz += other.nnz;
73  dec_time += other.dec_time;
74  rec_time += other.rec_time;
75  }
76 
77  friend std::ostream& operator <<(std::ostream& os,
78  const tensor_stats& stats) {
79  os << stats.description << " " << stats.ranks << " " << stats.n_iterations << " " << stats.error << " " << stats.nnz << " " << stats.dec_time << " " << stats.rec_time;
80  return os;
81  }
82 
83  std::string get_description() {
84  return description;
85  }
86 
87  std::string get_short_description() {
88  return short_description;
89  }
90 
91  int get_ranks() {
92  return ranks;
93  }
94 
95  int get_n_iterations() {
96  return n_iterations;
97  }
98 
99  double get_error() {
100  return error;
101  }
102 
103  int get_nnz() {
104  return nnz;
105  }
106 
107  double get_dec_time() {
108  return dec_time;
109  }
110 
111  double get_rec_time() {
112  return rec_time;
113  }
114 
115  void set_description( const std::string& desc ) {
116  description = desc;
117  }
118 
119  void set_short_description( const std::string& short_desc ) {
120  short_description = short_desc;
121  }
122 
123  void set_ranks( const int r ) { ranks = r; }
124 
125  void set_n_iterations( const int n_it ) { n_iterations = n_it; }
126 
127  void set_error( const double err ) { error = err; }
128 
129  void set_nnz( const int nnz_ ) { nnz = nnz_; }
130 
131  void set_dec_time( const double dec ) { dec_time = dec; }
132 
133  void set_rec_time( const double rec ) { rec_time = rec; }
134 
135  static std::string get_content() {
136  return "description ranks n_iterations error nnz dec_time rec_time";
137  }
138 
139  private:
140  std::string description;
141  std::string short_description; // The description, without rank sizes
142  int ranks;
143  int n_iterations;
144  double error;
145  int nnz;
146  double dec_time;
147  double rec_time;
148 
149  };
150 
151 } // namespace vmml
152 
153 #endif
154