24template <
typename ObjFuncT,
typename TargetT,
typename Parent>
25template <
typename IterT>
27SumOfGeneralisedObjectiveFunctions<ObjFuncT, TargetT, Parent>::set_functions(IterT begin, IterT end)
29 this->_functions.resize(0);
30 std::copy(begin, end, this->_functions.begin());
33template <
typename ObjFuncT,
typename TargetT,
typename Parent>
34SumOfGeneralisedObjectiveFunctions<ObjFuncT, TargetT, Parent>::SumOfGeneralisedObjectiveFunctions()
37template <
typename ObjFuncT,
typename TargetT,
typename Parent>
38template <
typename IterT>
39SumOfGeneralisedObjectiveFunctions<ObjFuncT, TargetT, Parent>::SumOfGeneralisedObjectiveFunctions(IterT begin, IterT end)
41 set_functions(begin, end);
44template <
typename ObjFuncT,
typename TargetT,
typename Parent>
45SumOfGeneralisedObjectiveFunctions<ObjFuncT, TargetT, Parent>::~SumOfGeneralisedObjectiveFunctions()
50template <
typename ObjFuncT,
typename TargetT,
typename Parent>
52SumOfGeneralisedObjectiveFunctions<ObjFuncT, TargetT, Parent>::
53construct_target_ptr()
const
55 if (this->_functions.size() == 0)
58 return this->_functions[0].construct_target_ptr();
62template <
typename ObjFuncT,
typename TargetT,
typename Parent>
66 if (base_type::set_up(target_sptr) != Succeeded::yes)
69 _functions_iterator_type iter = this->_functions.begin();
70 _functions_iterator_type end_iter = this->_functions.end();
71 while (iter != end_iter)
73 if (iter->set_up(target_sptr) == Succeeded::no)
77 return Succeeded::yes;
80template <
typename ObjFuncT,
typename TargetT,
typename Parent>
83 TargetT& gradient,
const TargetT& current_estimate,
const int subset_num)
85 _functions_iterator_type iter = this->_functions.begin();
86 _functions_iterator_type end_iter = this->_functions.end();
87 while (iter != end_iter)
89 iter->compute_sub_gradient_without_penalty(gradient, current_estimate, subset_num);
95template <
typename ObjFuncT,
typename TargetT,
typename Parent>
98 const TargetT& current_estimate,
const int subset_num)
100 _functions_iterator_type iter = this->_functions.begin();
101 _functions_iterator_type end_iter = this->_functions.end();
103 while (iter != end_iter)
105 result += iter->compute_objective_function_without_penalty(current_estimate, subset_num);
112template <
typename ObjFuncT,
typename TargetT,
typename Parent>
116 this->num_subsets = new_num_subsets;
117 _functions_iterator_type iter = this->_functions.begin();
118 _functions_iterator_type end_iter = this->_functions.end();
119 while (iter != end_iter)
122 if (iter->set_num_subsets(this->num_subsets) != this->num_subsets)
123 error(
"set_num_subsets failed to set to %d subsets", this->num_subsets);
126 return this->num_subsets;
129template <
typename ObjFuncT,
typename TargetT,
typename Parent>
132 std::string& warning_message)
const
134 _functions_const_iterator_type iter = this->_functions.begin();
135 _functions_const_iterator_type end_iter = this->_functions.end();
136 while (iter != end_iter)
138 if (!iter->subsets_are_approximately_balanced(warning_message))
Declaration of class stir::Succeeded.
virtual Succeeded set_up(shared_ptr< TargetT > const &target_sptr)
Has to be called before using this object.
Definition SumOfGeneralisedObjectiveFunctions.inl:64
virtual int set_num_subsets(const int num_subsets)
Attempts to change the number of subsets.
Definition SumOfGeneralisedObjectiveFunctions.inl:114
virtual double actual_compute_objective_function_without_penalty(const TargetT ¤t_estimate, const int subset_num)
Implementation of function that computes the objective function for the current subset.
Definition SumOfGeneralisedObjectiveFunctions.inl:97
virtual void compute_sub_gradient_without_penalty(TargetT &gradient, const TargetT ¤t_estimate, const int subset_num)
This computes the gradient of the unregularised objective function at the current_estimate.
Definition SumOfGeneralisedObjectiveFunctions.inl:82
virtual bool actual_subsets_are_approximately_balanced(std::string &warning_message) const
Implementation of function that checks subset balancing.
Definition SumOfGeneralisedObjectiveFunctions.inl:131
Declaration of stir::error()
void error(const char *const s,...)
Print error with format string a la printf and throw exception.
Definition error.cxx:42