Skip to content

Commit

Permalink
initial renaming of some core packages
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoreilly committed Apr 14, 2024
1 parent b0bf70f commit d2c953f
Show file tree
Hide file tree
Showing 39 changed files with 355 additions and 355 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -122,7 +122,7 @@ The following all work together to provide a convenient layer of abstraction for

* [esg](esg) is the *emergent stochastic / sentence generator* -- parses simple grammars that generate random events (sentences) -- can be a good starting point for generating more complex environments.

* [evec](evec) has `Vec2i` which uses plain `int` X, Y fields, whereas the `mat32` package uses `int32` which are needed for graphics but int is more convenient in models.
* [evec](evec) has `Vec2i` which uses plain `int` X, Y fields, whereas the `math32` package uses `int32` which are needed for graphics but int is more convenient in models.

* [popcode](popcode) supports the encoding and decoding of population codes -- distributed representations of numeric quantities across a population of neurons. This is the `ScalarVal` functionality from C++ emergent, but now completely independent of any specific algorithm so it can be used anywhere.

Expand Down
4 changes: 2 additions & 2 deletions decoder/linear.go
Expand Up @@ -9,7 +9,7 @@ package decoder
import (
"fmt"

"cogentcore.org/core/mat32"
"cogentcore.org/core/math32"

Check failure on line 12 in decoder/linear.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package cogentcore.org/core/math32; to add it:
"github.com/emer/empi/v2/mpi"
"github.com/emer/etable/v2/etensor"
)
Expand Down Expand Up @@ -70,7 +70,7 @@ func IdentityFunc(x float32) float32 { return x }
// LogisticFunc implements the standard logistic function.
// Its outputs are in the range (0, 1).
// Also known as Sigmoid. See https://en.wikipedia.org/wiki/Logistic_function.
func LogisticFunc(x float32) float32 { return 1 / (1 + mat32.FastExp(-x)) }
func LogisticFunc(x float32) float32 { return 1 / (1 + math32.FastExp(-x)) }

