From ee92a36123eb7bc2e08e586fe97d43e3cc13d332 Mon Sep 17 00:00:00 2001 From: Eugene Khvedchenya Date: Tue, 29 Mar 2016 11:09:54 +0300 Subject: [PATCH] Added parallel implementation of compute_gradient method. --- modules/ml/src/lr.cpp | 45 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/modules/ml/src/lr.cpp b/modules/ml/src/lr.cpp index 585162cf98..5464d25c7e 100644 --- a/modules/ml/src/lr.cpp +++ b/modules/ml/src/lr.cpp @@ -362,6 +362,42 @@ double LogisticRegressionImpl::compute_cost(const Mat& _data, const Mat& _labels return cost; } +struct LogisticRegressionImpl_ComputeDradient_Impl : ParallelLoopBody +{ + const Mat* data; + const Mat* theta; + const Mat* pcal_a; + Mat* gradient; + double lambda; + + LogisticRegressionImpl_ComputeDradient_Impl(const Mat& _data, const Mat &_theta, const Mat& _pcal_a, const double _lambda, Mat & _gradient) + : data(&_data) + , theta(&_theta) + , pcal_a(&_pcal_a) + , gradient(&_gradient) + , lambda(_lambda) + { + + } + + void operator()(const cv::Range& r) const + { + const Mat& _data = *data; + const Mat &_theta = *theta; + Mat & _gradient = *gradient; + const Mat & _pcal_a = *pcal_a; + const int m = _data.rows; + Mat pcal_ab; + + for (int ii = r.start; ii