EnergyThreshold.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2015 Imperial College London
5  * Copyright 2013-2015 Andreas Schuh
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef MIRTK_EnergyThreshold_H
21 #define MIRTK_EnergyThreshold_H
22 
23 #include "mirtk/StoppingCriterion.h"
24 
25 
26 namespace mirtk {
27 
28 
29 /**
30  * Stops minimization when object function value falls below a given threshold
31  */
33 {
34  mirtkObjectMacro(EnergyThreshold);
35 
36  // ---------------------------------------------------------------------------
37  // Attributes
38 
39  /// Target objective function value
40  mirtkPublicAttributeMacro(double, Threshold);
41 
42  /// Copy attributes of this class from another instance
43  void CopyAttributes(const EnergyThreshold &other);
44 
45  // ---------------------------------------------------------------------------
46  // Construction/Destruction
47 public:
48 
49  /// Constructor
50  EnergyThreshold(const ObjectiveFunction * = NULL);
51 
52  /// Copy constructor
54 
55  /// Assignment operator
57 
58  /// Create new copy of this instance
59  virtual StoppingCriterion *New() const;
60 
61  /// Destructor
62  virtual ~EnergyThreshold();
63 
64  // ---------------------------------------------------------------------------
65  // Evaluation
66 
67  /// Test stopping criterion
68  ///
69  /// \param[in] iter Current number of iterations.
70  /// \param[in] value Objective function value at current iteration.
71  /// \param[in] delta Last change of objective function parameters.
72  ///
73  /// \returns Whether stopping criterion is fulfilled.
74  virtual bool Fulfilled(int iter, double value, const double *delta);
75 
76  // ---------------------------------------------------------------------------
77  // Logging
78 
79  /// Print current stopping criterion status / value
80  ///
81  /// This function must be called after Fulfilled, which should update any
82  /// cached values that are needed by this function to avoid a costly
83  /// reevaluation of the stopping criterion.
84  ///
85  /// \note The printed string is expected to be considerably short and must
86  /// not end with a newline or space characters.
87  virtual void Print(ostream &) const;
88 
89 };
90 
91 
92 } // namespace mirtk
93 
94 #endif // MIRTK_EnergyThreshold_H
virtual bool Fulfilled(int iter, double value, const double *delta)
EnergyThreshold & operator=(const EnergyThreshold &)
Assignment operator.
virtual StoppingCriterion * New() const
Create new copy of this instance.
Definition: IOConfig.h:41
EnergyThreshold(const ObjectiveFunction *=NULL)
Constructor.
virtual void Print(ostream &) const
virtual ~EnergyThreshold()
Destructor.