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
20a32ab9
Commit
20a32ab9
authored
3 years ago
by
Andrew E. Torda
Browse files
Options
Downloads
Patches
Plain Diff
Have to check in, before an experiment
parent
fa33a486
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
+8
-7
8 additions, 7 deletions
mc_work/dorun.go
mc_work/plot.go
+2
-2
2 additions, 2 deletions
mc_work/plot.go
mc_work/scrnplt.go
+0
-14
0 additions, 14 deletions
mc_work/scrnplt.go
ui/scrnplt.go
+32
-0
32 additions, 0 deletions
ui/scrnplt.go
with
42 additions
and
23 deletions
mc_work/dorun.go
+
8
−
7
View file @
20a32ab9
...
@@ -12,6 +12,7 @@ import (
...
@@ -12,6 +12,7 @@ import (
"sync"
"sync"
"example.com/ackley_mc/ackley"
"example.com/ackley_mc/ackley"
"example.com/ackley_mc/ui"
)
)
const
(
const
(
...
@@ -48,7 +49,7 @@ type cprm struct { // parameters calculated from input
...
@@ -48,7 +49,7 @@ type cprm struct { // parameters calculated from input
plotXtrj
[]
float32
// for plotting trajectories
plotXtrj
[]
float32
// for plotting trajectories
coolme
bool
// Cooling ? or just constant temperature ?
coolme
bool
// Cooling ? or just constant temperature ?
fplotWrt
io
.
WriteCloser
// Where to write the plot of function values
fplotWrt
io
.
WriteCloser
// Where to write the plot of function values
fplot
io
buf
*
bytes
.
Buffer
// The buffer possibly behind fplotWrt
fplotbuf
*
bytes
.
Buffer
// The buffer possibly behind fplotWrt
xplotme
bool
// Are we plotting X trajectories
xplotme
bool
// Are we plotting X trajectories
}
}
...
@@ -101,7 +102,7 @@ func setupRun(mcPrm *mcPrm, cprm *cprm) error {
...
@@ -101,7 +102,7 @@ func setupRun(mcPrm *mcPrm, cprm *cprm) error {
}
}
if
mcPrm
.
fPltName
!=
""
{
// Then we are writing to a file
if
mcPrm
.
fPltName
!=
""
{
// Then we are writing to a file
if
mcPrm
.
fPltName
,
err
=
setSuffix
(
mcPrm
.
fPltName
,
".
pn
g"
);
err
!=
nil
{
if
mcPrm
.
fPltName
,
err
=
setSuffix
(
mcPrm
.
fPltName
,
".
sv
g"
);
err
!=
nil
{
return
fmt
.
Errorf
(
"plot filename: %w"
,
err
)
return
fmt
.
Errorf
(
"plot filename: %w"
,
err
)
}
}
if
cprm
.
fplotWrt
,
err
=
os
.
Create
(
mcPrm
.
fPltName
);
err
!=
nil
{
if
cprm
.
fplotWrt
,
err
=
os
.
Create
(
mcPrm
.
fPltName
);
err
!=
nil
{
...
@@ -110,7 +111,7 @@ func setupRun(mcPrm *mcPrm, cprm *cprm) error {
...
@@ -110,7 +111,7 @@ func setupRun(mcPrm *mcPrm, cprm *cprm) error {
}
else
{
// Must be writing to a screen
}
else
{
// Must be writing to a screen
var
w
bytes
.
Buffer
// could be fancy, preallocate and use bytes.Newbuffer
var
w
bytes
.
Buffer
// could be fancy, preallocate and use bytes.Newbuffer
cprm
.
fplotWrt
=
addClose
(
&
w
)
// Fix this, effectively two copies
cprm
.
fplotWrt
=
addClose
(
&
w
)
// Fix this, effectively two copies
cprm
.
fplot
io
buf
=
&
w
// of the pointer
cprm
.
fplotbuf
=
&
w
// of the pointer
}
}
n_alloc
:=
mcPrm
.
nStep
/
5
// About a fifth of the number of steps
n_alloc
:=
mcPrm
.
nStep
/
5
// About a fifth of the number of steps
cprm
.
plotnstp
=
make
([]
float64
,
0
,
n_alloc
)
cprm
.
plotnstp
=
make
([]
float64
,
0
,
n_alloc
)
...
@@ -120,7 +121,7 @@ func setupRun(mcPrm *mcPrm, cprm *cprm) error {
...
@@ -120,7 +121,7 @@ func setupRun(mcPrm *mcPrm, cprm *cprm) error {
}
}
if
mcPrm
.
xPltName
!=
""
{
if
mcPrm
.
xPltName
!=
""
{
if
mcPrm
.
xPltName
,
err
=
setSuffix
(
mcPrm
.
xPltName
,
".
pn
g"
);
err
!=
nil
{
if
mcPrm
.
xPltName
,
err
=
setSuffix
(
mcPrm
.
xPltName
,
".
sv
g"
);
err
!=
nil
{
return
fmt
.
Errorf
(
"plot filename: %w"
,
err
)
return
fmt
.
Errorf
(
"plot filename: %w"
,
err
)
}
}
cprm
.
xplotme
=
true
cprm
.
xplotme
=
true
...
@@ -272,9 +273,9 @@ func doRun(mcPrm *mcPrm) error {
...
@@ -272,9 +273,9 @@ func doRun(mcPrm *mcPrm) error {
return
err
return
err
}
}
if
cprm
.
fplot
io
buf
!=
nil
{
if
cprm
.
fplotbuf
!=
nil
{
fmt
.
Println
(
"len"
,
cprm
.
fplot
io
buf
.
Len
())
fmt
.
Println
(
"len"
,
cprm
.
fplotbuf
.
Len
())
s
crnplt
(
cprm
.
fplot
io
buf
.
Bytes
())
ui
.
S
crnplt
(
cprm
.
fplotbuf
.
Bytes
())
}
}
if
err
:=
plotxWrt
(
&
cprm
,
mcPrm
.
xPltName
,
len
(
mcPrm
.
xIni
));
err
!=
nil
{
if
err
:=
plotxWrt
(
&
cprm
,
mcPrm
.
xPltName
,
len
(
mcPrm
.
xIni
));
err
!=
nil
{
return
err
return
err
...
...
This diff is collapsed.
Click to expand it.
mc_work/plot.go
+
2
−
2
View file @
20a32ab9
...
@@ -143,7 +143,7 @@ func plotfWrt(cprm *cprm) error {
...
@@ -143,7 +143,7 @@ func plotfWrt(cprm *cprm) error {
},
},
}
}
if
err
:=
graph
.
Render
(
chart
.
PN
G
,
cprm
.
fplotWrt
);
err
!=
nil
{
if
err
:=
graph
.
Render
(
chart
.
SV
G
,
cprm
.
fplotWrt
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Render: %w"
,
err
)
return
fmt
.
Errorf
(
"Render: %w"
,
err
)
}
}
...
@@ -201,7 +201,7 @@ func plotxWrt(cprm *cprm, xPltName string, ndim int) error {
...
@@ -201,7 +201,7 @@ func plotxWrt(cprm *cprm, xPltName string, ndim int) error {
return
err
return
err
}
}
defer
xPlt
.
Close
()
defer
xPlt
.
Close
()
if
err
:=
graph
.
Render
(
chart
.
PN
G
,
xPlt
);
err
!=
nil
{
if
err
:=
graph
.
Render
(
chart
.
SV
G
,
xPlt
);
err
!=
nil
{
return
fmt
.
Errorf
(
"plotting X trajectories: %w"
,
err
)
return
fmt
.
Errorf
(
"plotting X trajectories: %w"
,
err
)
}
}
return
nil
return
nil
...
...
This diff is collapsed.
Click to expand it.
mc_work/scrnplt.go
deleted
100644 → 0
+
0
−
14
View file @
fa33a486
// 25 Jan 2020
// Given a buffer or two with a plot picture, send it to the screen
// I think this might be better in its own package
package
mc_work
import
(
"fmt"
)
func
scrnplt
(
b
[]
byte
)
{
fmt
.
Println
(
"scrnplt says hello, buf size"
,
len
(
b
))
}
This diff is collapsed.
Click to expand it.
ui/scrnplt.go
0 → 100644
+
32
−
0
View file @
20a32ab9
// 25 Jan 2020
// Given a buffer or two with a plot picture, send it to the screen
// I think this might be better in its own package
package
ui
import
(
"bytes"
"fmt"
"image/color"
// need this for the green ?
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
)
func
Scrnplt
(
b
[]
byte
)
{
fmt
.
Println
(
"scrnplt says buf size"
,
len
(
b
),
"first few bytes:"
,
string
(
b
[
:
10
]))
a
:=
app
.
New
()
w
:=
a
.
NewWindow
(
"container"
)
image
:=
canvas
.
NewImageFromReader
(
bytes
.
NewReader
(
b
),
"boo.svg"
)
green
:=
color
.
NRGBA
{
R
:
0
,
G
:
180
,
B
:
0
,
A
:
255
}
text1
:=
canvas
.
NewText
(
"Hello"
,
green
);
print
(
text1
)
text2
:=
canvas
.
NewText
(
"There"
,
green
)
text2
.
Move
(
fyne
.
NewPos
(
20
,
20
))
content
:=
container
.
NewWithoutLayout
(
image
)
// no more text 1, text2
// content := container.New(layout.NewGridLayout(2), text1, text2)
w
.
SetContent
(
content
)
w
.
ShowAndRun
()
}
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