Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
miscmaths
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
FSL
miscmaths
Commits
274304ce
Commit
274304ce
authored
20 years ago
by
Mark Woolrich
Browse files
Options
Downloads
Patches
Plain Diff
*** empty log message ***
parent
5156ef12
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
minimize.cc
+4
-5
4 additions, 5 deletions
minimize.cc
minimize.h
+19
-5
19 additions, 5 deletions
minimize.h
with
23 additions
and
10 deletions
minimize.cc
+
4
−
5
View file @
274304ce
...
...
@@ -171,7 +171,7 @@ ReturnMatrix gradient(const ColumnVector& x, const EvalFunction& func, float h,i
return
deriv
;
}
ReturnMatrix
hessian
(
const
ColumnVector
&
x
,
const
EvalFunction
&
func
,
float
h
,
int
errorord
)
ReturnMatrix
hessian
(
const
ColumnVector
&
x
,
const
EvalFunction
&
func
,
ColumnVector
&
paramstovaryflags
,
float
h
,
int
errorord
)
{
//evaluates the hessian of function "eval" at x in parameter space
//errorord=4 requires something like 8n^2-3n evaluations
...
...
@@ -191,7 +191,7 @@ ReturnMatrix hessian(const ColumnVector& x, const EvalFunction& func, float h,in
}
void
minsearch
(
ColumnVector
&
x
,
const
EvalFunction
&
func
){
void
minsearch
(
ColumnVector
&
x
,
const
EvalFunction
&
func
,
ColumnVector
&
paramstovaryflags
){
//perform generic function minimization without gradient info
int
n
=
x
.
Nrows
(),
maxiter
=
200
*
n
,
iter
=
0
;
int
func_evals
=
0
;
...
...
@@ -344,11 +344,10 @@ void minsearch(ColumnVector& x, const EvalFunction& func){
}
//closing while
x
=
v
[
0
].
second
;
}
void
scg
(
ColumnVector
&
x
,
const
gEvalFunction
&
func
,
float
tol
,
float
eps
,
int
niters
){
void
scg
(
ColumnVector
&
x
,
const
gEvalFunction
&
func
,
ColumnVector
&
paramstovaryflags
,
float
tol
,
float
eps
,
int
niters
){
int
fevals
=
0
;
int
gevals
=
0
;
...
...
This diff is collapsed.
Click to expand it.
minimize.h
+
19
−
5
View file @
274304ce
...
...
@@ -52,11 +52,11 @@ float diff2(const ColumnVector& x, const EvalFunction& func, int i,int j,float h
ReturnMatrix
gradient
(
const
ColumnVector
&
x
,
const
EvalFunction
&
func
,
float
h
,
int
errorord
=
4
);
// finite diff derivative vector
ReturnMatrix
hessian
(
const
ColumnVector
&
x
,
const
EvalFunction
&
func
,
float
h
,
int
errorord
=
4
);
// finite diff hessian
ReturnMatrix
hessian
(
const
ColumnVector
&
x
,
const
EvalFunction
&
func
,
ColumnVector
&
paramstovaryflags
,
float
h
,
int
errorord
=
4
);
// finite diff hessian
void
minsearch
(
ColumnVector
&
x
,
const
EvalFunction
&
func
);
void
minsearch
(
ColumnVector
&
x
,
const
EvalFunction
&
func
,
ColumnVector
&
paramstovaryflags
);
void
scg
(
ColumnVector
&
x
,
const
gEvalFunction
&
func
,
float
tol
=
0.0000001
,
float
eps
=
1e-16
,
int
niters
=
100
);
void
scg
(
ColumnVector
&
x
,
const
gEvalFunction
&
func
,
ColumnVector
&
paramstovaryflags
,
float
tol
=
0.0000001
,
float
eps
=
1e-16
,
int
niters
=
100
);
class
EvalFunction
{
//Function where gradient is not analytic (or you are too lazy to work it out) (required for fminsearch)
...
...
@@ -67,7 +67,14 @@ public:
virtual
void
minimize
(
ColumnVector
&
x
)
{
minsearch
(
x
,
*
this
);
ColumnVector
paramstovaryflags
(
x
.
Nrows
());
paramstovaryflags
=
1
;
minsearch
(
x
,
*
this
,
paramstovaryflags
);
}
virtual
void
minimize
(
ColumnVector
&
x
,
ColumnVector
&
paramstovaryflags
)
{
minsearch
(
x
,
*
this
,
paramstovaryflags
);
}
private
:
...
...
@@ -86,7 +93,14 @@ public:
virtual
void
minimize
(
ColumnVector
&
x
)
{
scg
(
x
,
*
this
);
ColumnVector
paramstovaryflags
(
x
.
Nrows
());
paramstovaryflags
=
1
;
scg
(
x
,
*
this
,
paramstovaryflags
);
}
virtual
void
minimize
(
ColumnVector
&
x
,
ColumnVector
&
paramstovaryflags
)
{
scg
(
x
,
*
this
,
paramstovaryflags
);
}
private
:
...
...
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