Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
CoMISo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
4
Issues
4
List
Boards
Labels
Service Desk
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
CoMISo
CoMISo
Commits
fd25b225
Commit
fd25b225
authored
May 18, 2018
by
Patrick Schmidt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
NPDerivativeChecker: Checking at given x.
parent
14860d7a
Pipeline
#6997
failed with stages
in 2 minutes and 31 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
17 deletions
+24
-17
NSolver/NPDerivativeChecker.hh
NSolver/NPDerivativeChecker.hh
+24
-17
No files found.
NSolver/NPDerivativeChecker.hh
View file @
fd25b225
...
...
@@ -61,36 +61,40 @@ public:
};
template
<
class
ProblemInterface
>
bool
check_all
(
ProblemInterface
*
_np
,
double
_dx
,
double
_eps
)
bool
check_all
(
ProblemInterface
*
_np
,
const
double
*
_x
,
double
_dx
,
double
_eps
)
{
conf_
.
dx
=
_dx
;
conf_
.
eps
=
_eps
;
return
check_all
(
_np
);
return
check_all
(
_np
,
_x
);
}
template
<
class
ProblemInterface
>
bool
check_all
(
ProblemInterface
*
_np
)
bool
check_all
(
ProblemInterface
*
_np
,
const
double
*
_x
)
{
bool
d1_ok
=
check_d1
(
_np
);
bool
d2_ok
=
check_d2
(
_np
);
bool
d1_ok
=
check_d1
(
_np
,
_x
);
bool
d2_ok
=
check_d2
(
_np
,
_x
);
return
(
d1_ok
&&
d2_ok
);
}
template
<
class
ProblemInterface
>
bool
check_d1
(
ProblemInterface
*
_np
)
bool
check_d1
(
ProblemInterface
*
_np
,
const
double
*
_x
)
{
int
n_ok
=
0
;
int
n_errors
=
0
;
int
n
=
_np
->
n_unknowns
();
std
::
vector
<
double
>
x
(
n
),
g
(
n
);
std
::
vector
<
double
>
x
(
n
);
// Copy x because we don't want to change the input
for
(
int
i
=
0
;
i
<
n
;
++
i
)
x
[
i
]
=
_x
[
i
];
for
(
int
i
=
0
;
i
<
conf_
.
n_iters
;
++
i
)
{
std
::
vector
<
double
>
g
(
n
);
// for(int i=0; i<conf_.n_iters; ++i)
// {
// get random x
get_random_x
(
x
,
conf_
.
x_min
,
conf_
.
x_max
);
//
get_random_x(x, conf_.x_min, conf_.x_max);
// gradient
_np
->
eval_gradient
(
P
(
x
),
P
(
g
));
...
...
@@ -111,7 +115,7 @@ public:
<<
" should be "
<<
fd
<<
" ("
<<
std
::
abs
(
fd
-
g
[
j
])
<<
")"
<<
std
::
endl
;
}
else
++
n_ok
;
}
//
}
}
std
::
cerr
<<
"############## Gradient Checker Summary #############
\n
"
;
...
...
@@ -125,19 +129,22 @@ public:
inline
double
getCoeff
(
const
MatrixType
&
m
,
int
r
,
int
c
);
template
<
class
ProblemInterface
>
bool
check_d2
(
ProblemInterface
*
_np
)
bool
check_d2
(
ProblemInterface
*
_np
,
const
double
*
_x
)
{
int
n_ok
=
0
;
int
n_errors
=
0
;
int
n
=
_np
->
n_unknowns
();
std
::
vector
<
double
>
x
(
n
);
std
::
vector
<
double
>
x
(
n
);
// Copy x because we don't want to change the input
for
(
int
i
=
0
;
i
<
n
;
++
i
)
x
[
i
]
=
_x
[
i
];
typename
ProblemInterface
::
SMatrixNP
H
(
n
,
n
);
for
(
int
i
=
0
;
i
<
conf_
.
n_iters
;
++
i
)
{
//
for(int i=0; i<conf_.n_iters; ++i)
//
{
// get random x
get_random_x
(
x
,
conf_
.
x_min
,
conf_
.
x_max
);
//
get_random_x(x, conf_.x_min, conf_.x_max);
// gradient
_np
->
eval_hessian
(
P
(
x
),
H
);
...
...
@@ -167,7 +174,7 @@ public:
<<
", relative delta:"
<<
(
std
::
abs
(
fd
-
getCoeff
(
H
,
j
,
k
))
/
std
::
max
(
std
::
abs
(
getCoeff
(
H
,
j
,
k
)),
1.0
))
<<
")"
<<
std
::
endl
;
}
else
++
n_ok
;
}
//
}
}
std
::
cerr
<<
"############## Hessian Checker Summary #############
\n
"
;
...
...
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