Struct opencv::core::ConjGradSolver
source · pub struct ConjGradSolver { /* private fields */ }
Expand description
This class is used to perform the non-linear non-constrained minimization of a function with known gradient,
defined on an n-dimensional Euclidean space, using the Nonlinear Conjugate Gradient method. The implementation was done based on the beautifully clear explanatory article An Introduction to the Conjugate Gradient Method Without the Agonizing Pain by Jonathan Richard Shewchuk. The method can be seen as an adaptation of a standard Conjugate Gradient method (see, for example http://en.wikipedia.org/wiki/Conjugate_gradient_method) for numerically solving the systems of linear equations.
It should be noted, that this method, although deterministic, is rather a heuristic method and therefore may converge to a local minima, not necessary a global one. What is even more disastrous, most of its behaviour is ruled by gradient, therefore it essentially cannot distinguish between local minima and maxima. Therefore, if it starts sufficiently near to the local maximum, it may converge to it. Another obvious restriction is that it should be possible to compute the gradient of a function at any point, thus it is preferable to have analytic expression for gradient and computational burden should be born by the user.
The latter responsibility is accomplished via the getGradient method of a MinProblemSolver::Function interface (which represents function being optimized). This method takes point a point in n-dimensional space (first argument represents the array of coordinates of that point) and compute its gradient (it should be stored in the second argument as an array).
Note: class ConjGradSolver thus does not add any new methods to the basic MinProblemSolver interface.
Note: term criteria should meet following condition:
termcrit.type == (TermCriteria::MAX_ITER + TermCriteria::EPS) && termcrit.epsilon > 0 && termcrit.maxCount > 0
// or
termcrit.type == TermCriteria::MAX_ITER) && termcrit.maxCount > 0
Implementations§
source§impl ConjGradSolver
impl ConjGradSolver
sourcepub fn create(
f: &Ptr<MinProblemSolver_Function>,
termcrit: TermCriteria
) -> Result<Ptr<ConjGradSolver>>
pub fn create( f: &Ptr<MinProblemSolver_Function>, termcrit: TermCriteria ) -> Result<Ptr<ConjGradSolver>>
This function returns the reference to the ready-to-use ConjGradSolver object.
All the parameters are optional, so this procedure can be called even without parameters at all. In this case, the default values will be used. As default value for terminal criteria are the only sensible ones, MinProblemSolver::setFunction() should be called upon the obtained object, if the function was not given to create(). Otherwise, the two ways (submit it to create() or miss it out and call the MinProblemSolver::setFunction()) are absolutely equivalent (and will drop the same errors in the same way, should invalid input be detected).
§Parameters
- f: Pointer to the function that will be minimized, similarly to the one you submit via MinProblemSolver::setFunction.
- termcrit: Terminal criteria to the algorithm, similarly to the one you submit via MinProblemSolver::setTermCriteria.
§C++ default parameters
- f: PtrConjGradSolver::Function()
- termcrit: TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,5000,0.000001)
sourcepub fn create_def() -> Result<Ptr<ConjGradSolver>>
pub fn create_def() -> Result<Ptr<ConjGradSolver>>
This function returns the reference to the ready-to-use ConjGradSolver object.
All the parameters are optional, so this procedure can be called even without parameters at all. In this case, the default values will be used. As default value for terminal criteria are the only sensible ones, MinProblemSolver::setFunction() should be called upon the obtained object, if the function was not given to create(). Otherwise, the two ways (submit it to create() or miss it out and call the MinProblemSolver::setFunction()) are absolutely equivalent (and will drop the same errors in the same way, should invalid input be detected).
§Parameters
- f: Pointer to the function that will be minimized, similarly to the one you submit via MinProblemSolver::setFunction.
- termcrit: Terminal criteria to the algorithm, similarly to the one you submit via MinProblemSolver::setTermCriteria.
§Note
This alternative version of ConjGradSolver::create function uses the following default values for its arguments:
- f: PtrConjGradSolver::Function()
- termcrit: TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,5000,0.000001)
Trait Implementations§
source§impl AlgorithmTrait for ConjGradSolver
impl AlgorithmTrait for ConjGradSolver
source§impl AlgorithmTraitConst for ConjGradSolver
impl AlgorithmTraitConst for ConjGradSolver
fn as_raw_Algorithm(&self) -> *const c_void
source§fn write(&self, fs: &mut impl FileStorageTrait) -> Result<()>
fn write(&self, fs: &mut impl FileStorageTrait) -> Result<()>
source§fn write_1(&self, fs: &mut impl FileStorageTrait, name: &str) -> Result<()>
fn write_1(&self, fs: &mut impl FileStorageTrait, name: &str) -> Result<()>
source§fn write_with_name(&self, fs: &Ptr<FileStorage>, name: &str) -> Result<()>
fn write_with_name(&self, fs: &Ptr<FileStorage>, name: &str) -> Result<()>
source§fn write_with_name_def(&self, fs: &Ptr<FileStorage>) -> Result<()>
fn write_with_name_def(&self, fs: &Ptr<FileStorage>) -> Result<()>
§Note
source§fn empty(&self) -> Result<bool>
fn empty(&self) -> Result<bool>
source§fn save(&self, filename: &str) -> Result<()>
fn save(&self, filename: &str) -> Result<()>
source§fn get_default_name(&self) -> Result<String>
fn get_default_name(&self) -> Result<String>
source§impl Boxed for ConjGradSolver
impl Boxed for ConjGradSolver
source§unsafe fn from_raw(
ptr: <ConjGradSolver as OpenCVFromExtern>::ExternReceive
) -> Self
unsafe fn from_raw( ptr: <ConjGradSolver as OpenCVFromExtern>::ExternReceive ) -> Self
source§fn into_raw(
self
) -> <ConjGradSolver as OpenCVTypeExternContainer>::ExternSendMut
fn into_raw( self ) -> <ConjGradSolver as OpenCVTypeExternContainer>::ExternSendMut
source§fn as_raw(&self) -> <ConjGradSolver as OpenCVTypeExternContainer>::ExternSend
fn as_raw(&self) -> <ConjGradSolver as OpenCVTypeExternContainer>::ExternSend
source§fn as_raw_mut(
&mut self
) -> <ConjGradSolver as OpenCVTypeExternContainer>::ExternSendMut
fn as_raw_mut( &mut self ) -> <ConjGradSolver as OpenCVTypeExternContainer>::ExternSendMut
source§impl ConjGradSolverTrait for ConjGradSolver
impl ConjGradSolverTrait for ConjGradSolver
fn as_raw_mut_ConjGradSolver(&mut self) -> *mut c_void
source§impl ConjGradSolverTraitConst for ConjGradSolver
impl ConjGradSolverTraitConst for ConjGradSolver
fn as_raw_ConjGradSolver(&self) -> *const c_void
source§impl Debug for ConjGradSolver
impl Debug for ConjGradSolver
source§impl Drop for ConjGradSolver
impl Drop for ConjGradSolver
source§impl From<ConjGradSolver> for Algorithm
impl From<ConjGradSolver> for Algorithm
source§fn from(s: ConjGradSolver) -> Self
fn from(s: ConjGradSolver) -> Self
source§impl From<ConjGradSolver> for MinProblemSolver
impl From<ConjGradSolver> for MinProblemSolver
source§fn from(s: ConjGradSolver) -> Self
fn from(s: ConjGradSolver) -> Self
source§impl MinProblemSolverTrait for ConjGradSolver
impl MinProblemSolverTrait for ConjGradSolver
fn as_raw_mut_MinProblemSolver(&mut self) -> *mut c_void
source§fn set_function(&mut self, f: &Ptr<MinProblemSolver_Function>) -> Result<()>
fn set_function(&mut self, f: &Ptr<MinProblemSolver_Function>) -> Result<()>
source§fn set_term_criteria(&mut self, termcrit: TermCriteria) -> Result<()>
fn set_term_criteria(&mut self, termcrit: TermCriteria) -> Result<()>
source§impl MinProblemSolverTraitConst for ConjGradSolver
impl MinProblemSolverTraitConst for ConjGradSolver
fn as_raw_MinProblemSolver(&self) -> *const c_void
source§fn get_function(&self) -> Result<Ptr<MinProblemSolver_Function>>
fn get_function(&self) -> Result<Ptr<MinProblemSolver_Function>>
source§fn get_term_criteria(&self) -> Result<TermCriteria>
fn get_term_criteria(&self) -> Result<TermCriteria>
source§impl TryFrom<Algorithm> for ConjGradSolver
impl TryFrom<Algorithm> for ConjGradSolver
source§impl TryFrom<MinProblemSolver> for ConjGradSolver
impl TryFrom<MinProblemSolver> for ConjGradSolver
impl Send for ConjGradSolver
Auto Trait Implementations§
impl Freeze for ConjGradSolver
impl RefUnwindSafe for ConjGradSolver
impl !Sync for ConjGradSolver
impl Unpin for ConjGradSolver
impl UnwindSafe for ConjGradSolver
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Mat> ModifyInplace for Matwhere
Mat: Boxed,
impl<Mat> ModifyInplace for Matwhere
Mat: Boxed,
source§unsafe fn modify_inplace<Res>(
&mut self,
f: impl FnOnce(&Mat, &mut Mat) -> Res
) -> Res
unsafe fn modify_inplace<Res>( &mut self, f: impl FnOnce(&Mat, &mut Mat) -> Res ) -> Res
Mat
or another similar object. By passing
a mutable reference to the Mat
to this function your closure will get called with the read reference and a write references
to the same Mat
. This is of course unsafe as it breaks the Rust aliasing rules, but it might be useful for some performance
sensitive operations. One example of an OpenCV function that allows such in-place modification is imgproc::threshold
. Read more