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
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
agnumpde
dune-tectonic
Commits
1ee8f2a4
Commit
1ee8f2a4
authored
Oct 31, 2011
by
Elias Pipping
Committed by
Elias Pipping
Oct 31, 2011
Browse files
Options
Downloads
Patches
Plain Diff
Have minimise() make multiple steps
parent
9680be4d
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/myblockproblem.hh
+2
-4
2 additions, 4 deletions
src/myblockproblem.hh
src/samplefunctional.hh
+44
-43
44 additions, 43 deletions
src/samplefunctional.hh
src/test-gradient-method.cc
+1
-7
1 addition, 7 deletions
src/test-gradient-method.cc
with
47 additions
and
54 deletions
src/myblockproblem.hh
+
2
−
4
View file @
1ee8f2a4
...
@@ -32,6 +32,7 @@ template <class MyConvexProblemTypeTEMPLATE> class MyBlockProblem {
...
@@ -32,6 +32,7 @@ template <class MyConvexProblemTypeTEMPLATE> class MyBlockProblem {
class
IterateObject
;
class
IterateObject
;
MyBlockProblem
(
MyConvexProblemType
&
problem
)
:
problem
(
problem
)
{
MyBlockProblem
(
MyConvexProblemType
&
problem
)
:
problem
(
problem
)
{
// TODO: Is it clever to create a bisection here?
bisection
=
Bisection
(
0.0
,
1.0
,
1e-15
,
true
,
1e-14
);
bisection
=
Bisection
(
0.0
,
1.0
,
1e-15
,
true
,
1e-14
);
};
};
...
@@ -118,10 +119,7 @@ class MyBlockProblem<MyConvexProblemTypeTEMPLATE>::IterateObject {
...
@@ -118,10 +119,7 @@ class MyBlockProblem<MyConvexProblemTypeTEMPLATE>::IterateObject {
Dune
::
SampleFunctional
<
block_size
>
localJ
(
*
localA
,
localb
,
phi
);
Dune
::
SampleFunctional
<
block_size
>
localJ
(
*
localA
,
localb
,
phi
);
LocalVectorType
correction
;
LocalVectorType
correction
;
for
(
size_t
i
=
1
;
i
<=
10
;
++
i
)
{
// FIXME: hardcoded value
Dune
::
minimise
(
localJ
,
ui
,
10
);
// FIXME: hardcoded value
Dune
::
minimise
(
localJ
,
ui
,
correction
);
ui
+=
correction
;
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/samplefunctional.hh
+
44
−
43
View file @
1ee8f2a4
...
@@ -118,8 +118,8 @@ template <int dimension> class SampleFunctional {
...
@@ -118,8 +118,8 @@ template <int dimension> class SampleFunctional {
};
};
template
<
class
Functional
>
template
<
class
Functional
>
void
minimise
(
const
Functional
J
,
const
typename
Functional
::
SmallVector
x
,
void
minimise
(
const
Functional
J
,
typename
Functional
::
SmallVector
&
x
,
typename
Functional
::
SmallVector
&
corr
,
size_t
steps
=
1
,
Bisection
const
&
bisection
=
Bisection
const
&
bisection
=
Bisection
(
0.0
,
// acceptError: Stop if the search interval has
Bisection
(
0.0
,
// acceptError: Stop if the search interval has
// become smaller than this number
// become smaller than this number
...
@@ -130,13 +130,13 @@ void minimise(const Functional J, const typename Functional::SmallVector x,
...
@@ -130,13 +130,13 @@ void minimise(const Functional J, const typename Functional::SmallVector x,
// minimization
// minimization
{
{
typedef
typename
Functional
::
SmallVector
SmallVector
;
typedef
typename
Functional
::
SmallVector
SmallVector
;
for
(
size_t
step
=
0
;
step
<
steps
;
++
step
)
{
SmallVector
descDir
;
SmallVector
descDir
;
J
.
descentDirection
(
x
,
descDir
);
J
.
descentDirection
(
x
,
descDir
);
if
(
descDir
==
SmallVector
(
0.0
))
{
if
(
descDir
==
SmallVector
(
0.0
))
corr
=
SmallVector
(
0.0
);
return
;
return
;
}
// {{{ Construct a restriction of J to the line x + t * descDir
// {{{ Construct a restriction of J to the line x + t * descDir
...
@@ -167,22 +167,23 @@ void minimise(const Functional J, const typename Functional::SmallVector x,
...
@@ -167,22 +167,23 @@ void minimise(const Functional J, const typename Functional::SmallVector x,
Interval
<
double
>
D
;
Interval
<
double
>
D
;
JRest
.
subDiff
(
0
,
D
);
JRest
.
subDiff
(
0
,
D
);
dverb
dverb
<<
"## Directional derivative (as per subdifferential of "
<<
"## Directional derivative (as per subdifferential of
restriction)
:
"
"restriction): "
<<
D
[
1
]
<<
" (coordinates of the
restriction)"
<<
D
[
1
]
<<
" (coordinates of the restriction)"
<<
std
::
endl
;
<<
std
::
endl
;
assert
(
D
[
1
]
<=
assert
(
D
[
1
]
<=
0
);
// We should not be minimising in this direction otherwise
0
);
// We should not be minimising in this direction otherwise
}
}
int
count
;
int
count
;
// FIXME: The value of x_old should not matter if the factor is 1.0, correct?
// FIXME: The value of x_old should not matter if the factor is 1.0,
// correct?
double
const
stepsize
=
bisection
.
minimize
(
JRest
,
0.0
,
1.0
,
count
);
double
const
stepsize
=
bisection
.
minimize
(
JRest
,
0.0
,
1.0
,
count
);
dverb
<<
"Number of iterations in the bisection method: "
<<
count
dverb
<<
"Number of iterations in the bisection method: "
<<
count
<<
std
::
endl
;
<<
std
::
endl
;
;
;
corr
=
descDir
;
x
.
axpy
(
stepsize
,
descDir
)
;
corr
*=
stepsize
;
}
}
}
}
}
#endif
#endif
This diff is collapsed.
Click to expand it.
src/test-gradient-method.cc
+
1
−
7
View file @
1ee8f2a4
...
@@ -15,14 +15,8 @@ template <int dim>
...
@@ -15,14 +15,8 @@ template <int dim>
double
functionTester
(
Dune
::
SampleFunctional
<
dim
>
J
,
double
functionTester
(
Dune
::
SampleFunctional
<
dim
>
J
,
typename
Dune
::
SampleFunctional
<
dim
>::
SmallVector
&
start
,
typename
Dune
::
SampleFunctional
<
dim
>::
SmallVector
&
start
,
size_t
runs
)
{
size_t
runs
)
{
typename
Dune
::
SampleFunctional
<
dim
>::
SmallVector
correction
;
std
::
cout
<<
"Old value: J(...) = "
<<
J
(
start
)
<<
std
::
endl
;
std
::
cout
<<
"Old value: J(...) = "
<<
J
(
start
)
<<
std
::
endl
;
for
(
size_t
i
=
1
;
i
<=
runs
;
++
i
)
{
Dune
::
minimise
(
J
,
start
,
runs
);
Dune
::
minimise
(
J
,
start
,
correction
);
start
+=
correction
;
if
(
i
!=
runs
)
std
::
cout
<<
"New value: J(...) = "
<<
J
(
start
)
<<
std
::
endl
;
}
double
const
final
=
J
(
start
);
double
const
final
=
J
(
start
);
std
::
cout
<<
"Final value J(...) = "
<<
final
<<
std
::
endl
;
std
::
cout
<<
"Final value J(...) = "
<<
final
<<
std
::
endl
;
return
final
;
return
final
;
...
...
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