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
607e1fc0
Commit
607e1fc0
authored
3 years ago
by
Andrew E. Torda
Browse files
Options
Downloads
Patches
Plain Diff
Added more stats (best position) to graphical display.
parent
ac9a0c8c
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
mc_work/dorun.go
+31
-4
31 additions, 4 deletions
mc_work/dorun.go
mc_work/mc_work.go
+4
-2
4 additions, 2 deletions
mc_work/mc_work.go
ui/output_tab.go
+3
-2
3 additions, 2 deletions
ui/output_tab.go
ui/ui_run.go
+0
-1
0 additions, 1 deletion
ui/ui_run.go
with
38 additions
and
9 deletions
mc_work/dorun.go
+
31
−
4
View file @
607e1fc0
...
...
@@ -135,7 +135,8 @@ func setupRun(mcPrm *McPrm, cprm *cprm) error {
return
nil
}
// newx will move just one coordinate at a time
// newx will move just one dimension at a time. Moving all dimensions at once
// required teeny moves.
func
newx
(
xold
[]
float32
,
xT
[]
float32
,
rand
*
rand
.
Rand
,
xDlta
float64
)
{
var
iDim
int
if
(
len
(
xold
))
>
1
{
...
...
@@ -147,7 +148,7 @@ func newx(xold []float32, xT []float32, rand *rand.Rand, xDlta float64) {
}
// printfVal is the loop to print out the function value and coordinates
//
probably
for later plotting.
// for later plotting.
func
printfVal
(
fOut
io
.
Writer
,
x
[]
float32
,
n
int
,
tmprtr
float64
,
fOld
float64
)
{
fmt
.
Fprintf
(
fOut
,
"%d,%.4g,%.5g"
,
n
,
tmprtr
,
fOld
)
for
_
,
xx
:=
range
x
{
...
...
@@ -156,9 +157,27 @@ func printfVal(fOut io.Writer, x []float32, n int, tmprtr float64, fOld float64)
fmt
.
Fprintln
(
fOut
)
}
// saveBest checks if we have found a best value for the function. If so,
// update the location where we store it.
var
bestfval
float64
var
bestX
[]
float32
var
bestN
int
func
saveBest
(
x
[]
float32
,
fTrial
float64
,
n
int
)
{
if
bestX
==
nil
{
bestX
=
make
([]
float32
,
len
(
x
))
}
if
fTrial
<
bestfval
||
n
==
0
{
bestfval
=
fTrial
bestN
=
n
copy
(
bestX
,
x
)
}
}
// saveStep is called when we accept a change. It writes or saves for
// later plotting.
func
saveStep
(
cprm
*
cprm
,
n
int
,
tmprtr
float64
,
x
[]
float32
,
fTrial
float64
)
{
saveBest
(
x
,
fTrial
,
n
)
cprm
.
plotnstp
=
append
(
cprm
.
plotnstp
,
float64
(
n
))
// num steps
if
cprm
.
fplotWrt
!=
nil
{
// Function values // function values
cprm
.
plotf
=
append
(
cprm
.
plotf
,
fTrial
)
...
...
@@ -272,7 +291,11 @@ func DoRun(mcPrm *McPrm) (MCresult, error) {
saveStep
(
&
cprm
,
mcPrm
.
NStep
,
tmprtr
,
x
,
fOld
)
}
defer
fmt
.
Println
(
"n accepted:"
,
nAcc
,
"of"
,
mcPrm
.
NStep
)
if
bestX
!=
nil
{
defer
fmt
.
Printf
(
"Best function value: %.2f at %.2v
\n
"
,
bestfval
,
bestX
)
}
else
{
defer
fmt
.
Println
(
"bestX was never initialised"
)
}
if
err
:=
plotfWrt
(
&
cprm
);
err
!=
nil
{
return
broken
,
err
}
...
...
@@ -288,5 +311,9 @@ func DoRun(mcPrm *McPrm) (MCresult, error) {
xdata
=
xBuf
.
Bytes
()
}
return
MCresult
{
Fdata
:
fdata
,
Xdata
:
xdata
,
NStep
:
mcPrm
.
NStep
,
NAcc
:
nAcc
},
nil
return
MCresult
{
Fdata
:
fdata
,
Xdata
:
xdata
,
NStep
:
mcPrm
.
NStep
,
NAcc
:
nAcc
,
Bestfval
:
bestfval
,
BestX
:
bestX
,
},
nil
}
This diff is collapsed.
Click to expand it.
mc_work/mc_work.go
+
4
−
2
View file @
607e1fc0
...
...
@@ -28,4 +28,6 @@ var Seed int
type
MCresult
struct
{
Fdata
,
Xdata
[]
byte
// png images of function and X data
NStep
,
NAcc
int
// number of steps and accepted steps
Bestfval
float64
// best function value found
BestX
[]
float32
// location of this best value found
}
This diff is collapsed.
Click to expand it.
ui/output_tab.go
+
3
−
2
View file @
607e1fc0
...
...
@@ -28,9 +28,10 @@ import (
// runStatTxt should summarise some of the statistics
func
runStatTxt
(
rslt
*
mcwork
.
MCresult
)
fyne
.
Widget
{
t
xt
:=
fmt
.
Sprintf
(
"Num steps %d
\n
Num accepted %d
\n
acceptance rate %.1f %%"
,
t
1
:=
fmt
.
Sprintf
(
"Num steps %d
\n
Num accepted %d
\n
acceptance rate %.1f %%
\n
"
,
rslt
.
NStep
,
rslt
.
NAcc
,
(
float32
(
rslt
.
NAcc
)
/
float32
(
rslt
.
NStep
))
*
100.
)
r
:=
widget
.
NewLabel
(
txt
)
t2
:=
fmt
.
Sprintf
(
"best function value: %.2f
\n
at %.1g"
,
rslt
.
Bestfval
,
rslt
.
BestX
)
r
:=
widget
.
NewLabel
(
t1
+
t2
)
return
r
}
...
...
This diff is collapsed.
Click to expand it.
ui/ui_run.go
+
0
−
1
View file @
607e1fc0
...
...
@@ -33,7 +33,6 @@ const (
type
workstatus
struct
{
mcwork
.
MCresult
// fdata, xdata []byte // the data in a function or X value plot
err
error
status
status
// Tells us what we should do now
}
...
...
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