Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-tnnmg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
agnumpde
dune-tnnmg
Commits
ceadb798
Commit
ceadb798
authored
Jun 8, 2015
by
Oliver Sander
Browse files
Options
Downloads
Patches
Plain Diff
Implement test for the directionalSubDiff method
parent
1aaeea68
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
dune/tnnmg/functionals/test/functionaltest.hh
+33
-1
33 additions, 1 deletion
dune/tnnmg/functionals/test/functionaltest.hh
with
33 additions
and
1 deletion
dune/tnnmg/functionals/test/functionaltest.hh
+
33
−
1
View file @
ceadb798
...
@@ -245,7 +245,39 @@ template <class Functional>
...
@@ -245,7 +245,39 @@ template <class Functional>
void
testDirectionalSubdifferential
(
const
Functional
&
functional
,
void
testDirectionalSubdifferential
(
const
Functional
&
functional
,
const
std
::
vector
<
typename
Functional
::
VectorType
>&
testPoints
)
const
std
::
vector
<
typename
Functional
::
VectorType
>&
testPoints
)
{
{
// TODO: Implement me!
// Step size. Best value: square root of the machine precision
const
double
eps
=
std
::
sqrt
(
std
::
numeric_limits
<
double
>::
epsilon
());
// Loop over all test points
for
(
auto
&&
testPoint
:
testPoints
)
{
// Abuse test points also as test directions
for
(
auto
&&
testDirection
:
testPoints
)
{
Solvers
::
Interval
<
double
>
subDifferential
;
functional
.
directionalSubDiff
(
testPoint
,
testDirection
,
subDifferential
);
auto
forwardPoint
=
testPoint
;
forwardPoint
.
axpy
(
eps
,
testDirection
);
auto
backwardPoint
=
testPoint
;
backwardPoint
.
axpy
(
-
eps
,
testDirection
);
auto
forwardFDGradient
=
(
functional
(
forwardPoint
)
-
functional
(
testPoint
))
/
eps
;
auto
backwardFDGradient
=
(
functional
(
testPoint
)
-
functional
(
backwardPoint
))
/
eps
;
if
(
std
::
abs
(
backwardFDGradient
-
subDifferential
[
0
])
>
100
*
eps
or
std
::
abs
(
forwardFDGradient
-
subDifferential
[
1
])
>
100
*
eps
)
{
std
::
cout
<<
"Bug in directionalSubDiff for functional type "
<<
Dune
::
className
<
Functional
>
()
<<
":"
<<
std
::
endl
;
std
::
cerr
<<
"Subdifferential doesn't match FD approximation"
<<
std
::
endl
;
std
::
cerr
<<
"SubDifferential: "
<<
subDifferential
<<
", FD: ["
<<
backwardFDGradient
<<
", "
<<
forwardFDGradient
<<
"]"
<<
std
::
endl
;
std
::
cerr
<<
"Test point:"
<<
std
::
endl
<<
testPoint
<<
std
::
endl
;
std
::
cerr
<<
"Test direction:"
<<
std
::
endl
<<
testDirection
<<
std
::
endl
;
DUNE_THROW
(
MathError
,
""
);
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment