From 2df15c65792bd056d902345f84a37b0772c6ce8e Mon Sep 17 00:00:00 2001 From: David Cattermole Date: Sun, 26 Jan 2025 14:56:21 +1100 Subject: [PATCH] Solver Core - Give "epsilon" tolerance values better names. These names are inline with the Ceres solver tolerance variable names. Also, this change actually fixes a bug where the function tolerence (epsilon1) was being incorrectly set as the grdient tolerance (epsilon3). --- docs/source/commands_solve.rst | 44 +++---- python/mmSolver/_api/solverstep.py | 14 +-- share/design/api/api_classes_detail.graphml | 12 +- src/mmSolver/adjust/adjust_base.cpp | 9 +- src/mmSolver/adjust/adjust_ceres_lmder.cpp | 6 +- src/mmSolver/adjust/adjust_ceres_lmdif.cpp | 6 +- src/mmSolver/adjust/adjust_cminpack_lmder.cpp | 6 +- src/mmSolver/adjust/adjust_cminpack_lmdif.cpp | 6 +- src/mmSolver/adjust/adjust_data.h | 12 +- src/mmSolver/adjust/adjust_defines.h | 30 ++--- src/mmSolver/adjust/adjust_levmar_bc_dif.cpp | 12 +- src/mmSolver/cmd/MMSolver2Cmd.cpp | 13 ++- src/mmSolver/cmd/MMSolverCmd.cpp | 19 +-- src/mmSolver/cmd/MMSolverCmd.h | 45 ++++---- src/mmSolver/cmd/arg_flags_solve_info.cpp | 109 ++++++++++-------- src/mmSolver/cmd/arg_flags_solve_info.h | 42 +++---- 16 files changed, 206 insertions(+), 179 deletions(-) diff --git a/docs/source/commands_solve.rst b/docs/source/commands_solve.rst index 8842c2606..5cbd07401 100644 --- a/docs/source/commands_solve.rst +++ b/docs/source/commands_solve.rst @@ -14,27 +14,27 @@ The command can be run in both MEL and Python. Here is a table of command flags, as currently specified in the command. -======================== ========================================== ======================================================================= ============== -Flag Type Description Default Value -======================== ========================================== ======================================================================= ============== --camera (-c) string, string Camera transform and shape nodes None --marker (-m) string, string, string Marker, Camera, Bundle None --attr (-a) string, string, string, string, string Node attribute, min value, max value, offset and scale None --frame (-f) long int Frame number to solve with 1 --attrStiffness (-asf) string, string, string, string Node attribute, weight plug name, variance plug name, value plug name. None --attrSmoothness (-asm) string, string, string, string Node attribute, weight plug name, variance plug name, value plug name. None --solverType (-st) unsigned int Type of solver to use. --sceneGraphMode (-sgm) unsigned int The Scene Graph used; 0=Maya DAG, 1=MM Scene Graph 0 (Maya DAG) --timeEvalMode (-tem) unsigned int How to evalulate values at different times, 0=DG Context 1=Set TIme 0 (DG Context) --iterations (-it) unsigned int Maximum number of iterations 20 --tauFactor (-t) double Initial Damping Factor 1E-03 --epsilon1 (-e1) double Acceptable gradient change 1E-06 --epsilon2 (-e2) double Acceptable parameter change 1E-06 --epsilon3 (-e3) double Acceptable error 1E-06 --delta (-dt) double Change to the guessed parameters each iteration 1E-04 --autoDiffType (-adt) unsigned int Auto-differencing type 0=forward 1=central 0 (forward) --verbose (-v) bool Prints more information False -======================== ========================================== ======================================================================= ============== +======================== ===================== ========================================== ======================================================================= ============== +Command Flag Command Flag (short) Type Description Default Value +======================== ===================== ========================================== ======================================================================= ============== +-camera -c string, string Camera transform and shape nodes. None +-marker -m string, string, string Marker, Camera, Bundle. None +-attr -a string, string, string, string, string Node attribute, min value, max value, offset and scale. None +-frame -f long int Frame number to solve with. 1 +-attrStiffness -asf string, string, string, string Node attribute, weight plug name, variance plug name, value plug name. None +-attrSmoothness -asm string, string, string, string Node attribute, weight plug name, variance plug name, value plug name. None +-solverType -st unsigned int Type of solver to use. +-sceneGraphMode -sgm unsigned int The Scene Graph used; 0=Maya DAG, 1=MM Scene Graph. 0 (Maya DAG) +-timeEvalMode -tem unsigned int How to evalulate values at different times, 0=DG Context 1=Set Time. 0 (DG Context) +-iterations -it unsigned int Maximum number of iterations. 20 +-tauFactor -t double Initial Damping Factor. 1E-03 +-functionTolerance -ftl double Acceptable function change. 1E-06 +-parameterTolerance -ptl double Acceptable parameter change. 1E-06 +-gradientTolerance -gtl double Acceptable gradient error. 1E-06 +-delta -dt double Change to the guessed parameters each iteration. 1E-04 +-autoDiffType -adt unsigned int Auto-differencing type 0=forward 1=central. 0 (forward) +-verbose -v bool Prints more information. False +======================== ===================== ========================================== ======================================================================= ============== Return ------ @@ -102,7 +102,7 @@ Python Example: solvers = maya.cmds.mmSolverType(query=True, list=True) default_solver = maya.cmds.mmSolverType(query=True, default=True) - + ``mmSolverAffects`` Command +++++++++++++++++++++++++++ diff --git a/python/mmSolver/_api/solverstep.py b/python/mmSolver/_api/solverstep.py index c03145ea8..6e4050712 100644 --- a/python/mmSolver/_api/solverstep.py +++ b/python/mmSolver/_api/solverstep.py @@ -680,17 +680,17 @@ def compile(self, col, mkr_list, attr_list, withtest=False): if tau_factor is not None: kwargs['tauFactor'] = tau_factor - gradient_error_factor = self.get_gradient_error_factor() - if gradient_error_factor is not None: - kwargs['epsilon1'] = gradient_error_factor + function_error_factor = self.get_error_factor() + if function_error_factor is not None: + kwargs['function_tolerance'] = function_error_factor parameter_error_factor = self.get_parameter_error_factor() if parameter_error_factor is not None: - kwargs['epsilon2'] = parameter_error_factor + kwargs['parameter_tolerance'] = parameter_error_factor - error_factor = self.get_error_factor() - if error_factor is not None: - kwargs['epsilon3'] = error_factor + gradient_error_factor = self.get_gradient_error_factor() + if gradient_error_factor is not None: + kwargs['gradient_tolerance'] = gradient_error_factor robust_loss_type = self.get_robust_loss_type() if robust_loss_type is not None: diff --git a/share/design/api/api_classes_detail.graphml b/share/design/api/api_classes_detail.graphml index 867b3518a..fbeed8490 100644 --- a/share/design/api/api_classes_detail.graphml +++ b/share/design/api/api_classes_detail.graphml @@ -321,14 +321,14 @@ get_max_iterations() set_max_iterations(value) get_tau_factor() -get_epsilon1() -get_epsilon2() -get_epsilon3() +get_function_tolerance() +get_parameter_tolerance() +get_gradient_tolerance() get_delta() set_tau_factor(value) -set_epsilon1(value) -set_epsilon2(value) -set_epsilon3(value) +set_function_tolerance(value) +set_parameter_tolerance(value) +set_gradient_tolerance(value) set_delta(value) get_frame_list() diff --git a/src/mmSolver/adjust/adjust_base.cpp b/src/mmSolver/adjust/adjust_base.cpp index 35f57a620..1cc4f04b3 100644 --- a/src/mmSolver/adjust/adjust_base.cpp +++ b/src/mmSolver/adjust/adjust_base.cpp @@ -910,9 +910,12 @@ MStatus solveFrames( MMSOLVER_MAYA_INFO("Solver Type=" << solverOptions.solverType); MMSOLVER_MAYA_INFO("Maximum Iterations=" << solverOptions.iterMax); MMSOLVER_MAYA_INFO("Tau=" << solverOptions.tau); - MMSOLVER_MAYA_INFO("Epsilon1=" << solverOptions.eps1); - MMSOLVER_MAYA_INFO("Epsilon2=" << solverOptions.eps2); - MMSOLVER_MAYA_INFO("Epsilon3=" << solverOptions.eps3); + MMSOLVER_MAYA_INFO( + "Function Tolerance=" << solverOptions.function_tolerance); + MMSOLVER_MAYA_INFO( + "Parameter Tolerance=" << solverOptions.parameter_tolerance); + MMSOLVER_MAYA_INFO( + "Gradient Tolerance=" << solverOptions.gradient_tolerance); MMSOLVER_MAYA_INFO("Delta=" << fabs(solverOptions.delta)); MMSOLVER_MAYA_INFO( "Auto Differencing Type=" << solverOptions.autoDiffType); diff --git a/src/mmSolver/adjust/adjust_ceres_lmder.cpp b/src/mmSolver/adjust/adjust_ceres_lmder.cpp index d690e13e3..735547934 100644 --- a/src/mmSolver/adjust/adjust_ceres_lmder.cpp +++ b/src/mmSolver/adjust/adjust_ceres_lmder.cpp @@ -213,9 +213,9 @@ bool solve_3d_ceres_lmder(SolverOptions& solverOptions, options.max_num_consecutive_invalid_steps = 5; // Allow some invalid steps. options.max_num_iterations = solverOptions.iterMax; - options.function_tolerance = solverOptions.eps1; - options.parameter_tolerance = solverOptions.eps2; - options.gradient_tolerance = solverOptions.eps3; + options.function_tolerance = solverOptions.function_tolerance; + options.parameter_tolerance = solverOptions.parameter_tolerance; + options.gradient_tolerance = solverOptions.gradient_tolerance; options.initial_trust_region_radius = solverOptions.tau; options.jacobi_scaling = true; options.num_threads = 1; diff --git a/src/mmSolver/adjust/adjust_ceres_lmdif.cpp b/src/mmSolver/adjust/adjust_ceres_lmdif.cpp index 4432ea90f..b6d1060f1 100644 --- a/src/mmSolver/adjust/adjust_ceres_lmdif.cpp +++ b/src/mmSolver/adjust/adjust_ceres_lmdif.cpp @@ -131,9 +131,9 @@ bool solve_3d_ceres_lmdif(SolverOptions& solverOptions, options.max_num_consecutive_invalid_steps = 5; // Allow some invalid steps. options.max_num_iterations = solverOptions.iterMax; - options.function_tolerance = solverOptions.eps1; - options.parameter_tolerance = solverOptions.eps2; - options.gradient_tolerance = solverOptions.eps3; + options.function_tolerance = solverOptions.function_tolerance; + options.parameter_tolerance = solverOptions.parameter_tolerance; + options.gradient_tolerance = solverOptions.gradient_tolerance; options.initial_trust_region_radius = solverOptions.tau; options.jacobi_scaling = true; options.num_threads = 1; diff --git a/src/mmSolver/adjust/adjust_cminpack_lmder.cpp b/src/mmSolver/adjust/adjust_cminpack_lmder.cpp index af1b3e61a..497a5af06 100644 --- a/src/mmSolver/adjust/adjust_cminpack_lmder.cpp +++ b/src/mmSolver/adjust/adjust_cminpack_lmder.cpp @@ -99,9 +99,9 @@ bool solve_3d_cminpack_lmder(SolverOptions &solverOptions, ldfjac = numberOfParameters; } - double ftol = solverOptions.eps1; - double xtol = solverOptions.eps2; - double gtol = solverOptions.eps3; + double ftol = solverOptions.function_tolerance; + double xtol = solverOptions.parameter_tolerance; + double gtol = solverOptions.gradient_tolerance; int mode = 2; // Off if (solverOptions.autoParamScale == 1) { diff --git a/src/mmSolver/adjust/adjust_cminpack_lmdif.cpp b/src/mmSolver/adjust/adjust_cminpack_lmdif.cpp index b728af9aa..9dfddb4f7 100644 --- a/src/mmSolver/adjust/adjust_cminpack_lmdif.cpp +++ b/src/mmSolver/adjust/adjust_cminpack_lmdif.cpp @@ -98,9 +98,9 @@ bool solve_3d_cminpack_lmdif(SolverOptions &solverOptions, ldfjac = numberOfParameters; } - double ftol = solverOptions.eps1; - double xtol = solverOptions.eps2; - double gtol = solverOptions.eps3; + double ftol = solverOptions.function_tolerance; + double xtol = solverOptions.parameter_tolerance; + double gtol = solverOptions.gradient_tolerance; // Change the sign of the delta // Note: lmdif only supports auto-diff 'forward' mode. diff --git a/src/mmSolver/adjust/adjust_data.h b/src/mmSolver/adjust/adjust_data.h index 578e480d0..18a859d11 100644 --- a/src/mmSolver/adjust/adjust_data.h +++ b/src/mmSolver/adjust/adjust_data.h @@ -134,9 +134,9 @@ struct PrintStatOptions { struct SolverOptions { int iterMax; double tau; - double eps1; - double eps2; - double eps3; + double function_tolerance; + double parameter_tolerance; + double gradient_tolerance; double delta; int autoDiffType; int autoParamScale; @@ -163,9 +163,9 @@ struct SolverOptions { SolverOptions() : iterMax(0) , tau(0.0) - , eps1(0.0) - , eps2(0.0) - , eps3(0.0) + , function_tolerance(0.0) + , parameter_tolerance(0.0) + , gradient_tolerance(0.0) , delta(0.0) , autoDiffType(AUTO_DIFF_TYPE_FORWARD) , autoParamScale(0) diff --git a/src/mmSolver/adjust/adjust_defines.h b/src/mmSolver/adjust/adjust_defines.h index fb79abd91..93148d2f0 100644 --- a/src/mmSolver/adjust/adjust_defines.h +++ b/src/mmSolver/adjust/adjust_defines.h @@ -113,9 +113,9 @@ // #define CMINPACK_LMDIF_ITERATIONS_DEFAULT_VALUE (100) #define CMINPACK_LMDIF_TAU_DEFAULT_VALUE (1.0) -#define CMINPACK_LMDIF_EPSILON1_DEFAULT_VALUE (1E-6) // ftol -#define CMINPACK_LMDIF_EPSILON2_DEFAULT_VALUE (1E-6) // xtol -#define CMINPACK_LMDIF_EPSILON3_DEFAULT_VALUE (1E-6) // gtol +#define CMINPACK_LMDIF_FUNCTION_TOLERANCE_DEFAULT_VALUE (1E-6) // ftol +#define CMINPACK_LMDIF_PARAMETER_TOLERANCE_DEFAULT_VALUE (1E-6) // xtol +#define CMINPACK_LMDIF_GRADIENT_TOLERANCE_DEFAULT_VALUE (1E-6) // gtol #define CMINPACK_LMDIF_DELTA_DEFAULT_VALUE (1E-04) // cminpack lmdif only supports forward '0=forward' differentiation. #define CMINPACK_LMDIF_AUTO_DIFF_TYPE_DEFAULT_VALUE (AUTO_DIFF_TYPE_FORWARD) @@ -134,9 +134,9 @@ // #define CMINPACK_LMDER_ITERATIONS_DEFAULT_VALUE (100) #define CMINPACK_LMDER_TAU_DEFAULT_VALUE (1.0) -#define CMINPACK_LMDER_EPSILON1_DEFAULT_VALUE (1E-6) // ftol -#define CMINPACK_LMDER_EPSILON2_DEFAULT_VALUE (1E-6) // xtol -#define CMINPACK_LMDER_EPSILON3_DEFAULT_VALUE (1E-6) // gtol +#define CMINPACK_LMDER_FUNCTION_TOLERANCE_DEFAULT_VALUE (1E-6) // ftol +#define CMINPACK_LMDER_PARAMETER_TOLERANCE_DEFAULT_VALUE (1E-6) // xtol +#define CMINPACK_LMDER_GRADIENT_TOLERANCE_DEFAULT_VALUE (1E-6) // gtol #define CMINPACK_LMDER_DELTA_DEFAULT_VALUE (1E-04) // cminpack lmder supports both forward '0=forward' and 'central' auto-diff'ing. #define CMINPACK_LMDER_AUTO_DIFF_TYPE_DEFAULT_VALUE (AUTO_DIFF_TYPE_FORWARD) @@ -156,9 +156,9 @@ // #define CERES_LMDIF_ITERATIONS_DEFAULT_VALUE (100) #define CERES_LMDIF_TAU_DEFAULT_VALUE (1E4) -#define CERES_LMDIF_EPSILON1_DEFAULT_VALUE (1E-6) // function_tolerance -#define CERES_LMDIF_EPSILON2_DEFAULT_VALUE (1E-10) // parameter_tolerance -#define CERES_LMDIF_EPSILON3_DEFAULT_VALUE (1E-8) // gradient_tolerance +#define CERES_LMDIF_FUNCTION_TOLERANCE_DEFAULT_VALUE (1E-6) +#define CERES_LMDIF_PARAMETER_TOLERANCE_DEFAULT_VALUE (1E-10) +#define CERES_LMDIF_GRADIENT_TOLERANCE_DEFAULT_VALUE (1E-8) #define CERES_LMDIF_DELTA_DEFAULT_VALUE (1E-04) // ceres lmder supports both forward '0=forward' and 'central' auto-diff'ing. #define CERES_LMDIF_AUTO_DIFF_TYPE_DEFAULT_VALUE (AUTO_DIFF_TYPE_FORWARD) @@ -178,9 +178,9 @@ // #define CERES_LMDER_ITERATIONS_DEFAULT_VALUE (100) #define CERES_LMDER_TAU_DEFAULT_VALUE (1E4) -#define CERES_LMDER_EPSILON1_DEFAULT_VALUE (1E-6) // function_tolerance -#define CERES_LMDER_EPSILON2_DEFAULT_VALUE (1E-10) // parameter_tolerance -#define CERES_LMDER_EPSILON3_DEFAULT_VALUE (1E-8) // gradient_tolerance +#define CERES_LMDER_FUNCTION_TOLERANCE_DEFAULT_VALUE (1E-6) +#define CERES_LMDER_PARAMETER_TOLERANCE_DEFAULT_VALUE (1E-10) +#define CERES_LMDER_GRADIENT_TOLERANCE_DEFAULT_VALUE (1E-8) #define CERES_LMDER_DELTA_DEFAULT_VALUE (1E-04) // ceres lmder supports both forward '0=forward' and 'central' auto-diff'ing. #define CERES_LMDER_AUTO_DIFF_TYPE_DEFAULT_VALUE (AUTO_DIFF_TYPE_FORWARD) @@ -197,9 +197,9 @@ // #define LEVMAR_ITERATIONS_DEFAULT_VALUE (100) #define LEVMAR_TAU_DEFAULT_VALUE (1.0) -#define LEVMAR_EPSILON1_DEFAULT_VALUE (1E-6) -#define LEVMAR_EPSILON2_DEFAULT_VALUE (1E-6) -#define LEVMAR_EPSILON3_DEFAULT_VALUE (1E-6) +#define LEVMAR_FUNCTION_TOLERANCE_DEFAULT_VALUE (1E-6) +#define LEVMAR_PARAMETER_TOLERANCE_DEFAULT_VALUE (1E-6) +#define LEVMAR_GRADIENT_TOLERANCE_DEFAULT_VALUE (1E-6) #define LEVMAR_DELTA_DEFAULT_VALUE (1E-04) #define LEVMAR_AUTO_DIFF_TYPE_DEFAULT_VALUE (AUTO_DIFF_TYPE_FORWARD) // LevMar does not have auto-parameter scaling. diff --git a/src/mmSolver/adjust/adjust_levmar_bc_dif.cpp b/src/mmSolver/adjust/adjust_levmar_bc_dif.cpp index f45e3f4d2..ba0907d6c 100644 --- a/src/mmSolver/adjust/adjust_levmar_bc_dif.cpp +++ b/src/mmSolver/adjust/adjust_levmar_bc_dif.cpp @@ -85,9 +85,9 @@ bool solve_3d_levmar_bc_dif(SolverOptions &solverOptions, } levmar_opts[0] = solverOptions.tau; - levmar_opts[1] = solverOptions.eps1; - levmar_opts[2] = solverOptions.eps2; - levmar_opts[3] = solverOptions.eps3; + levmar_opts[1] = solverOptions.function_tolerance; + levmar_opts[2] = solverOptions.parameter_tolerance; + levmar_opts[3] = solverOptions.gradient_tolerance; levmar_opts[4] = delta_factor; userData.solverType = solverType; @@ -145,9 +145,9 @@ bool solve_3d_levmar_bc_dif(SolverOptions &solverOptions, // Minimisation options (input only) // opts[0] = tau (scale factor for initialTransform mu) - // opts[1] = epsilon1 (stopping threshold for ||J^T e||_inf) - // opts[2] = epsilon2 (stopping threshold for ||Dp||_2) - // opts[3] = epsilon3 (stopping threshold for ||e||_2) + // opts[1] = function_tolerance (stopping threshold for ||J^T e||_inf) + // opts[2] = parameter_tolerance (stopping threshold for ||Dp||_2) + // opts[3] = gradient_tolerance (stopping threshold for ||e||_2) // opts[4] = delta (step used in difference approximation to the // Jacobian) // diff --git a/src/mmSolver/cmd/MMSolver2Cmd.cpp b/src/mmSolver/cmd/MMSolver2Cmd.cpp index cbc336696..5ba265397 100644 --- a/src/mmSolver/cmd/MMSolver2Cmd.cpp +++ b/src/mmSolver/cmd/MMSolver2Cmd.cpp @@ -87,12 +87,13 @@ MStatus MMSolver2Cmd::parseArgs(const MArgList &args) { status = parseSolveInfoArguments_v2( argData, m_solverOptions.iterMax, m_solverOptions.tau, - m_solverOptions.eps1, m_solverOptions.eps2, m_solverOptions.eps3, - m_solverOptions.delta, m_solverOptions.autoDiffType, - m_solverOptions.autoParamScale, m_solverOptions.robustLossType, - m_solverOptions.robustLossScale, m_solverOptions.solverType, - m_solverOptions.sceneGraphMode, m_solverOptions.timeEvalMode, - m_solverOptions.acceptOnlyBetter, m_solverOptions.frameSolveMode, + m_solverOptions.function_tolerance, m_solverOptions.parameter_tolerance, + m_solverOptions.gradient_tolerance, m_solverOptions.delta, + m_solverOptions.autoDiffType, m_solverOptions.autoParamScale, + m_solverOptions.robustLossType, m_solverOptions.robustLossScale, + m_solverOptions.solverType, m_solverOptions.sceneGraphMode, + m_solverOptions.timeEvalMode, m_solverOptions.acceptOnlyBetter, + m_solverOptions.frameSolveMode, m_solverOptions.solverSupportsAutoDiffForward, m_solverOptions.solverSupportsAutoDiffCentral, m_solverOptions.solverSupportsParameterBounds, diff --git a/src/mmSolver/cmd/MMSolverCmd.cpp b/src/mmSolver/cmd/MMSolverCmd.cpp index 7cf506294..d78a7ecaa 100644 --- a/src/mmSolver/cmd/MMSolverCmd.cpp +++ b/src/mmSolver/cmd/MMSolverCmd.cpp @@ -92,12 +92,13 @@ MStatus MMSolverCmd::parseArgs(const MArgList &args) { CHECK_MSTATUS_AND_RETURN_IT(status); status = parseSolveInfoArguments_v1( - argData, m_iterations, m_tau, m_epsilon1, m_epsilon2, m_epsilon3, - m_delta, m_autoDiffType, m_autoParamScale, m_robustLossType, - m_robustLossScale, m_solverType, m_sceneGraphMode, m_timeEvalMode, - m_acceptOnlyBetter, m_frameSolveMode, m_supportAutoDiffForward, - m_supportAutoDiffCentral, m_supportParameterBounds, m_supportRobustLoss, - m_removeUnusedMarkers, m_removeUnusedAttributes, m_imageWidth); + argData, m_iterations, m_tau, m_function_tolerance, + m_parameter_tolerance, m_gradient_tolerance, m_delta, m_autoDiffType, + m_autoParamScale, m_robustLossType, m_robustLossScale, m_solverType, + m_sceneGraphMode, m_timeEvalMode, m_acceptOnlyBetter, m_frameSolveMode, + m_supportAutoDiffForward, m_supportAutoDiffCentral, + m_supportParameterBounds, m_supportRobustLoss, m_removeUnusedMarkers, + m_removeUnusedAttributes, m_imageWidth); CHECK_MSTATUS_AND_RETURN_IT(status); status = parseSolveLogArguments_v1(argData, m_printStatsList, m_logLevel); @@ -136,9 +137,9 @@ MStatus MMSolverCmd::doIt(const MArgList &args) { SolverOptions solverOptions; solverOptions.iterMax = m_iterations; solverOptions.tau = m_tau; - solverOptions.eps1 = m_epsilon1; - solverOptions.eps2 = m_epsilon2; - solverOptions.eps3 = m_epsilon3; + solverOptions.function_tolerance = m_function_tolerance; + solverOptions.parameter_tolerance = m_parameter_tolerance; + solverOptions.gradient_tolerance = m_gradient_tolerance; solverOptions.delta = m_delta; solverOptions.autoDiffType = m_autoDiffType; solverOptions.autoParamScale = m_autoParamScale; diff --git a/src/mmSolver/cmd/MMSolverCmd.h b/src/mmSolver/cmd/MMSolverCmd.h index 6ef4ea130..9fb89744c 100644 --- a/src/mmSolver/cmd/MMSolverCmd.h +++ b/src/mmSolver/cmd/MMSolverCmd.h @@ -65,9 +65,9 @@ class MMSolverCmd : public MPxCommand { MMSolverCmd() : m_iterations(10) , m_tau(0.0) - , m_epsilon1(0.0) - , m_epsilon2(0.0) - , m_epsilon3(0.0) + , m_function_tolerance(0.0) + , m_parameter_tolerance(0.0) + , m_gradient_tolerance(0.0) , m_delta(0.0) , m_autoDiffType(AUTO_DIFF_TYPE_FORWARD) , m_autoParamScale(0) @@ -106,28 +106,31 @@ class MMSolverCmd : public MPxCommand { // Solver Information. int m_iterations; - double m_tau; // Scale factor for initial transform mu - double m_epsilon1; // Stopping threshold for ||J^T e||_inf (ftol) - double m_epsilon2; // Stopping threshold for ||Dp||_2 (xtol) - double m_epsilon3; // Stopping threshold for ||e||_2 (gtol) - double m_delta; // Step used in difference approximation to the Jacobian + double m_tau; // Scale factor for initial transform mu. + double m_function_tolerance; // Stopping threshold for ||J^T e||_inf (ftol) + double m_parameter_tolerance; // Stopping threshold for ||Dp||_2 (xtol) + double m_gradient_tolerance; // Stopping threshold for ||e||_2 (gtol) + double m_delta; // Step used in difference approximation to the Jacobian. int m_autoDiffType; // Auto Differencing type to use; 0=forward, 1=central. - int m_autoParamScale; // Auto Parameter Scaling; 0=OFF, 1=ON. - int m_robustLossType; // Robust Loss function type; 0=trivial, - // 1=soft_l1, - // 2=cauchy. - double m_robustLossScale; // Factor to scale robust loss function by. - int m_solverType; // Solver type to use; 0=levmar, - // 1=cminpack_lmdif, - // 2=cmpinpack_lmder. - int m_timeEvalMode; // How to evaluate values at different times? - SceneGraphMode m_sceneGraphMode; - bool m_acceptOnlyBetter; // Do not accept solved parameter values if - // the average devation is higher than at start. - bool m_removeUnusedMarkers; // Remove unused Markers from solve? + int m_autoParamScale; // Auto Parameter Scaling; 0=OFF, 1=ON. + int m_robustLossType; // Robust Loss function type; 0=trivial, + // 1=soft_l1, + // 2=cauchy. + double m_robustLossScale; // Factor to scale robust loss function by. + int m_solverType; // Solver type to use; 0=levmar, + // 1=cminpack_lmdif, + // 2=cminpack_lmder, + // 3=ceres_lmdif, + // 4=ceres_lmder. + int m_timeEvalMode; // How to evaluate values at different times? + bool m_acceptOnlyBetter; // Do not accept solved parameter values + // if the average devation is higher + // than at start. + bool m_removeUnusedMarkers; // Remove unused Markers from solve? bool m_removeUnusedAttributes; // Remove unused Attributes from solve? double m_imageWidth; // Defines pixel size in camera space. FrameSolveMode m_frameSolveMode; + SceneGraphMode m_sceneGraphMode; // What type of features does the given solver type support? bool m_supportAutoDiffForward; diff --git a/src/mmSolver/cmd/arg_flags_solve_info.cpp b/src/mmSolver/cmd/arg_flags_solve_info.cpp index d4753580a..3fa7b6b51 100644 --- a/src/mmSolver/cmd/arg_flags_solve_info.cpp +++ b/src/mmSolver/cmd/arg_flags_solve_info.cpp @@ -41,9 +41,12 @@ namespace mmsolver { void createSolveInfoSyntax_solverType(MSyntax &syntax) { syntax.addFlag(TAU_FLAG, TAU_FLAG_LONG, MSyntax::kDouble); - syntax.addFlag(EPSILON1_FLAG, EPSILON1_FLAG_LONG, MSyntax::kDouble); - syntax.addFlag(EPSILON2_FLAG, EPSILON2_FLAG_LONG, MSyntax::kDouble); - syntax.addFlag(EPSILON3_FLAG, EPSILON3_FLAG_LONG, MSyntax::kDouble); + syntax.addFlag(FUNCTION_TOLERANCE_FLAG, FUNCTION_TOLERANCE_FLAG_LONG, + MSyntax::kDouble); + syntax.addFlag(PARAMETER_TOLERANCE_FLAG, PARAMETER_TOLERANCE_FLAG_LONG, + MSyntax::kDouble); + syntax.addFlag(GRADIENT_TOLERANCE_FLAG, GRADIENT_TOLERANCE_FLAG_LONG, + MSyntax::kDouble); syntax.addFlag(DELTA_FLAG, DELTA_FLAG_LONG, MSyntax::kDouble); syntax.addFlag(AUTO_DIFF_TYPE_FLAG, AUTO_DIFF_TYPE_FLAG_LONG, MSyntax::kUnsigned); @@ -98,9 +101,10 @@ void createSolveInfoSyntax(MSyntax &syntax, const int command_version = 0) { MStatus parseSolveInfoArguments_solverType( const MArgDatabase &argData, int &out_iterations, double &out_tau, - double &out_epsilon1, double &out_epsilon2, double &out_epsilon3, - double &out_delta, int &out_autoDiffType, int &out_autoParamScale, - int &out_robustLossType, double &out_robustLossScale, int &out_solverType, + double &out_function_tolerance, double &out_parameter_tolerance, + double &out_gradient_tolerance, double &out_delta, int &out_autoDiffType, + int &out_autoParamScale, int &out_robustLossType, + double &out_robustLossScale, int &out_solverType, bool &out_supportAutoDiffForward, bool &out_supportAutoDiffCentral, bool &out_supportParameterBounds, bool &out_supportRobustLoss) { MStatus status = MStatus::kSuccess; @@ -126,9 +130,12 @@ MStatus parseSolveInfoArguments_solverType( if (out_solverType == SOLVER_TYPE_CMINPACK_LMDIF) { out_iterations = CMINPACK_LMDIF_ITERATIONS_DEFAULT_VALUE; out_tau = CMINPACK_LMDIF_TAU_DEFAULT_VALUE; - out_epsilon1 = CMINPACK_LMDIF_EPSILON1_DEFAULT_VALUE; - out_epsilon2 = CMINPACK_LMDIF_EPSILON2_DEFAULT_VALUE; - out_epsilon3 = CMINPACK_LMDIF_EPSILON3_DEFAULT_VALUE; + out_function_tolerance = + CMINPACK_LMDIF_FUNCTION_TOLERANCE_DEFAULT_VALUE; + out_parameter_tolerance = + CMINPACK_LMDIF_PARAMETER_TOLERANCE_DEFAULT_VALUE; + out_gradient_tolerance = + CMINPACK_LMDIF_GRADIENT_TOLERANCE_DEFAULT_VALUE; out_delta = CMINPACK_LMDIF_DELTA_DEFAULT_VALUE; out_autoDiffType = CMINPACK_LMDIF_AUTO_DIFF_TYPE_DEFAULT_VALUE; out_autoParamScale = CMINPACK_LMDIF_AUTO_PARAM_SCALE_DEFAULT_VALUE; @@ -147,9 +154,12 @@ MStatus parseSolveInfoArguments_solverType( } else if (out_solverType == SOLVER_TYPE_CMINPACK_LMDER) { out_iterations = CMINPACK_LMDER_ITERATIONS_DEFAULT_VALUE; out_tau = CMINPACK_LMDER_TAU_DEFAULT_VALUE; - out_epsilon1 = CMINPACK_LMDER_EPSILON1_DEFAULT_VALUE; - out_epsilon2 = CMINPACK_LMDER_EPSILON2_DEFAULT_VALUE; - out_epsilon3 = CMINPACK_LMDER_EPSILON3_DEFAULT_VALUE; + out_function_tolerance = + CMINPACK_LMDER_FUNCTION_TOLERANCE_DEFAULT_VALUE; + out_parameter_tolerance = + CMINPACK_LMDER_PARAMETER_TOLERANCE_DEFAULT_VALUE; + out_gradient_tolerance = + CMINPACK_LMDER_GRADIENT_TOLERANCE_DEFAULT_VALUE; out_delta = CMINPACK_LMDER_DELTA_DEFAULT_VALUE; out_autoDiffType = CMINPACK_LMDER_AUTO_DIFF_TYPE_DEFAULT_VALUE; out_autoParamScale = CMINPACK_LMDER_AUTO_PARAM_SCALE_DEFAULT_VALUE; @@ -168,9 +178,9 @@ MStatus parseSolveInfoArguments_solverType( } else if (out_solverType == SOLVER_TYPE_CERES_LMDIF) { out_iterations = CERES_LMDIF_ITERATIONS_DEFAULT_VALUE; out_tau = CERES_LMDIF_TAU_DEFAULT_VALUE; - out_epsilon1 = CERES_LMDIF_EPSILON1_DEFAULT_VALUE; - out_epsilon2 = CERES_LMDIF_EPSILON2_DEFAULT_VALUE; - out_epsilon3 = CERES_LMDIF_EPSILON3_DEFAULT_VALUE; + out_function_tolerance = CERES_LMDIF_FUNCTION_TOLERANCE_DEFAULT_VALUE; + out_parameter_tolerance = CERES_LMDIF_PARAMETER_TOLERANCE_DEFAULT_VALUE; + out_gradient_tolerance = CERES_LMDIF_GRADIENT_TOLERANCE_DEFAULT_VALUE; out_delta = CERES_LMDIF_DELTA_DEFAULT_VALUE; out_autoDiffType = CERES_LMDIF_AUTO_DIFF_TYPE_DEFAULT_VALUE; out_autoParamScale = CERES_LMDIF_AUTO_PARAM_SCALE_DEFAULT_VALUE; @@ -191,9 +201,9 @@ MStatus parseSolveInfoArguments_solverType( } else if (out_solverType == SOLVER_TYPE_CERES_LMDER) { out_iterations = CERES_LMDER_ITERATIONS_DEFAULT_VALUE; out_tau = CERES_LMDER_TAU_DEFAULT_VALUE; - out_epsilon1 = CERES_LMDER_EPSILON1_DEFAULT_VALUE; - out_epsilon2 = CERES_LMDER_EPSILON2_DEFAULT_VALUE; - out_epsilon3 = CERES_LMDER_EPSILON3_DEFAULT_VALUE; + out_function_tolerance = CERES_LMDER_FUNCTION_TOLERANCE_DEFAULT_VALUE; + out_parameter_tolerance = CERES_LMDER_PARAMETER_TOLERANCE_DEFAULT_VALUE; + out_gradient_tolerance = CERES_LMDER_GRADIENT_TOLERANCE_DEFAULT_VALUE; out_delta = CERES_LMDER_DELTA_DEFAULT_VALUE; out_autoDiffType = CERES_LMDER_AUTO_DIFF_TYPE_DEFAULT_VALUE; out_autoParamScale = CERES_LMDER_AUTO_PARAM_SCALE_DEFAULT_VALUE; @@ -217,9 +227,9 @@ MStatus parseSolveInfoArguments_solverType( } else if (out_solverType == SOLVER_TYPE_LEVMAR) { out_iterations = LEVMAR_ITERATIONS_DEFAULT_VALUE; out_tau = LEVMAR_TAU_DEFAULT_VALUE; - out_epsilon1 = LEVMAR_EPSILON1_DEFAULT_VALUE; - out_epsilon2 = LEVMAR_EPSILON2_DEFAULT_VALUE; - out_epsilon3 = LEVMAR_EPSILON3_DEFAULT_VALUE; + out_function_tolerance = LEVMAR_FUNCTION_TOLERANCE_DEFAULT_VALUE; + out_parameter_tolerance = LEVMAR_PARAMETER_TOLERANCE_DEFAULT_VALUE; + out_gradient_tolerance = LEVMAR_GRADIENT_TOLERANCE_DEFAULT_VALUE; out_delta = LEVMAR_DELTA_DEFAULT_VALUE; out_autoDiffType = LEVMAR_AUTO_DIFF_TYPE_DEFAULT_VALUE; out_autoParamScale = LEVMAR_AUTO_PARAM_SCALE_DEFAULT_VALUE; @@ -269,21 +279,24 @@ MStatus parseSolveInfoArguments_solverType( out_tau = std::min(out_tau, tau_max_value); assert((out_tau >= tau_min_value) && (out_tau <= tau_max_value)); - // Get 'Epsilon1' - if (argData.isFlagSet(EPSILON1_FLAG)) { - status = argData.getFlagArgument(EPSILON1_FLAG, 0, out_epsilon1); + // Get 'Function_Tolerance' + if (argData.isFlagSet(FUNCTION_TOLERANCE_FLAG)) { + status = argData.getFlagArgument(FUNCTION_TOLERANCE_FLAG, 0, + out_function_tolerance); CHECK_MSTATUS_AND_RETURN_IT(status); } - // Get 'Epsilon2' - if (argData.isFlagSet(EPSILON2_FLAG)) { - status = argData.getFlagArgument(EPSILON2_FLAG, 0, out_epsilon2); + // Get 'Parameter_Tolerance' + if (argData.isFlagSet(PARAMETER_TOLERANCE_FLAG)) { + status = argData.getFlagArgument(PARAMETER_TOLERANCE_FLAG, 0, + out_parameter_tolerance); CHECK_MSTATUS_AND_RETURN_IT(status); } - // Get 'Epsilon3' - if (argData.isFlagSet(EPSILON3_FLAG)) { - status = argData.getFlagArgument(EPSILON3_FLAG, 0, out_epsilon3); + // Get 'Gradient_Tolerance' + if (argData.isFlagSet(GRADIENT_TOLERANCE_FLAG)) { + status = argData.getFlagArgument(GRADIENT_TOLERANCE_FLAG, 0, + out_gradient_tolerance); CHECK_MSTATUS_AND_RETURN_IT(status); } @@ -395,9 +408,10 @@ MStatus parseSolveInfoArguments_other(const MArgDatabase &argData, MStatus parseSolveInfoArguments_v1( const MArgDatabase &argData, int &out_iterations, double &out_tau, - double &out_epsilon1, double &out_epsilon2, double &out_epsilon3, - double &out_delta, int &out_autoDiffType, int &out_autoParamScale, - int &out_robustLossType, double &out_robustLossScale, int &out_solverType, + double &out_function_tolerance, double &out_parameter_tolerance, + double &out_gradient_tolerance, double &out_delta, int &out_autoDiffType, + int &out_autoParamScale, int &out_robustLossType, + double &out_robustLossScale, int &out_solverType, SceneGraphMode &out_sceneGraphMode, int &out_timeEvalMode, bool &out_acceptOnlyBetter, FrameSolveMode &out_frameSolveMode, bool &out_supportAutoDiffForward, bool &out_supportAutoDiffCentral, @@ -405,11 +419,12 @@ MStatus parseSolveInfoArguments_v1( bool &out_removeUnusedMarkers, bool &out_removeUnusedAttributes, double &out_imageWidth) { MStatus status = parseSolveInfoArguments_solverType( - argData, out_iterations, out_tau, out_epsilon1, out_epsilon2, - out_epsilon3, out_delta, out_autoDiffType, out_autoParamScale, - out_robustLossType, out_robustLossScale, out_solverType, - out_supportAutoDiffForward, out_supportAutoDiffCentral, - out_supportParameterBounds, out_supportRobustLoss); + argData, out_iterations, out_tau, out_function_tolerance, + out_parameter_tolerance, out_gradient_tolerance, out_delta, + out_autoDiffType, out_autoParamScale, out_robustLossType, + out_robustLossScale, out_solverType, out_supportAutoDiffForward, + out_supportAutoDiffCentral, out_supportParameterBounds, + out_supportRobustLoss); CHECK_MSTATUS_AND_RETURN_IT(status); status = parseSolveInfoArguments_other( @@ -425,20 +440,22 @@ MStatus parseSolveInfoArguments_v1( MStatus parseSolveInfoArguments_v2( const MArgDatabase &argData, int &out_iterations, double &out_tau, - double &out_epsilon1, double &out_epsilon2, double &out_epsilon3, - double &out_delta, int &out_autoDiffType, int &out_autoParamScale, - int &out_robustLossType, double &out_robustLossScale, int &out_solverType, + double &out_function_tolerance, double &out_parameter_tolerance, + double &out_gradient_tolerance, double &out_delta, int &out_autoDiffType, + int &out_autoParamScale, int &out_robustLossType, + double &out_robustLossScale, int &out_solverType, SceneGraphMode &out_sceneGraphMode, int &out_timeEvalMode, bool &out_acceptOnlyBetter, FrameSolveMode &out_frameSolveMode, bool &out_supportAutoDiffForward, bool &out_supportAutoDiffCentral, bool &out_supportParameterBounds, bool &out_supportRobustLoss, double &out_imageWidth) { MStatus status = parseSolveInfoArguments_solverType( - argData, out_iterations, out_tau, out_epsilon1, out_epsilon2, - out_epsilon3, out_delta, out_autoDiffType, out_autoParamScale, - out_robustLossType, out_robustLossScale, out_solverType, - out_supportAutoDiffForward, out_supportAutoDiffCentral, - out_supportParameterBounds, out_supportRobustLoss); + argData, out_iterations, out_tau, out_function_tolerance, + out_parameter_tolerance, out_gradient_tolerance, out_delta, + out_autoDiffType, out_autoParamScale, out_robustLossType, + out_robustLossScale, out_solverType, out_supportAutoDiffForward, + out_supportAutoDiffCentral, out_supportParameterBounds, + out_supportRobustLoss); CHECK_MSTATUS_AND_RETURN_IT(status); status = parseSolveInfoArguments_other( diff --git a/src/mmSolver/cmd/arg_flags_solve_info.h b/src/mmSolver/cmd/arg_flags_solve_info.h index 8ccd6c355..f6e95f59b 100644 --- a/src/mmSolver/cmd/arg_flags_solve_info.h +++ b/src/mmSolver/cmd/arg_flags_solve_info.h @@ -83,29 +83,29 @@ #define TAU_FLAG "-t" #define TAU_FLAG_LONG "-tauFactor" -// Acceptable Gradient Change. +// Acceptable Error // -// At the beginning of an solver iteration, if the solver has not -// decreased the gradient by at least this value, the solver gives up -// trying to reduce the error any more. -#define EPSILON1_FLAG "-e1" -#define EPSILON1_FLAG_LONG "-epsilon1" +// At the beginning of an solver iteration, if the error level is +// below this value, the solver considers the error to be low enough +// for the user's needs and stops trying to reduce the error. +#define FUNCTION_TOLERANCE_FLAG "-ftl" +#define FUNCTION_TOLERANCE_FLAG_LONG "-functionTolerance" // Acceptable Parameter Change. // // At the beginning of an solver iteration, if the guessed parameters // do not change by at least this value, the solver gives up trying to // reduce the error any more. -#define EPSILON2_FLAG "-e2" -#define EPSILON2_FLAG_LONG "-epsilon2" +#define PARAMETER_TOLERANCE_FLAG "-ptl" +#define PARAMETER_TOLERANCE_FLAG_LONG "-parameterTolerance" -// Acceptable Error +// Acceptable Gradient Change. // -// At the beginning of an solver iteration, if the error level is -// below this value, the solver considers the error to be low enough -// for the user's needs and stops trying to reduce the error. -#define EPSILON3_FLAG "-e3" -#define EPSILON3_FLAG_LONG "-epsilon3" +// At the beginning of an solver iteration, if the solver has not +// decreased the gradient by at least this value, the solver gives up +// trying to reduce the error any more. +#define GRADIENT_TOLERANCE_FLAG "-gtl" +#define GRADIENT_TOLERANCE_FLAG_LONG "-gradientTolerance" // Change to the guessed parameters each iteration // @@ -180,9 +180,10 @@ void createSolveInfoSyntax_v2(MSyntax &syntax); // Parse arguments into solver info. MStatus parseSolveInfoArguments_v1( const MArgDatabase &argData, int &out_iterations, double &out_tau, - double &out_epsilon1, double &out_epsilon2, double &out_epsilon3, - double &out_delta, int &out_autoDiffType, int &out_autoParamScale, - int &out_robustLossType, double &out_robustLossScale, int &out_solverType, + double &out_function_tolerance, double &out_parameter_tolerance, + double &out_gradient_tolerance, double &out_delta, int &out_autoDiffType, + int &out_autoParamScale, int &out_robustLossType, + double &out_robustLossScale, int &out_solverType, SceneGraphMode &out_sceneGraphMode, int &out_timeEvalMode, bool &out_acceptOnlyBetter, FrameSolveMode &out_frameSolveMode, bool &out_supportAutoDiffForward, bool &out_supportAutoDiffCentral, @@ -192,9 +193,10 @@ MStatus parseSolveInfoArguments_v1( MStatus parseSolveInfoArguments_v2( const MArgDatabase &argData, int &out_iterations, double &out_tau, - double &out_epsilon1, double &out_epsilon2, double &out_epsilon3, - double &out_delta, int &out_autoDiffType, int &out_autoParamScale, - int &out_robustLossType, double &out_robustLossScale, int &out_solverType, + double &out_function_tolerance, double &out_parameter_tolerance, + double &out_gradient_tolerance, double &out_delta, int &out_autoDiffType, + int &out_autoParamScale, int &out_robustLossType, + double &out_robustLossScale, int &out_solverType, SceneGraphMode &out_sceneGraphMode, int &out_timeEvalMode, bool &out_acceptOnlyBetter, FrameSolveMode &out_frameSolveMode, bool &out_supportAutoDiffForward, bool &out_supportAutoDiffCentral,