Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ackley_mc
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
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Torda, Prof. Dr. Andrew Ernest
ackley_mc
Commits
c619eb28
Commit
c619eb28
authored
Jan 6, 2022
by
Andrew E. Torda
Browse files
Options
Downloads
Patches
Plain Diff
Working well and the test9d with plots look very pretty.
parent
f9136d0f
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
ackwork/ackwork_test.go
+14
-3
14 additions, 3 deletions
ackwork/ackwork_test.go
ackwork/dorun.go
+16
-10
16 additions, 10 deletions
ackwork/dorun.go
with
30 additions
and
13 deletions
ackwork/ackwork_test.go
+
14
−
3
View file @
c619eb28
...
@@ -108,17 +108,28 @@ func TestCsv(t *testing.T) {
...
@@ -108,17 +108,28 @@ func TestCsv(t *testing.T) {
}
}
}
}
var
s
1
dplot
=
`
var
s
9
dplot
=
`
ini_temp 0.0925
ini_temp 0.0925
final_temp 0.09
final_temp 0.09
x_ini 15,10,11,12,14,18,-12,-8,-9
x_ini 15,10,11,12,14,18,-12,-8,-9
n_step 1000
n_step 50000
x_delta 0.2
fOutName test9d
fOutName test9d
fPltName testplot.svg
fPltName testplot.svg
xPltName testrajplt`
xPltName testrajplt`
var
s9bdplot
=
`
ini_temp 0.0925
final_temp 0.09
x_ini 15,10,11,12,14,0,-12,-8,-9
n_step 50000
x_delta 0.2
fOutName test9db
fPltName test9dbf
xPltName test9dbtraj`
var
plotTest
=
[]
string
{
var
plotTest
=
[]
string
{
s
1
dplot
,
s
9dplot
,
s9b
dplot
,
}
}
func
TestPlot
(
t
*
testing
.
T
)
{
func
TestPlot
(
t
*
testing
.
T
)
{
...
...
This diff is collapsed.
Click to expand it.
ackwork/dorun.go
+
16
−
10
View file @
c619eb28
...
@@ -146,18 +146,18 @@ func saveStep(cprm *cprm, n uint32, tmprtr float64, x []float32, fTrial float64)
...
@@ -146,18 +146,18 @@ func saveStep(cprm *cprm, n uint32, tmprtr float64, x []float32, fTrial float64)
}
}
// nRunAdj will try to adjust the step size, given our history of accept/reject.
// nRunAdj will try to adjust the step size, given our history of accept/reject.
func
nRunAdj
(
mcPrm
*
mcPrm
,
runAcc
float64
,
xDlta
float32
)
float32
{
func
nRunAdj
(
mcPrm
*
mcPrm
,
nstep
uint32
,
runAcc
float64
,
xDlta
float32
)
float32
{
const
step
=
"step"
const
step
=
"step"
if
runAcc
<
accRateIdeal
-
0.01
{
// acceptance rate too low
if
runAcc
<
accRateIdeal
-
0.01
{
// acceptance rate too low
xDlta
*=
0.9
xDlta
*=
0.9
if
mcPrm
.
verbose
{
if
mcPrm
.
verbose
{
fmt
.
Println
(
step
,
xDlta
,
"decrease"
)
fmt
.
Println
(
step
,
nstep
,
"decrease"
,
xDlta
)
}
}
}
else
if
(
xDlta
<
maxxDlta
)
&&
(
runAcc
>
accRateIdeal
+
0.01
)
{
}
else
if
(
xDlta
<
maxxDlta
)
&&
(
runAcc
>
accRateIdeal
+
0.01
)
{
xDlta
*=
1.1
xDlta
*=
1.1
if
mcPrm
.
verbose
{
if
mcPrm
.
verbose
{
fmt
.
Println
(
step
,
xDlta
,
"increase"
)
fmt
.
Println
(
step
,
nstep
,
"increase"
,
xDlta
)
}
}
}
}
return
xDlta
return
xDlta
...
@@ -188,26 +188,25 @@ func doRun(mcPrm *mcPrm) error {
...
@@ -188,26 +188,25 @@ func doRun(mcPrm *mcPrm) error {
runAcc
:=
accRateIdeal
// Running acceptance rate, exponentially weighted
runAcc
:=
accRateIdeal
// Running acceptance rate, exponentially weighted
copy
(
x
,
mcPrm
.
xIni
)
copy
(
x
,
mcPrm
.
xIni
)
fOld
:=
ackley
.
Ackley
(
x
)
// Initial function value
fOld
:=
ackley
.
Ackley
(
x
)
// Initial function value
fTrial
:=
fOld
tmprtr
:=
float64
(
mcPrm
.
iniTmp
)
tmprtr
:=
float64
(
mcPrm
.
iniTmp
)
nRunAcc
:=
nRunAccAdj
// Every nRunAccAdj, try adjusting the step size.
nRunAcc
:=
nRunAccAdj
// Every nRunAccAdj, try adjusting the step size.
const
runMult
=
0.99
const
runMult
=
0.99
xDlta
:=
mcPrm
.
xDlta
// Adaptable step size
xDlta
:=
mcPrm
.
xDlta
// Adaptable step size
if
mcPrm
.
fOutName
==
"test9d.csv"
{
breaker
()
}
saveStep
(
&
cprm
,
0
,
tmprtr
,
x
,
fOld
)
saveStep
(
&
cprm
,
0
,
tmprtr
,
x
,
fOld
)
for
n
:=
uint32
(
0
);
n
<
mcPrm
.
nStep
;
n
++
{
for
n
:=
uint32
(
0
);
n
<
mcPrm
.
nStep
;
n
++
{
var
acc
bool
var
acc
bool
// nout--
// if nout == 0 { // Do we want to print out results on this step ?
// printfVal(cprm.fOut, x, n, tmprtr, fOld)
// nout = cprm.nEvery
// }
nRunAcc
--
nRunAcc
--
if
nRunAcc
==
0
{
// Do we want to try adjusting the step size ?
if
nRunAcc
==
0
{
// Do we want to try adjusting the step size ?
xDlta
=
nRunAdj
(
mcPrm
,
runAcc
,
xDlta
)
xDlta
=
nRunAdj
(
mcPrm
,
n
,
runAcc
,
xDlta
)
nRunAcc
=
nRunAccAdj
// Reset the counter
nRunAcc
=
nRunAccAdj
// Reset the counter
}
}
newx
(
x
,
xT
,
cprm
.
rand
,
xDlta
)
newx
(
x
,
xT
,
cprm
.
rand
,
xDlta
)
fTrial
:
=
ackley
.
Ackley
(
xT
)
fTrial
=
ackley
.
Ackley
(
xT
)
if
fOld
<
fTrial
{
if
fOld
<
fTrial
{
r
:=
cprm
.
rand
.
Float64
()
// Make the decision as to whether to
r
:=
cprm
.
rand
.
Float64
()
// Make the decision as to whether to
...
@@ -232,7 +231,14 @@ func doRun(mcPrm *mcPrm) error {
...
@@ -232,7 +231,14 @@ func doRun(mcPrm *mcPrm) error {
tmprtr
*=
cprm
.
coolMult
tmprtr
*=
cprm
.
coolMult
}
}
}
}
if
mcPrm
.
fOutName
==
"test9d.csv"
{
breaker
()
}
// On plots, we want the last step, even if nothing changed. Print me. Fix.
// On plots, we want the last step, even if nothing changed. Print me. Fix.
if
fTrial
!=
fOld
{
// last move was not accepted, so we have to add last step
saveStep
(
&
cprm
,
mcPrm
.
nStep
,
tmprtr
,
x
,
fOld
)
}
err
:=
plotfWrt
(
cprm
.
plotnstp
,
cprm
.
plotf
,
cprm
.
plotTmprtr
,
cprm
.
fPlt
,
cprm
.
fplotme
)
err
:=
plotfWrt
(
cprm
.
plotnstp
,
cprm
.
plotf
,
cprm
.
plotTmprtr
,
cprm
.
fPlt
,
cprm
.
fplotme
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
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