1 #ifndef TRWS_ADSAL_HXX_
2 #define TRWS_ADSAL_HXX_
24 bool absolutePrecision=
true,
25 size_t numOfInternalIterations=3,
29 ValueType primalBoundPrecision=std::numeric_limits<ValueType>::epsilon(),
31 size_t presolveMaxIterNumber=100,
42 :parent(numOfExternalIterations,
45 numOfInternalIterations,
51 presolveMaxIterNumber,
69 #ifdef TRWS_DEBUG_OUTPUT
70 void print(std::ostream& fout)
const
96 template<
class GM,
class ACC>
116 ADSal(
const GraphicalModelType& gm,
const Parameter& param
117 #ifdef TRWS_DEBUG_OUTPUT
118 ,std::ostream& fout=std::cout
123 #ifdef TRWS_DEBUG_OUTPUT
124 ,(param.verbose_ ? fout : *OUT::nullstream::Instance())
129 #ifdef TRWS_DEBUG_OUTPUT
130 parent::_fout <<
"Parameters of the "<<
name() <<
" algorithm:"<<std::endl;
131 param.print(parent::_fout);
134 if (param.numOfExternalIterations_==0)
throw std::runtime_error(
"ADSal: a strictly positive number of iterations must be provided!");
137 std::string
name()
const{
return "ADSal"; }
146 Parameter _parameters;
149 template<
class GM,
class ACC>
150 template<
class VISITOR>
156 visitor.
addLog(
"oracleCalls");
157 visitor.
addLog(
"primalLPbound");
160 if (parent::_sumprodsolver.GetSmoothing()<=0.0)
162 if (parent::_Presolve(visitor, &counter)==
CONVERGENCE)
164 parent::_SelectOptimalBoundsAndLabeling();
166 visitor.
log(
"oracleCalls",(
double)counter);
167 visitor.
log(
"primalLPbound",(
double)parent::_bestPrimalLPbound);
172 #ifdef TRWS_DEBUG_OUTPUT
173 parent::_fout <<
"Switching to the smooth solver============================================"<<std::endl;
175 counter+=parent::_EstimateStartingSmoothing(visitor);
178 bool forwardMoveNeeded=
true;
179 for (
size_t i=0;i<_parameters.numOfExternalIterations_;++i)
181 #ifdef TRWS_DEBUG_OUTPUT
182 parent::_fout <<
"Main iteration Nr."<<i<<
"============================================"<<std::endl;
186 counter+=_parameters.numberOfInternalIterations();
187 if (forwardMoveNeeded)
189 ++counter;returncode=parent::_sumprodsolver.infer();
190 forwardMoveNeeded=
false;
193 returncode=parent::_sumprodsolver.core_infer();
197 parent::_SelectOptimalBoundsAndLabeling();
199 visitor.
log(
"oracleCalls",(
double)counter);
200 visitor.
log(
"primalLPbound",(
double)parent::_bestPrimalLPbound);
206 ++counter;parent::_maxsumsolver.ForwardMove();
207 #ifdef TRWS_DEBUG_OUTPUT
208 parent::_fout <<
"_maxsumsolver.bound()=" <<parent::_maxsumsolver.bound()<<std::endl;
211 ValueType derivative;
212 if (parent::_isLPBoundComputed() || !_parameters.lazyDerivativeComputation())
214 ++counter; parent::_sumprodsolver.GetMarginalsAndDerivativeMove();
215 derivative=parent::_EstimateRhoDerivative();
216 #ifdef TRWS_DEBUG_OUTPUT
217 parent::_fout <<
"derivative="<<derivative<<std::endl;
219 forwardMoveNeeded=
true;
222 derivative=parent::_FastEstimateRhoDerivative();
224 if ( parent::_CheckStoppingCondition(&returncode))
227 visitor.
log(
"oracleCalls",(
double)counter);
228 visitor.
log(
"primalLPbound",(
double)parent::_bestPrimalLPbound);
234 size_t flag=visitor();
235 visitor.
log(
"oracleCalls",(
double)counter);
236 visitor.
log(
"primalLPbound",(
double)parent::_bestPrimalLPbound);
241 if (parent::_UpdateSmoothing(parent::_bestPrimalBound,parent::_maxsumsolver.bound(),parent::_sumprodsolver.bound(),derivative,i+1))
242 forwardMoveNeeded=
true;
243 else if (parent::_sumprodsolver.ConvergenceFlag())
245 #ifdef TRWS_DEBUG_OUTPUT
246 parent::_fout <<
"Numerical Precision attained (smoothing can not be decreased further). Stopping." <<std::endl;
253 parent::_SelectOptimalBoundsAndLabeling();
255 visitor.
log(
"oracleCalls",(
double)counter);
256 visitor.
log(
"primalLPbound",(
double)parent::_bestPrimalLPbound);
262 template<
class GM,
class ACC>
265 if (parent::_sumprodsolver.GetSmoothing()<=0.0)
267 parent::_EstimateStartingSmoothing();
270 for (
size_t i=0;i<_parameters.numOfExternalIterations_;++i)
272 #ifdef TRWS_DEBUG_OUTPUT
273 parent::_fout <<
"Main iteration Nr."<<i<<
"============================================"<<std::endl;
275 for (
size_t innerIt=0;innerIt<_parameters.maxNumberOfIterations_;++innerIt)
277 parent::_sumprodsolver.ForwardMove();
278 parent::_sumprodsolver.BackwardMove();
279 #ifdef TRWS_DEBUG_OUTPUT
280 parent::_fout <<
"subIter="<< innerIt<<
", smoothDualBound=" << parent::_sumprodsolver.bound() <<std::endl;
284 parent::_sumprodsolver.ForwardMove();
285 parent::_sumprodsolver.GetMarginalsAndDerivativeMove();
286 parent::_maxsumsolver.ForwardMove();
287 ValueType derivative=parent::_EstimateRhoDerivative();
288 #ifdef TRWS_DEBUG_OUTPUT
289 parent::_fout <<
"derivative="<<derivative<<std::endl;
292 if ( parent::_CheckStoppingCondition(&returncode))
return returncode;
294 parent::_UpdateSmoothing(parent::_bestPrimalBound,parent::_maxsumsolver.bound(),parent::_sumprodsolver.bound(),derivative,i+1);
bool lazyDerivativeComputation_
bool & lazyDerivativeComputation()
const ValueType & precision() const
parent::SumProdSolver SumProdSolver
ValueType & smoothingDecayMultiplier()
InferenceTermination oldinfer()
Storage::StructureType & decompositionType()
SmoothingStrategyType & smoothingStrategy()
void log(const std::string &logName, double value)
bool & lazyLPPrimalBoundComputation()
parent::MaxSumSolver MaxSumSolver
parent::SumProdSolverParametersType SumProdSolverParametersType
InferenceTermination infer()
size_t & maxPrimalBoundIterationNumber()
visitors::TimingVisitor< ADSal< GM, ACC > > TimingVisitorType
const bool & canonicalNormalization() const
visitors::EmptyVisitor< ADSal< GM, ACC > > EmptyVisitorType
SmoothingParametersType::SmoothingStrategyType SmoothingStrategyType
ADSal_Parameter(size_t numOfExternalIterations=0, ValueType precision=1.0, bool absolutePrecision=true, size_t numOfInternalIterations=3, typename Storage::StructureType decompositionType=Storage::GENERALSTRUCTURE, ValueType smoothingGapRatio=4, ValueType startSmoothingValue=0.0, ValueType primalBoundPrecision=std::numeric_limits< ValueType >::epsilon(), size_t maxPrimalBoundIterationNumber=100, size_t presolveMaxIterNumber=100, bool canonicalNormalization=true, ValueType presolveMinRelativeDualImprovement=0.01, bool lazyLPPrimalBoundComputation=true, bool lazyDerivativeComputation=false, ValueType smoothingDecayMultiplier=-1.0, SmoothingStrategyType smoothingStrategy=SmoothingParametersType::ADAPTIVE_DIMINISHING, bool fastComputations=true, bool verbose=false)
ValueType & smoothingGapRatio()
const bool & fastComputations() const
MaxSumTRWS_Parameters< ValueType > MaxSumSolverParametersType
SumProdTRWS_Parameters< ValueType > SumProdSolverParametersType
ADSal(const GraphicalModelType &gm, const Parameter ¶m)
trws_base::DecompositionStorage< GM > Storage
trws_base::DecompositionStorage< GM > Storage
const bool & lazyDerivativeComputation() const
ValueType & presolveMinRelativeDualImprovement()
const ValueType & startSmoothingValue() const
trws_base::SmoothingBasedInference_Parameter< GM > parent
parent::SmoothingStrategyType SmoothingStrategyType
parent::MaxSumSolverParametersType MaxSumSolverParametersType
[class adsal] ADSal - adaptive diminishing smoothing algorithm Based on the paper: B...
trws_base::SmoothingBasedInference< GM, ACC > parent
PrimalLPBound< GM, ACC > PrimalBoundEstimator
parent::PrimalBoundEstimator PrimalBoundEstimator
trws_base::SumProdTRWS< GM, ACC > SumProdSolver
visitors::VerboseVisitor< ADSal< GM, ACC > > VerboseVisitorType
parent::PrimalLPEstimatorParametersType PrimalLPEstimatorParametersType
PrimalLPBound_Parameter< ValueType > PrimalLPEstimatorParametersType
ADSal_Parameter< GM > Parameter
void addLog(const std::string &logName)
parent::SmoothingParametersType SmoothingParametersType
static const size_t ContinueInf
trws_base::MaxSumTRWS< GM, ACC > MaxSumSolver