Skip to content

Commit

Permalink
update params to new styler names and fix texts.
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Aug 11, 2024
1 parent 7bfe300 commit b11aea1
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 60 deletions.
8 changes: 4 additions & 4 deletions emer/netparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (pr *NetParams) Name() string {
// RunName returns standard name simulation run based on params Name()
// and starting run number.
func (pr *NetParams) RunName(startRun int) string {
return fmt.Sprintf("%s_%03d", pr.Name, startRun)
return fmt.Sprintf("%s_%03d", pr.Name(), startRun)
}

// Validate checks that the Network has been set
Expand Down Expand Up @@ -157,7 +157,7 @@ func NetworkHyperParams(net Network, sheet *params.Sheet) params.Flex {
for li := range nl {
ly := net.EmerLayer(li)
nm := ly.StyleName()
hypers[nm] = &params.FlexVal{Nm: nm, Type: "Layer", Cls: ly.StyleClass(), Obj: params.Hypers{}}
hypers[nm] = &params.FlexVal{Name: nm, Type: "Layer", Class: ly.StyleClass(), Object: params.Hypers{}}
}
// separate pathways
for li := range nl {
Expand All @@ -166,12 +166,12 @@ func NetworkHyperParams(net Network, sheet *params.Sheet) params.Flex {
for pi := range np {
pj := ly.RecvPath(pi)
nm := pj.StyleName()
hypers[nm] = &params.FlexVal{Nm: nm, Type: "Path", Cls: pj.StyleClass(), Obj: params.Hypers{}}
hypers[nm] = &params.FlexVal{Name: nm, Type: "Path", Class: pj.StyleClass(), Object: params.Hypers{}}
}
}
for nm, vl := range hypers {
sheet.Apply(vl, false)
hv := vl.Obj.(params.Hypers)
hv := vl.Object.(params.Hypers)
hv.DeleteValOnly()
if len(hv) == 0 {
delete(hypers, nm)
Expand Down
4 changes: 2 additions & 2 deletions emer/netsize.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (ns *NetSize) AddLayers(names []string, class string) {
*ns = make(NetSize)
}
for _, nm := range names {
(*ns)[nm] = &params.FlexVal{Nm: nm, Type: "Layer", Cls: class, Obj: &LaySize{}}
(*ns)[nm] = &params.FlexVal{Name: nm, Type: "Layer", Class: class, Object: &LaySize{}}
}
}

Expand All @@ -59,7 +59,7 @@ func (ns *NetSize) Layer(name string) (*LaySize, error) {
err := fmt.Errorf("emer.NetSize: layer named: %s not found", name)
return nil, err
}
return fv.Obj.(*LaySize), nil
return fv.Object.(*LaySize), nil
}

// LayX returns the X value = horizontal size of 2D layer or number of pools
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/emer/emergent/v2
go 1.22

require (
cogentcore.org/core v0.3.2-0.20240809164801-7009c15e5272
cogentcore.org/core v0.3.2-0.20240811064529-4a22c2f0a3e9
github.com/BurntSushi/toml v1.3.2
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883
github.com/iancoleman/strcase v0.3.0
Expand All @@ -25,7 +25,6 @@ require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a // indirect
github.com/goki/freetype v1.0.5 // indirect
github.com/goki/vulkan v1.0.8 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/h2non/filetype v1.1.3 // indirect
github.com/hack-pad/go-indexeddb v0.3.2 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cogentcore.org/core v0.3.2-0.20240809164801-7009c15e5272 h1:wdM6lmuuqOmC/ikIr+lWj7rTilGVZ7KdbH/JeCL5d5w=
cogentcore.org/core v0.3.2-0.20240809164801-7009c15e5272/go.mod h1:dyArrrZBlucGMUCMl8dAX/22nY32Bv7Q16vwE0K/daY=
cogentcore.org/core v0.3.2-0.20240811064529-4a22c2f0a3e9 h1:Y7+KwE61bjyRjkmLOXksceatyKv+qv6vvP7qFgbb8j0=
cogentcore.org/core v0.3.2-0.20240811064529-4a22c2f0a3e9/go.mod h1:dyArrrZBlucGMUCMl8dAX/22nY32Bv7Q16vwE0K/daY=
github.com/Bios-Marcel/wastebasket v0.0.4-0.20240213135800-f26f1ae0a7c4 h1:6lx9xzJAhdjq0LvVfbITeC3IH9Fzvo1aBahyPu2FuG8=
github.com/Bios-Marcel/wastebasket v0.0.4-0.20240213135800-f26f1ae0a7c4/go.mod h1:FChzXi1izqzdPb6BiNZmcZLGyTYiT61iGx9Rxx9GNeI=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
Expand Down Expand Up @@ -44,8 +44,6 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a h1:vxnBhFDDT+
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/goki/freetype v1.0.5 h1:yi2lQeUhXnBgSMqYd0vVmPw6RnnfIeTP3N4uvaJXd7A=
github.com/goki/freetype v1.0.5/go.mod h1:wKmKxddbzKmeci9K96Wknn5kjTWLyfC8tKOqAFbEX8E=
github.com/goki/vulkan v1.0.8 h1:yx7GPP3wZOFeJ25wEneHk08fOSlUz/wxHBBCiCB1G18=
github.com/goki/vulkan v1.0.8/go.mod h1:xPwQgSdRep28xG1Tn4yysNGFORyCsAZcf9DcljIxGRs=
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg=
Expand Down
24 changes: 12 additions & 12 deletions params/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ import (
// The field names are abbreviated because full names are used in StylerObject.
type FlexVal struct {
// name of this specific object, matches #Name selections
Nm string
Name string

// type name of this object, matches plain TypeName selections
Type string

// space-separated list of class name(s), match the .Class selections
Cls string
Class string

// actual object with data that is set by the parameters
Obj any
Object any

// History of params applied
History HistoryImpl `table:"-"`
Expand All @@ -39,23 +39,23 @@ func (fv *FlexVal) StyleType() string {
}

func (fv *FlexVal) StyleClass() string {
return fv.Cls
return fv.Class
}

func (fv *FlexVal) Name() string {
return fv.Nm
func (fv *FlexVal) StyleName() string {
return fv.Name
}

func (fv *FlexVal) StyleObject() any {
return fv.Obj
return fv.Object
}

func (fv *FlexVal) CopyFrom(cp *FlexVal) {
fv.Nm = cp.Nm // these should be the same, but copy anyway
fv.Name = cp.Name // these should be the same, but copy anyway
fv.Type = cp.Type
fv.Cls = cp.Cls
if hyp, ok := fv.Obj.(Hypers); ok { // this is the main use-case
if cph, ok := cp.Obj.(Hypers); ok {
fv.Class = cp.Class
if hyp, ok := fv.Object.(Hypers); ok { // this is the main use-case
if cph, ok := cp.Object.(Hypers); ok {
hyp.CopyFrom(cph)
}
}
Expand Down Expand Up @@ -105,7 +105,7 @@ func (fl *Flex) Init(vals []FlexVal) {
*fl = make(Flex, len(vals))
for _, vl := range vals {
inst := vl
(*fl)[vl.Nm] = &inst
(*fl)[vl.Name] = &inst
}
}

Expand Down
32 changes: 16 additions & 16 deletions params/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ func TestParamSetsSet(t *testing.T) {

var trgHypers = `{
"Hidden1": {
"Nm": "Hidden1",
"Name": "Hidden1",
"Type": "Layer",
"Cls": "Hidden",
"Obj": {
"Class": "Hidden",
"Object": {
"Layer.Inhib.Layer.Gi": {
"Min": "0.5",
"StdDev": "0.1",
Expand All @@ -185,10 +185,10 @@ var trgHypers = `{
]
},
"Hidden2": {
"Nm": "Hidden2",
"Name": "Hidden2",
"Type": "Layer",
"Cls": "Hidden",
"Obj": {
"Class": "Hidden",
"Object": {
"Layer.Inhib.Layer.Gi": {
"Min": "0.5",
"StdDev": "0.1",
Expand All @@ -212,10 +212,10 @@ var trgHypers = `{
]
},
"Input": {
"Nm": "Input",
"Name": "Input",
"Type": "Layer",
"Cls": "Input",
"Obj": {
"Class": "Input",
"Object": {
"Layer.Inhib.Layer.Gi": {
"Min": "0.5",
"StdDev": "0.1",
Expand All @@ -239,10 +239,10 @@ var trgHypers = `{
]
},
"Output": {
"Nm": "Output",
"Name": "Output",
"Type": "Layer",
"Cls": "Target",
"Obj": {
"Class": "Target",
"Object": {
"Layer.Inhib.Layer.Gi": {
"Min": "0.5",
"StdDev": "0.1",
Expand Down Expand Up @@ -278,10 +278,10 @@ var trgHypers = `{
func TestFlexHypers(t *testing.T) {
hypers := Flex{}
hypers.Init([]FlexVal{
FlexVal{Nm: "Input", Type: "Layer", Cls: "Input", Obj: Hypers{}},
FlexVal{Nm: "Hidden1", Type: "Layer", Cls: "Hidden", Obj: Hypers{}},
FlexVal{Nm: "Hidden2", Type: "Layer", Cls: "Hidden", Obj: Hypers{}},
FlexVal{Nm: "Output", Type: "Layer", Cls: "Target", Obj: Hypers{}},
FlexVal{Name: "Input", Type: "Layer", Class: "Input", Object: Hypers{}},
FlexVal{Name: "Hidden1", Type: "Layer", Class: "Hidden", Object: Hypers{}},
FlexVal{Name: "Hidden2", Type: "Layer", Class: "Hidden", Object: Hypers{}},
FlexVal{Name: "Output", Type: "Layer", Class: "Target", Object: Hypers{}},
})
basenet := paramSets["Base"]
hypers.ApplySheet(basenet, false)
Expand Down
16 changes: 8 additions & 8 deletions params/tweak.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TweaksFromHypers(hypers Flex) []*Tweaks {
slices.Sort(fkeys)
for _, fnm := range fkeys {
flx := hypers[fnm]
hyps := flx.Obj.(Hypers)
hyps := flx.Object.(Hypers)
hkeys := maps.Keys(hyps)
slices.Sort(hkeys)
for _, ppath := range hkeys {
Expand All @@ -132,15 +132,15 @@ func TweaksFromHypers(hypers Flex) []*Tweaks {
if !ok {
sflex = &FlexVal{}
sflex.CopyFrom(flx)
sflex.Obj = make(Hypers)
sflex.Object = make(Hypers)
fm[fnm] = sflex
}
shyps := sflex.Obj.(Hypers)
shyps := sflex.Object.(Hypers)
_, ok = shyps[ppath]
if !ok {
shyps[ppath] = hv
}
sflex.Obj = shyps
sflex.Object = shyps
sels[sel] = fm
}
}
Expand All @@ -164,7 +164,7 @@ func TweaksFromHypers(hypers Flex) []*Tweaks {
break
}
}
hyps := f0.Obj.(Hypers)
hyps := f0.Object.(Hypers)
hkeys := maps.Keys(hyps)
slices.Sort(hkeys)
for _, ppath := range hkeys {
Expand All @@ -175,7 +175,7 @@ func TweaksFromHypers(hypers Flex) []*Tweaks {
slices.Sort(fkeys)
for _, fk := range fkeys {
fv := flx[fk]
hyp := fv.Obj.(Hypers)
hyp := fv.Object.(Hypers)
vals := hyp[ppath]
tweak, ok := vals["Tweak"]
tweak = strings.ToLower(strings.TrimSpace(tweak))
Expand All @@ -189,12 +189,12 @@ func TweaksFromHypers(hypers Flex) []*Tweaks {
}
f64, err := strconv.ParseFloat(val, 32)
if err != nil {
fmt.Printf("TweakFromHypers float parse error: only works for float type params. Obj: %s Param: %s val: %s parse error: %v\n", fv.Nm, ppath, val, err)
fmt.Printf("TweakFromHypers float parse error: only works for float type params. Obj: %s Param: %s val: %s parse error: %v\n", fv.Name, ppath, val, err)
continue
}
start := float32(f64)

sval := SearchValues{Name: fv.Nm, Type: fv.Type, Path: ppath, Start: start}
sval := SearchValues{Name: fv.Name, Type: fv.Type, Path: ppath, Start: start}

var pars []float32 // param vals to search
if tweak[0] == '[' {
Expand Down
Loading

0 comments on commit b11aea1

Please sign in to comment.