// LinearUnit has variables for Linear decoder unit
type LinearUnit struct {
Expand Down
4 changes: 2 additions & 2 deletions decoder/softmax.go
Expand Up @@ -15,7 +15,7 @@ import (
"path/filepath"
"sort"

"cogentcore.org/core/mat32"
"cogentcore.org/core/math32"
"github.com/emer/emergent/v2/emer"
"github.com/emer/empi/v2/mpi"
"github.com/emer/etable/v2/etensor"
Expand Down Expand Up @@ -171,7 +171,7 @@ func (sm *SoftMax) Forward() {
for ui := range sm.Units {
u := &sm.Units[ui]
u.Net -= max
u.Exp = mat32.FastExp(u.Net)
u.Exp = math32.FastExp(u.Net)
sum += u.Exp
}
for ui := range sm.Units {
Expand Down
2 changes: 1 addition & 1 deletion econfig/config.go
Expand Up @@ -11,7 +11,7 @@ import (
"os"
"reflect"

"cogentcore.org/core/glop/dirs"
"cogentcore.org/core/gox/dirs"

Check failure on line 14 in econfig/config.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package cogentcore.org/core/gox/dirs; to add it:
"github.com/emer/empi/v2/mpi"
)

Expand Down
8 changes: 4 additions & 4 deletions edge/wrapmindist.go
Expand Up @@ -4,17 +4,17 @@

package edge

import "cogentcore.org/core/mat32"
import "cogentcore.org/core/math32"

// WrapMinDist returns the wrapped coordinate value that is closest to ctr
// i.e., if going out beyond max is closer, then returns that coordinate
// else if going below 0 is closer than not, then returns that coord
func WrapMinDist(ci, max, ctr float32) float32 {
nwd := mat32.Abs(ci - ctr) // no-wrap dist
if mat32.Abs((ci+max)-ctr) < nwd {
nwd := math32.Abs(ci - ctr) // no-wrap dist
if math32.Abs((ci+max)-ctr) < nwd {
return ci + max
}
if mat32.Abs((ci-max)-ctr) < nwd {
if math32.Abs((ci-max)-ctr) < nwd {
return ci - max
}
return ci
Expand Down
8 changes: 4 additions & 4 deletions efuns/gauss.go
Expand Up @@ -9,20 +9,20 @@ package efuns
//go:generate core generate -add-types

import (
"cogentcore.org/core/mat32"
"cogentcore.org/core/math32"
)

// GaussVecDistNoNorm returns the gaussian of the distance between two 2D vectors
// using given sigma standard deviation, without normalizing area under gaussian
// (i.e., max value is 1 at dist = 0)
func GaussVecDistNoNorm(a, b mat32.Vec2, sigma float32) float32 {
func GaussVecDistNoNorm(a, b math32.Vec2, sigma float32) float32 {
dsq := a.DistToSquared(b)
return mat32.FastExp((-0.5 * dsq) / (sigma * sigma))
return math32.FastExp((-0.5 * dsq) / (sigma * sigma))
}

// Gauss1DNoNorm returns the gaussian of a given x value, without normalizing
// (i.e., max value is 1 at x = 0)
func Gauss1DNoNorm(x, sig float32) float32 {
x /= sig
return mat32.FastExp(-0.5 * x * x)
return math32.FastExp(-0.5 * x * x)
}
4 changes: 2 additions & 2 deletions efuns/logistic.go
Expand Up @@ -4,9 +4,9 @@

package efuns

import "cogentcore.org/core/mat32"
import "cogentcore.org/core/math32"

// Logistic is the logistic (sigmoid) function of x: 1/(1 + e^(-gain*(x-off)))
func Logistic(x, gain, off float32) float32 {
return 1.0 / (1.0 + mat32.FastExp(-gain*(x-off)))
return 1.0 / (1.0 + math32.FastExp(-gain*(x-off)))
}
2 changes: 1 addition & 1 deletion egui/README.md
Expand Up @@ -18,7 +18,7 @@ func (ss *Sim) ConfigGUI() *gi.Window {

// optionally reconfigure the netview:
ss.GUI.NetView.Scene().Camera.Pose.Pos.Set(0, 1, 2.75)
ss.GUI.NetView.Scene().Camera.LookAt(mat32.V3(0, 0, 0), mat32.V3(0, 1, 0))
ss.GUI.NetView.Scene().Camera.LookAt(math32.V3(0, 0, 0), math32.V3(0, 1, 0))
ss.GUI.AddPlots(title, &ss.Logs) // automatically adds all configured plots
```
Expand Down
4 changes: 2 additions & 2 deletions egui/plots.go
Expand Up @@ -9,7 +9,7 @@ import (
"log"

"cogentcore.org/core/colors"
"cogentcore.org/core/grr"
"cogentcore.org/core/errors"

Check failure on line 12 in egui/plots.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package cogentcore.org/core/errors; to add it:
"github.com/emer/emergent/v2/elog"
"github.com/emer/emergent/v2/etime"
"github.com/emer/etable/v2/eplot"
Expand Down Expand Up @@ -53,7 +53,7 @@ func ConfigPlotFromLog(title string, plt *eplot.Plot2D, lg *elog.Logs, key etime
cp := plt.SetColParams(item.Name, item.Plot, item.FixMin, item.Range.Min, item.FixMax, item.Range.Max)

if item.Color != "" {
cp.Color = grr.Log1(colors.FromString(item.Color, nil))
cp.Color = errors.Log1(colors.FromString(item.Color, nil))
}
cp.TensorIndex = item.TensorIndex
cp.ErrCol = item.ErrCol
Expand Down
12 changes: 6 additions & 6 deletions emer/layer.go
Expand Up @@ -10,7 +10,7 @@ import (
"fmt"
"io"

"cogentcore.org/core/mat32"
"cogentcore.org/core/math32"
"github.com/emer/emergent/v2/params"
"github.com/emer/emergent/v2/relpos"
"github.com/emer/emergent/v2/weights"
Expand Down Expand Up @@ -87,16 +87,16 @@ type Layer interface {
// where the vertical dimension is Y and Z is the depth dimension. However, in the
// more "layer-centric" way of thinking about it, it is natural for the width & height
// to map onto X and Y, and then Z is left over for stacking vertically.
Pos() mat32.Vec3
Pos() math32.Vec3

// SetPos sets the 3D position of this layer -- will generally be overwritten by
// automatic RelPos setting, unless that doesn't specify a valid relative position.
SetPos(pos mat32.Vec3)
SetPos(pos math32.Vec3)

// Size returns the display size of this layer for the 3D view -- see Pos() for general info.
// This is multiplied by the RelPos.Scale factor to rescale layer sizes, and takes
// into account 2D and 4D layer structures.
Size() mat32.Vec2
Size() math32.Vec2

// Index returns a 0..n-1 index of the position of the layer within list of layers
// in the network. For backprop networks, index position has computational significance.
Expand Down Expand Up @@ -225,7 +225,7 @@ type Layer interface {
// useful when there are multiple projections between two layers.
// Returns error on invalid var name.
// If the receiving neuron is not connected to the given sending layer or neuron
// then the value is set to mat32.NaN().
// then the value is set to math32.NaN().
// Returns error on invalid var name or lack of recv prjn (vals always set to nan on prjn err).
RecvPrjnValues(vals *[]float32, varNm string, sendLay Layer, sendIndex1D int, prjnType string) error

Expand All @@ -237,7 +237,7 @@ type Layer interface {
// useful when there are multiple projections between two layers.
// Returns error on invalid var name.
// If the sending neuron is not connected to the given receiving layer or neuron
// then the value is set to mat32.NaN().
// then the value is set to math32.NaN().
// Returns error on invalid var name or lack of recv prjn (vals always set to nan on prjn err).
SendPrjnValues(vals *[]float32, varNm string, recvLay Layer, recvIndex1D int, prjnType string) error

Expand Down
8 changes: 4 additions & 4 deletions emer/network.go
Expand Up @@ -10,7 +10,7 @@ import (
"io"

"cogentcore.org/core/gi"
"cogentcore.org/core/mat32"
"cogentcore.org/core/math32"
"github.com/emer/emergent/v2/params"
"github.com/emer/emergent/v2/weights"
)
Expand Down Expand Up @@ -78,7 +78,7 @@ type Network interface {

// UnitVarNames returns a list of variable names available on the units in this network.
// This list determines what is shown in the NetView (and the order of vars list).
// Not all layers need to support all variables, but must safely return mat32.NaN() for
// Not all layers need to support all variables, but must safely return math32.NaN() for
// unsupported ones.
// This is typically a global list so do not modify!
UnitVarNames() []string
Expand All @@ -97,7 +97,7 @@ type Network interface {

// SynVarNames returns the names of all the variables on the synapses in this network.
// This list determines what is shown in the NetView (and the order of vars list).
// Not all projections need to support all variables, but must safely return mat32.NaN() for
// Not all projections need to support all variables, but must safely return math32.NaN() for
// unsupported ones.
// This is typically a global list so do not modify!
SynVarNames() []string
Expand Down Expand Up @@ -134,7 +134,7 @@ type Network interface {
OpenWtsJSON(filename gi.Filename) error

// Bounds returns the minimum and maximum display coordinates of the network for 3D display
Bounds() (min, max mat32.Vec3)
Bounds() (min, max math32.Vec3)

// VarRange returns the min / max values for given variable
VarRange(varNm string) (min, max float32, err error)
Expand Down
2 changes: 1 addition & 1 deletion emer/prjn.go
Expand Up @@ -116,7 +116,7 @@ type Prjn interface {

// SynVal returns value of given variable name on the synapse
// between given send, recv unit indexes (1D, flat indexes).
// Returns mat32.NaN() for access errors.
// Returns math32.NaN() for access errors.
SynValue(varNm string, sidx, ridx int) float32

// SetSynVal sets value of given variable name on the synapse
Expand Down
2 changes: 1 addition & 1 deletion erand/erand_test.go
Expand Up @@ -8,7 +8,7 @@ import (
"math"
"testing"

"cogentcore.org/core/glop/num"
"cogentcore.org/core/gox/num"
)

func TestPoisson(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion evec/README.md
@@ -1,5 +1,5 @@
Docs: [GoDoc](https://pkg.go.dev/github.com/emer/emergent/evec)

Package `evec` has vector types for emergent, including `Vec2i` which is a 2D vector with int values, using the API based on `mat32.Vec2i`. This is distinct from mat32.Vec2i because it uses int instead of int32, and the int is significantly easier to deal with for layer sizing params etc.
Package `evec` has vector types for emergent, including `Vec2i` which is a 2D vector with int values, using the API based on `math32.Vec2i`. This is distinct from math32.Vec2i because it uses int instead of int32, and the int is significantly easier to deal with for layer sizing params etc.


30 changes: 15 additions & 15 deletions evec/vec2i.go
Expand Up @@ -9,12 +9,12 @@
// with modifications needed to suit Cogent Core functionality.

// Package evec has vector types for emergent, including Vec2i which is a 2D
// vector with int values, using the API based on mat32.Vec2i.
// This is distinct from mat32.Vec2i because it uses int instead of int32, and
// vector with int values, using the API based on math32.Vec2i.
// This is distinct from math32.Vec2i because it uses int instead of int32, and
// the int is significantly easier to deal with for layer sizing params etc.
package evec

import "cogentcore.org/core/mat32"
import "cogentcore.org/core/math32"

// Vec2i is a 2D vector/point with X and Y int components.
type Vec2i struct {
Expand All @@ -32,24 +32,24 @@ func NewVec2iScalar(s int) Vec2i {
return Vec2i{X: s, Y: s}
}

// NewVec2iFromVec2Round converts from floating point mat32.Vec2 vector to int, using rounding
func NewVec2iFromVec2Round(v mat32.Vec2) Vec2i {
return Vec2i{int(mat32.Round(v.X)), int(mat32.Round(v.Y))}
// NewVec2iFromVec2Round converts from floating point math32.Vec2 vector to int, using rounding
func NewVec2iFromVec2Round(v math32.Vec2) Vec2i {
return Vec2i{int(math32.Round(v.X)), int(math32.Round(v.Y))}
}

// NewVec2iFromVec2Floor converts from floating point mat32.Vec2 vector to int, using floor
func NewVec2iFromVec2Floor(v mat32.Vec2) Vec2i {
return Vec2i{int(mat32.Floor(v.X)), int(mat32.Floor(v.Y))}
// NewVec2iFromVec2Floor converts from floating point math32.Vec2 vector to int, using floor
func NewVec2iFromVec2Floor(v math32.Vec2) Vec2i {
return Vec2i{int(math32.Floor(v.X)), int(math32.Floor(v.Y))}
}

// NewVec2iFromVec2Ceil converts from floating point mat32.Vec2 vector to int, using ceil
func NewVec2iFromVec2Ceil(v mat32.Vec2) Vec2i {
return Vec2i{X: int(mat32.Ceil(v.X)), Y: int(mat32.Ceil(v.Y))}
// NewVec2iFromVec2Ceil converts from floating point math32.Vec2 vector to int, using ceil
func NewVec2iFromVec2Ceil(v math32.Vec2) Vec2i {
return Vec2i{X: int(math32.Ceil(v.X)), Y: int(math32.Ceil(v.Y))}
}

// ToVec2 returns floating point mat32.Vec2 from int
func (v Vec2i) ToVec2() mat32.Vec2 {
return mat32.V2(float32(v.X), float32(v.Y))
// ToVec2 returns floating point math32.Vec2 from int
func (v Vec2i) ToVec2() math32.Vec2 {
return math32.V2(float32(v.X), float32(v.Y))
}

// IsNil returns true if all values are 0 (uninitialized).
Expand Down
2 changes: 1 addition & 1 deletion looper/manager.go
Expand Up @@ -11,7 +11,7 @@ import (
"strconv"
"strings"

"cogentcore.org/core/glop/indent"
"cogentcore.org/core/gox/indent"
"github.com/emer/emergent/v2/etime"
)

Expand Down
2 changes: 1 addition & 1 deletion netparams/io.go
Expand Up @@ -13,7 +13,7 @@ import (
"os"

"cogentcore.org/core/gi"
"cogentcore.org/core/glop/indent"
"cogentcore.org/core/gox/indent"

Check failure on line 16 in netparams/io.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package cogentcore.org/core/gox/indent; to add it:
"cogentcore.org/core/grows"
"cogentcore.org/core/grows/jsons"
"cogentcore.org/core/grows/tomls"
Expand Down
8 changes: 4 additions & 4 deletions netview/data.go
Expand Up @@ -5,7 +5,7 @@
package netview

import (
"cogentcore.org/core/mat32"
"cogentcore.org/core/math32"
"github.com/emer/emergent/v2/emer"
)

Expand Down Expand Up @@ -101,9 +101,9 @@ func (pd *PrjnData) RecordData(nd *NetData) {
mn := &nd.SynMinVar[nvi]
mx := &nd.SynMaxVar[nvi]
for _, vl := range sv {
if !mat32.IsNaN(vl) {
*mn = mat32.Min(*mn, vl)
*mx = mat32.Max(*mx, vl)
if !math32.IsNaN(vl) {
*mn = math32.Min(*mn, vl)
*mx = math32.Max(*mx, vl)
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions netview/events.go
Expand Up @@ -10,7 +10,7 @@ import (
"cogentcore.org/core/events"
"cogentcore.org/core/gi"
"cogentcore.org/core/giv"
"cogentcore.org/core/mat32"
"cogentcore.org/core/math32"
"cogentcore.org/core/xyz"
"cogentcore.org/core/xyzv"
"github.com/emer/emergent/v2/emer"
Expand Down Expand Up @@ -121,10 +121,10 @@ func (sw *Scene) LayerUnitAtPoint(e events.Event) (lay emer.Layer, lx, ly, unInd
}
nv := sw.NetView
nmin, nmax := nv.Net.Bounds()
nsz := nmax.Sub(nmin).Sub(mat32.V3(1, 1, 0)).Max(mat32.V3(1, 1, 1))
nsc := mat32.V3(1.0/nsz.X, 1.0/nsz.Y, 1.0/nsz.Z)
szc := mat32.Max(nsc.X, nsc.Y)
poff := mat32.V3Scalar(0.5)
nsz := nmax.Sub(nmin).Sub(math32.V3(1, 1, 0)).Max(math32.V3(1, 1, 1))
nsc := math32.V3(1.0/nsz.X, 1.0/nsz.Y, 1.0/nsz.Z)
szc := math32.Max(nsc.X, nsc.Y)
poff := math32.V3Scalar(0.5)
poff.Y = -0.5
for li, lgi := range *laysGp.Children() {
lay = nv.Net.Layer(li)
Expand All @@ -139,7 +139,7 @@ func (sw *Scene) LayerUnitAtPoint(e events.Event) (lay emer.Layer, lx, ly, unInd
ray := lo.RayPick(pos)
// layer is in XZ plane with norm pointing up in Y axis
// offset is 0 in local coordinates
plane := mat32.Plane{Norm: mat32.V3(0, 1, 0), Off: 0}
plane := math32.Plane{Norm: math32.V3(0, 1, 0), Off: 0}
pt, ok := ray.IntersectPlane(plane)
if !ok || pt.Z > 0 { // Z > 0 means clicked "in front" of plane -- where labels are
continue
Expand Down

0 comments on commit d2c953f

Please sign in to comment.