LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
objective_function.hpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2023, Lawrence Livermore National Security, LLC.
3 // Produced at the Lawrence Livermore National Laboratory.
4 // Written by the LBANN Research Team (B. Van Essen, et al.) listed in
5 // the CONTRIBUTORS file. <lbann-dev@llnl.gov>
6 //
7 // LLNL-CODE-697807.
8 // All rights reserved.
9 //
10 // This file is part of LBANN: Livermore Big Artificial Neural Network
11 // Toolkit. For details, see http://software.llnl.gov/LBANN or
12 // https://github.com/LLNL/LBANN.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "Licensee"); you
15 // may not use this file except in compliance with the License. You may
16 // obtain a copy of the License at:
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
23 // implied. See the License for the specific language governing
24 // permissions and limitations under the license.
26 
27 #ifndef LBANN_OBJECTIVE_FUNCTION_HPP_INCLUDED
28 #define LBANN_OBJECTIVE_FUNCTION_HPP_INCLUDED
29 
30 #include "lbann/metrics/metric.hpp"
32 
33 namespace lbann {
34 
37 {
38 public:
41 
47  ~objective_function() = default;
49  objective_function* copy() const { return new objective_function(*this); }
50 
52  template <class Archive>
53  void serialize(Archive& ar);
54 
56  void add_term(std::unique_ptr<objective_function_term> term);
58  std::vector<objective_function_term*> get_terms();
59 
61  void setup(model& m);
62 
70  void start_evaluation(execution_mode mode, int mini_batch_size);
71 
75  EvalType finish_evaluation(execution_mode mode, int mini_batch_size);
76 
80  void differentiate();
81 
86 
89  {
90  for (auto& stats : m_statistics) {
91  stats.second.reset();
92  }
93  }
95  void reset_statistics(execution_mode mode) { m_statistics[mode].reset(); }
96 
104 
106  std::vector<ViewingLayerPtr> get_layer_pointers() const;
108  void set_layer_pointers(std::vector<ViewingLayerPtr> layers);
110  std::vector<ViewingWeightsPtr> get_weights_pointers() const;
112  void set_weights_pointers(std::vector<ViewingWeightsPtr> w);
113 
120  {
121  m_evaluation_time = 0.0;
123  }
124 
126  void write_proto(lbann_data::ObjectiveFunction& proto) const;
127 
128 private:
130  std::vector<std::unique_ptr<objective_function_term>> m_terms;
131 
133  std::map<execution_mode, metric_statistics> m_statistics;
134 
139 };
140 
141 } // namespace lbann
142 
143 #endif // LBANN_OBJECTIVE_FUNCTION_INCLUDED
std::vector< objective_function_term * > get_terms()
void set_layer_pointers(std::vector< ViewingLayerPtr > layers)
std::vector< ViewingWeightsPtr > get_weights_pointers() const
int get_statistics_num_samples(execution_mode mode) const
Abstract base class for neural network models.
Definition: model.hpp:83
std::vector< std::unique_ptr< objective_function_term > > m_terms
std::map< execution_mode, metric_statistics > m_statistics
execution_mode
Neural network execution mode.
Definition: base.hpp:229
EvalType get_mean_value(execution_mode mode) const
void write_proto(lbann_data::ObjectiveFunction &proto) const
void set_weights_pointers(std::vector< ViewingWeightsPtr > w)
EvalType finish_evaluation(execution_mode mode, int mini_batch_size)
EvalType get_evaluation_time() const
std::vector< ViewingLayerPtr > get_layer_pointers() const
void start_evaluation(execution_mode mode, int mini_batch_size)
void reset_statistics(execution_mode mode)
void serialize(Archive &ar)
void add_term(std::unique_ptr< objective_function_term > term)
objective_function * copy() const
double EvalType
Definition: base.hpp:189
EvalType get_differentiation_time() const
objective_function & operator=(const objective_function &other)