Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-tectonic
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
podlesny
dune-tectonic
Commits
c50d4c1d
Commit
c50d4c1d
authored
13 years ago
by
Elias Pipping
Committed by
Elias Pipping
13 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Test horrible functions
parent
a5024f3b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/nicefunction.hh
+55
-0
55 additions, 0 deletions
src/nicefunction.hh
src/test-gradient-method.cc
+74
-0
74 additions, 0 deletions
src/test-gradient-method.cc
with
129 additions
and
0 deletions
src/nicefunction.hh
+
55
−
0
View file @
c50d4c1d
...
...
@@ -35,5 +35,60 @@ class TrivialFunction : public NiceFunction {
double
virtual
rightDifferential
(
const
double
)
const
{
return
0
;
}
};
// slope in [n-1,n] is n
class
HorribleFunction
:
public
NiceFunction
{
public:
void
virtual
evaluate
(
const
double
&
x
,
double
&
y
)
const
{
double
const
fl
=
floor
(
x
);
double
const
sum
=
fl
*
(
fl
+
1
)
/
2
;
y
=
sum
+
(
fl
+
1
)
*
(
x
-
fl
);
}
double
virtual
leftDifferential
(
const
double
x
)
const
{
double
const
fl
=
floor
(
x
);
if
(
x
-
fl
<
1e-14
)
return
fl
;
else
return
fl
+
1
;
}
double
virtual
rightDifferential
(
const
double
x
)
const
{
double
const
c
=
ceil
(
x
);
if
(
c
-
x
<
1e-14
)
return
c
+
1
;
else
return
c
;
}
};
// slope in [n-1,n] is log(n+1)
class
HorribleFunctionLogarithmic
:
public
NiceFunction
{
public:
void
virtual
evaluate
(
const
double
&
x
,
double
&
y
)
const
{
y
=
0
;
size_t
const
fl
=
floor
(
x
);
for
(
size_t
i
=
1
;
i
<=
fl
;)
y
+=
log
(
++
i
);
// factorials grow to fast so we compute this incrementally
y
+=
log
(
fl
+
2
)
*
(
x
-
fl
);
}
double
virtual
leftDifferential
(
const
double
x
)
const
{
double
const
fl
=
floor
(
x
);
if
(
x
-
fl
<
1e-14
)
return
log
(
fl
+
1
);
else
return
log
(
fl
+
2
);
}
double
virtual
rightDifferential
(
const
double
x
)
const
{
double
const
c
=
ceil
(
x
);
if
(
c
-
x
<
1e-14
)
return
log
(
c
+
2
);
else
return
log
(
c
+
1
);
}
};
}
#endif
This diff is collapsed.
Click to expand it.
src/test-gradient-method.cc
+
74
−
0
View file @
c50d4c1d
...
...
@@ -182,6 +182,76 @@ void testTrivialFunction() {
assert
(
std
::
abs
(
ret1
-
ret2
)
<
1e-5
);
}
void
testHorribleFunction
()
{
int
const
dim
=
2
;
typedef
Dune
::
SampleFunctional
<
dim
>
SampleFunctional
;
SampleFunctional
::
SmallMatrix
A
;
A
[
0
][
0
]
=
3
;
A
[
0
][
1
]
=
1.5
;
A
[
1
][
0
]
=
1.5
;
A
[
1
][
1
]
=
4
;
SampleFunctional
::
SmallVector
b
;
b
[
0
]
=
1
;
b
[
1
]
=
2
;
Dune
::
HorribleFunction
f
;
SampleFunctional
J
(
A
,
b
,
Dune
::
MyNonlinearity
<
dim
>
(
f
));
SampleFunctional
::
SmallVector
start
=
b
;
start
*=
17
;
double
const
ret1
=
functionTester
(
J
,
start
,
7
);
// Something random
start
[
0
]
=
279
;
start
[
1
]
=
-
96
;
double
const
ret2
=
functionTester
(
J
,
start
,
8
);
assert
(
std
::
abs
(
ret1
-
ret2
)
<
1e-5
);
start
[
0
]
=
0
;
start
[
1
]
=
0
;
double
const
ret3
=
functionTester
(
J
,
start
,
4
);
assert
(
std
::
abs
(
ret1
-
ret3
)
<
1e-5
);
}
void
testHorribleFunctionLogarithmic
()
{
int
const
dim
=
2
;
typedef
Dune
::
SampleFunctional
<
dim
>
SampleFunctional
;
SampleFunctional
::
SmallMatrix
A
;
A
[
0
][
0
]
=
3
;
A
[
0
][
1
]
=
1.5
;
A
[
1
][
0
]
=
1.5
;
A
[
1
][
1
]
=
4
;
SampleFunctional
::
SmallVector
b
;
b
[
0
]
=
1
;
b
[
1
]
=
2
;
Dune
::
HorribleFunctionLogarithmic
f
;
SampleFunctional
J
(
A
,
b
,
Dune
::
MyNonlinearity
<
dim
>
(
f
));
SampleFunctional
::
SmallVector
start
=
b
;
start
*=
17
;
double
const
ret1
=
functionTester
(
J
,
start
,
6
);
// Something random
start
[
0
]
=
279
;
start
[
1
]
=
-
96
;
double
const
ret2
=
functionTester
(
J
,
start
,
12
);
assert
(
std
::
abs
(
ret1
-
ret2
)
<
1e-5
);
start
[
0
]
=
0
;
start
[
1
]
=
0
;
double
const
ret3
=
functionTester
(
J
,
start
,
4
);
assert
(
std
::
abs
(
ret1
-
ret3
)
<
1e-5
);
}
int
main
()
{
try
{
testSampleFunction
();
...
...
@@ -189,6 +259,10 @@ int main() {
testSampleFunctionNonsmooth
();
std
::
cout
<<
std
::
endl
<<
std
::
endl
<<
std
::
endl
;
testTrivialFunction
();
std
::
cout
<<
std
::
endl
<<
std
::
endl
<<
std
::
endl
;
testHorribleFunction
();
std
::
cout
<<
std
::
endl
<<
std
::
endl
<<
std
::
endl
;
testHorribleFunctionLogarithmic
();
return
0
;
}
catch
(
Dune
::
Exception
&
e
)
{
...
...
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