SHOGUN  6.1.3
ObservedValue.h
Go to the documentation of this file.
1 /*
2 * BSD 3-Clause License
3 *
4 * Copyright (c) 2017, Shogun-Toolbox e.V. <shogun-team@shogun-toolbox.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * * Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * Written (W) 2017 Giovanni De Toni
33 *
34 */
35 
36 #ifndef SHOGUN_OBSERVEDVALUE_H
37 #define SHOGUN_OBSERVEDVALUE_H
38 
39 #include <chrono>
40 #include <shogun/lib/any.h>
41 #include <shogun/lib/common.h>
42 #include <utility>
43 
48 namespace shogun
49 {
50  /* Timepoint */
52 
53  /* Type of the observed value */
55  {
58  };
59 
64  {
65  public:
73  int64_t step, std::string& name, Any value, SG_OBS_VALUE_TYPE type)
74  : m_step(step), m_name(name), m_value(value), m_type(type)
75  {
76  }
77 
79 
84  int64_t get_step() const
85  {
86  return m_step;
87  }
88 
93  void set_step(int64_t step)
94  {
95  m_step = step;
96  }
97 
102  const std::string& get_name() const
103  {
104  return m_name;
105  }
106 
111  void set_name(const std::string& name)
112  {
113  m_name = name;
114  }
115 
120  const Any& get_value() const
121  {
122  return m_value;
123  }
124 
129  void set_value(const Any& value)
130  {
131  m_value = value;
132  }
133 
139  {
140  return m_type;
141  }
142 
147  void set_type(const SG_OBS_VALUE_TYPE type)
148  {
149  m_type = type;
150  }
151 
159  static ObservedValue
160  make_observation(int64_t step, std::string& name, Any value)
161  {
162  return ObservedValue(step, name, value, TENSORBOARD);
163  }
164 
165  protected:
167  int64_t m_step;
169  std::string m_name;
174  };
175 
179  typedef std::pair<ObservedValue, time_point> TimedObservedValue;
180 
186  SG_FORCED_INLINE double convert_to_millis(const time_point& value)
187  {
188  return std::chrono::duration_cast<std::chrono::milliseconds>(
189  value.time_since_epoch())
190  .count();
191  }
192 }
193 
194 #endif // SHOGUN_OBSERVEDVALUE_H
std::pair< ObservedValue, time_point > TimedObservedValue
void set_value(const Any &value)
SG_OBS_VALUE_TYPE
Definition: ObservedValue.h:54
Allows to store objects of arbitrary types by using a BaseAnyPolicy and provides a type agnostic API...
Definition: any.h:290
void set_name(const std::string &name)
SG_OBS_VALUE_TYPE get_type() const
#define SG_FORCED_INLINE
Definition: common.h:91
void set_step(int64_t step)
Definition: ObservedValue.h:93
static ObservedValue make_observation(int64_t step, std::string &name, Any value)
std::chrono::steady_clock::time_point time_point
Definition: ObservedValue.h:51
SG_OBS_VALUE_TYPE m_type
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
SG_FORCED_INLINE double convert_to_millis(const time_point &value)
const std::string & get_name() const
int64_t get_step() const
Definition: ObservedValue.h:84
ObservedValue(int64_t step, std::string &name, Any value, SG_OBS_VALUE_TYPE type)
Definition: ObservedValue.h:72
const Any & get_value() const
void set_type(const SG_OBS_VALUE_TYPE type)

SHOGUN Machine Learning Toolbox - Documentation