Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
ee92a361
Commit
ee92a361
authored
Mar 29, 2016
by
Eugene Khvedchenya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added parallel implementation of compute_gradient method.
parent
1e1dc142
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
7 deletions
+38
-7
lr.cpp
modules/ml/src/lr.cpp
+38
-7
No files found.
modules/ml/src/lr.cpp
View file @
ee92a361
...
...
@@ -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
<
r
.
end
;
ii
++
)
{
Mat
pcal_b
=
_data
(
Range
::
all
(),
Range
(
ii
,
ii
+
1
));
multiply
(
_pcal_a
,
pcal_b
,
pcal_ab
,
1
);
_gradient
.
row
(
ii
)
=
(
1.0
/
m
)
*
sum
(
pcal_ab
)[
0
]
+
(
lambda
/
m
)
*
_theta
.
row
(
ii
);
}
}
};
void
LogisticRegressionImpl
::
compute_gradient
(
const
Mat
&
_data
,
const
Mat
&
_labels
,
const
Mat
&
_theta
,
const
double
_lambda
,
Mat
&
_gradient
)
{
...
...
@@ -379,13 +415,8 @@ void LogisticRegressionImpl::compute_gradient(const Mat& _data, const Mat& _labe
_gradient
.
row
(
0
)
=
((
float
)
1
/
m
)
*
sum
(
pcal_ab
)[
0
];
//cout<<"for each training data entry"<<endl;
for
(
int
ii
=
1
;
ii
<
_gradient
.
rows
;
ii
++
)
{
pcal_b
=
_data
(
Range
::
all
(),
Range
(
ii
,
ii
+
1
));
multiply
(
pcal_a
,
pcal_b
,
pcal_ab
,
1
);
_gradient
.
row
(
ii
)
=
(
1.0
/
m
)
*
sum
(
pcal_ab
)[
0
]
+
(
_lambda
/
m
)
*
_theta
.
row
(
ii
);
}
LogisticRegressionImpl_ComputeDradient_Impl
invoker
(
_data
,
_theta
,
pcal_a
,
_lambda
,
_gradient
);
cv
::
parallel_for_
(
cv
::
Range
(
1
,
_gradient
.
rows
),
invoker
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment