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
7d70e12c
Commit
7d70e12c
authored
20 years ago
by
Tim Behrens
Browse files
Options
Downloads
Patches
Plain Diff
Fixed minsearch problem with non-varying parameters
parent
d6a81240
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
minimize.cc
+9
-12
9 additions, 12 deletions
minimize.cc
with
9 additions
and
12 deletions
minimize.cc
+
9
−
12
View file @
7d70e12c
...
@@ -212,17 +212,18 @@ void minsearch(ColumnVector& x, const EvalFunction& func, ColumnVector& paramsto
...
@@ -212,17 +212,18 @@ void minsearch(ColumnVector& x, const EvalFunction& func, ColumnVector& paramsto
}
}
}
}
//Number of parameters to estimate
//Number of parameters to estimate
int
n
=
x
.
Nrows
()
-
n_nonvary
,
maxiter
=
200
*
n
,
iter
=
0
;
int
n
=
x
.
Nrows
()
-
n_nonvary
,
maxiter
=
200
*
n
,
iter
=
0
;
int
ntot
=
x
.
Nrows
();
int
func_evals
=
0
;
int
func_evals
=
0
;
// Some things we'll need.
// Some things we'll need.
float
rho
=
1
,
chi
=
2
,
psi
=
0.5
,
sigma
=
0.5
;
float
rho
=
1
,
chi
=
2
,
psi
=
0.5
,
sigma
=
0.5
;
float
tolx
=
1e-6
,
tolf
=
1e-6
;
float
tolx
=
1e-6
,
tolf
=
1e-6
;
ColumnVector
onesn
(
n
);
ColumnVector
onesn
(
n
tot
);
onesn
=
1
;
onesn
=
1
;
ColumnVector
one2n
(
n
),
two2np1
(
n
);
ColumnVector
one2n
(
n
tot
),
two2np1
(
n
tot
);
for
(
int
i
=
1
;
i
<=
n
;
i
++
){
for
(
int
i
=
1
;
i
<=
n
tot
;
i
++
){
one2n
(
i
)
=
i
;
one2n
(
i
)
=
i
;
two2np1
(
i
)
=
i
+
1
;
two2np1
(
i
)
=
i
+
1
;
}
}
...
@@ -241,15 +242,14 @@ void minsearch(ColumnVector& x, const EvalFunction& func, ColumnVector& paramsto
...
@@ -241,15 +242,14 @@ void minsearch(ColumnVector& x, const EvalFunction& func, ColumnVector& paramsto
float
usual_delta
=
0.05
,
zero_term_delta
=
0.00025
;
float
usual_delta
=
0.05
,
zero_term_delta
=
0.00025
;
//perturb each parameter by a bit, and store the cost.
//perturb each parameter by a bit, and store the cost.
ColumnVector
y
;
ColumnVector
y
=
x
;
for
(
int
i
=
1
;
i
<=
n
;
i
++
){
for
(
int
i
=
1
;
i
<=
n
;
i
++
){
// The values of nonvarying parameters should be the same in
// The values of nonvarying parameters should be the same in
// all of the optional param vectors and therefore in all
// all of the optional param vectors and therefore in all
// combinations of them in the remainder of the code.
// combinations of them in the remainder of the code.
if
(
paramstovary
(
i
)
==
1
){
if
(
paramstovary
(
i
)
==
1
){
y
=
x
;
if
(
y
(
i
)
!=
0
){
y
(
i
)
=
(
1
+
usual_delta
)
*
y
(
i
);}
if
(
y
(
i
)
!=
0
){
y
(
i
)
=
(
1
+
usual_delta
)
*
y
(
i
);}
else
{
y
(
i
)
=
(
1
+
zero_term_delta
);}
else
{
y
(
i
)
=
(
1
+
zero_term_delta
);}
en
=
func
.
evaluate
(
y
);
en
=
func
.
evaluate
(
y
);
...
@@ -265,12 +265,10 @@ void minsearch(ColumnVector& x, const EvalFunction& func, ColumnVector& paramsto
...
@@ -265,12 +265,10 @@ void minsearch(ColumnVector& x, const EvalFunction& func, ColumnVector& paramsto
sort
(
v
.
begin
(),
v
.
end
(),
pair_comparer
());
//wasn't that easy...
sort
(
v
.
begin
(),
v
.
end
(),
pair_comparer
());
//wasn't that easy...
string
how
=
""
;
string
how
=
""
;
ColumnVector
xbar
(
n
),
xr
(
n
),
xe
(
n
),
xc
(
n
),
xcc
(
n
),
xtmp
(
n
);
ColumnVector
xbar
(
ntot
),
xr
(
ntot
),
xe
(
ntot
),
xc
(
ntot
),
xcc
(
ntot
),
xtmp
(
ntot
);
//cerr<<"starting loop"<<endl;
//cerr<<"starting loop"<<endl;
while
(
iter
<=
maxiter
){
while
(
iter
<=
maxiter
){
iter
++
;
iter
++
;
if
(
v
[
n
].
first
-
v
[
0
].
first
<
tolf
){
if
(
v
[
n
].
first
-
v
[
0
].
first
<
tolf
){
ColumnVector
tmpvec1
,
tmpvec2
;
ColumnVector
tmpvec1
,
tmpvec2
;
bool
stopsearch
=
true
;
bool
stopsearch
=
true
;
...
@@ -283,7 +281,6 @@ void minsearch(ColumnVector& x, const EvalFunction& func, ColumnVector& paramsto
...
@@ -283,7 +281,6 @@ void minsearch(ColumnVector& x, const EvalFunction& func, ColumnVector& paramsto
}
}
if
(
stopsearch
){
break
;}
if
(
stopsearch
){
break
;}
}
}
//compute reflection point
//compute reflection point
// xbar is average of best n paramsets.
// xbar is average of best n paramsets.
...
@@ -294,7 +291,7 @@ void minsearch(ColumnVector& x, const EvalFunction& func, ColumnVector& paramsto
...
@@ -294,7 +291,7 @@ void minsearch(ColumnVector& x, const EvalFunction& func, ColumnVector& paramsto
xbar
=
xbar
/
n
;
xbar
=
xbar
/
n
;
xr
=
(
1
+
rho
)
*
xbar
-
rho
*
v
[
n
].
second
;
//reflection point
xr
=
(
1
+
rho
)
*
xbar
-
rho
*
v
[
n
].
second
;
//reflection point
float
en_xr
=
func
.
evaluate
(
xr
);
func_evals
++
;
float
en_xr
=
func
.
evaluate
(
xr
);
func_evals
++
;
if
(
en_xr
<
v
[
0
].
first
){
//en_xr is better than our current best
if
(
en_xr
<
v
[
0
].
first
){
//en_xr is better than our current best
//compute expansion point
//compute expansion point
xe
=
(
1
+
rho
*
chi
)
*
xbar
-
rho
*
chi
*
v
[
n
].
second
;
xe
=
(
1
+
rho
*
chi
)
*
xbar
-
rho
*
chi
*
v
[
n
].
second
;
...
...
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