LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
objective_function_term.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_TERM_HPP_INCLUDED
28 #define LBANN_OBJECTIVE_FUNCTION_TERM_HPP_INCLUDED
29 
30 #include "lbann/base.hpp"
31 
32 // Forward-declare protobuf classes
33 namespace lbann_data {
34 class ObjectiveFunction;
35 }
36 
37 namespace lbann {
38 
39 // Forward declarations
40 class Layer;
41 using ViewingLayerPtr = std::weak_ptr<Layer>;
42 class model;
43 class weights;
44 using ViewingWeightsPtr = std::weak_ptr<weights>;
45 
48 {
49 public:
51  objective_function_term(EvalType scale_factor = EvalType(1));
52 
54  objective_function_term(const objective_function_term& other) = default;
57  operator=(const objective_function_term& other) = default;
59  virtual ~objective_function_term() = default;
61  virtual objective_function_term* copy() const = 0;
62 
64  template <class Archive>
65  void serialize(Archive& ar);
66 
68  virtual std::string name() const = 0;
69 
71  virtual void setup(model& m);
72 
77  virtual void start_evaluation() = 0;
78 
80  virtual EvalType finish_evaluation() = 0;
81 
86  virtual void differentiate() = 0;
87 
91  virtual void compute_weight_regularization() = 0;
92 
94  std::vector<ViewingLayerPtr> get_layer_pointers() const;
96  void set_layer_pointers(std::vector<ViewingLayerPtr> layers);
98  std::vector<ViewingWeightsPtr> get_weights_pointers() const;
100  void set_weights_pointers(std::vector<ViewingWeightsPtr> w);
101 
103  virtual void
104  write_specific_proto(lbann_data::ObjectiveFunction& proto) const = 0;
105 
106 protected:
109 
111  std::vector<ViewingLayerPtr> m_layers;
113  std::vector<ViewingWeightsPtr> m_weights;
114 
116  lbann_comm& get_comm() { return *m_comm; }
117 
118 private:
121 };
122 
123 } // namespace lbann
124 
125 #endif // LBANN_OBJECTIVE_FUNCTION_TERM_INCLUDED
std::weak_ptr< Layer > ViewingLayerPtr
Smart pointer to reference a layer object.
Definition: layer.hpp:133
std::vector< ViewingWeightsPtr > m_weights
void serialize(std::ostream &os, google::protobuf::Message const &msg)
Serialize the protobuf message to a stream.
Abstract base class for neural network models.
Definition: model.hpp:83
std::weak_ptr< weights > ViewingWeightsPtr
Smart pointer to reference a weights object.
Definition: layer.hpp:89
std::vector< ViewingLayerPtr > m_layers
double EvalType
Definition: base.hpp:189