+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions core/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ func (ls *geomSize) setInitContentMin(styMin math32.Vector2) {
styles.SetClampMaxVector(csz, ls.Max)
}

// fitSizeMax increases given size to fit given fm value, subject to Max constraints
func (ls *geomSize) fitSizeMax(to *math32.Vector2, fm math32.Vector2) {
// FitSizeMax increases given size to fit given fm value, subject to Max constraints
func (ls *geomSize) FitSizeMax(to *math32.Vector2, fm math32.Vector2) {
styles.SetClampMinVector(to, fm)
styles.SetClampMaxVector(to, ls.Max)
}
Expand Down Expand Up @@ -735,8 +735,8 @@ func (wb *WidgetBase) updateParentRelSizes() bool {
}
}
if got {
sz.fitSizeMax(&sz.Actual.Total, sz.Min)
sz.fitSizeMax(&sz.Alloc.Total, sz.Min)
sz.FitSizeMax(&sz.Actual.Total, sz.Min)
sz.FitSizeMax(&sz.Alloc.Total, sz.Min)
sz.setContentFromTotal(&sz.Actual)
sz.setContentFromTotal(&sz.Alloc)
}
Expand All @@ -750,7 +750,7 @@ func (wb *WidgetBase) sizeUpParts() {
}
wb.Parts.SizeUp()
sz := &wb.Geom.Size
sz.fitSizeMax(&sz.Actual.Content, wb.Parts.Geom.Size.Actual.Total)
sz.FitSizeMax(&sz.Actual.Content, wb.Parts.Geom.Size.Actual.Total)
}

func (fr *Frame) SizeUp() {
Expand Down Expand Up @@ -1532,7 +1532,7 @@ func (wb *WidgetBase) sizeFinalParts() {
}
wb.Parts.SizeFinal()
sz := &wb.Geom.Size
sz.fitSizeMax(&sz.Actual.Content, wb.Parts.Geom.Size.Actual.Total)
sz.FitSizeMax(&sz.Actual.Content, wb.Parts.Geom.Size.Actual.Total)
}

func (fr *Frame) SizeFinal() {
Expand Down
4 changes: 2 additions & 2 deletions core/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func (tx *Text) SizeUp() {
tx.configTextSize(sz.Actual.Content)
}
rsz := tx.paintText.BBox.Size().Ceil()
sz.fitSizeMax(&sz.Actual.Content, rsz)
sz.FitSizeMax(&sz.Actual.Content, rsz)
sz.setTotalFromContent(&sz.Actual)
if DebugSettings.LayoutTrace {
fmt.Println(tx, "Text SizeUp:", rsz, "Actual:", sz.Actual.Content)
Expand All @@ -344,7 +344,7 @@ func (tx *Text) SizeDown(iter int) bool {
prevContent := sz.Actual.Content
// start over so we don't reflect hysteresis of prior guess
sz.setInitContentMin(tx.Styles.Min.Dots().Ceil())
sz.fitSizeMax(&sz.Actual.Content, rsz)
sz.FitSizeMax(&sz.Actual.Content, rsz)
sz.setTotalFromContent(&sz.Actual)
chg := prevContent != sz.Actual.Content
if chg {
Expand Down
4 changes: 2 additions & 2 deletions core/textfield.go
Original file line number Diff line number Diff line change
Expand Up @@ -1859,7 +1859,7 @@ func (tf *TextField) SizeUp() {
rsz = tf.configTextSize(availSz)
}
rsz.SetAdd(icsz)
sz.fitSizeMax(&sz.Actual.Content, rsz)
sz.FitSizeMax(&sz.Actual.Content, rsz)
sz.setTotalFromContent(&sz.Actual)
tf.fontHeight = tf.Styles.Font.Face.Metrics.Height
tf.editText = tmptxt
Expand All @@ -1881,7 +1881,7 @@ func (tf *TextField) SizeDown(iter int) bool {
rsz.SetAdd(icsz)
// start over so we don't reflect hysteresis of prior guess
sz.setInitContentMin(tf.Styles.Min.Dots().Ceil())
sz.fitSizeMax(&sz.Actual.Content, rsz)
sz.FitSizeMax(&sz.Actual.Content, rsz)
sz.setTotalFromContent(&sz.Actual)
chg := prevContent != sz.Actual.Content
if chg {
Expand Down
6 changes: 0 additions & 6 deletions tensor/projection2d.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const (
// For any odd number of dimensions, the remaining outer-most dimension
// can either be multipliexed across the row or column, given the oddRow arg.
// Even multiples of inner-most dimensions are assumed to be row, then column.
// RowMajor and ColMajor layouts are handled appropriately.
// rowEx returns the number of "extra" (higher dimensional) rows
// and colEx returns the number of extra cols
func Projection2DShape(shp *Shape, oddRow bool) (rows, cols, rowEx, colEx int) {
Expand Down Expand Up @@ -59,7 +58,6 @@ func Projection2DShape(shp *Shape, oddRow bool) (rows, cols, rowEx, colEx int) {
// For any odd number of dimensions, the remaining outer-most dimension
// can either be multipliexed across the row or column, given the oddRow arg.
// Even multiples of inner-most dimensions are assumed to be row, then column.
// RowMajor and ColMajor layouts are handled appropriately.
func Projection2DIndex(shp *Shape, oddRow bool, row, col int) int {
nd := shp.NumDims()
switch nd {
Expand Down Expand Up @@ -146,7 +144,6 @@ func Projection2DCoords(shp *Shape, oddRow bool, row, col int) (rowCoords, colCo
// For any odd number of dimensions, the remaining outer-most dimension
// can either be multipliexed across the row or column, given the oddRow arg.
// Even multiples of inner-most dimensions are assumed to be row, then column.
// RowMajor and ColMajor layouts are handled appropriately.
func Projection2DValue(tsr Tensor, oddRow bool, row, col int) float64 {
idx := Projection2DIndex(tsr.Shape(), oddRow, row, col)
return tsr.Float1D(idx)
Expand All @@ -157,7 +154,6 @@ func Projection2DValue(tsr Tensor, oddRow bool, row, col int) float64 {
// For any odd number of dimensions, the remaining outer-most dimension
// can either be multipliexed across the row or column, given the oddRow arg.
// Even multiples of inner-most dimensions are assumed to be row, then column.
// RowMajor and ColMajor layouts are handled appropriately.
func Projection2DString(tsr Tensor, oddRow bool, row, col int) string {
idx := Projection2DIndex(tsr.Shape(), oddRow, row, col)
return tsr.String1D(idx)
Expand All @@ -168,7 +164,6 @@ func Projection2DString(tsr Tensor, oddRow bool, row, col int) string {
// For any odd number of dimensions, the remaining outer-most dimension
// can either be multipliexed across the row or column, given the oddRow arg.
// Even multiples of inner-most dimensions are assumed to be row, then column.
// RowMajor and ColMajor layouts are handled appropriately.
func Projection2DSet(tsr Tensor, oddRow bool, row, col int, val float64) {
idx := Projection2DIndex(tsr.Shape(), oddRow, row, col)
tsr.SetFloat1D(idx, val)
Expand All @@ -179,7 +174,6 @@ func Projection2DSet(tsr Tensor, oddRow bool, row, col int, val float64) {
// For any odd number of dimensions, the remaining outer-most dimension
// can either be multipliexed across the row or column, given the oddRow arg.
// Even multiples of inner-most dimensions are assumed to be row, then column.
// RowMajor and ColMajor layouts are handled appropriately.
func Projection2DSetString(tsr Tensor, oddRow bool, row, col int, val string) {
idx := Projection2DIndex(tsr.Shape(), oddRow, row, col)
tsr.SetString1D(idx, val)
Expand Down
2 changes: 1 addition & 1 deletion tensor/stats/clust/clust_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestClust(t *testing.T) {
}
ix := table.NewIndexView(dt)
smat := &simat.SimMat{}
smat.TableCol(ix, "Input", "Name", false, metric.Euclidean64)
smat.TableColumn(ix, "Input", "Name", false, metric.Euclidean64)

// fmt.Printf("%v\n", smat.Mat)
// cl := Glom(smat, MinDist)
Expand Down
20 changes: 10 additions & 10 deletions tensor/stats/pca/covar.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"cogentcore.org/core/tensor/table"
)

// CovarTableCol generates a covariance matrix from given column name
// CovarTableColumn generates a covariance matrix from given column name
// in given IndexView of an table.Table, and given metric function
// (typically Covariance or Correlation -- use Covar if vars have similar
// overall scaling, which is typical in neural network models, and use
Expand All @@ -22,15 +22,15 @@ import (
// cell co-varies in its value with each other cell across the rows of the table.
// This is the input to the PCA eigenvalue decomposition of the resulting
// covariance matrix.
func CovarTableCol(cmat tensor.Tensor, ix *table.IndexView, column string, mfun metric.Func64) error {
func CovarTableColumn(cmat tensor.Tensor, ix *table.IndexView, column string, mfun metric.Func64) error {
col, err := ix.Table.ColumnByName(column)
if err != nil {
return err
}
rows := ix.Len()
nd := col.NumDims()
if nd < 2 || rows == 0 {
return fmt.Errorf("pca.CovarTableCol: must have 2 or more dims and rows != 0")
return fmt.Errorf("pca.CovarTableColumn: must have 2 or more dims and rows != 0")
}
ln := col.Len()
sz := ln / col.DimSize(0) // size of cell
Expand All @@ -43,10 +43,10 @@ func CovarTableCol(cmat tensor.Tensor, ix *table.IndexView, column string, mfun
sdim := []int{0, 0}
for ai := 0; ai < sz; ai++ {
sdim[0] = ai
TableColRowsVec(av, ix, col, ai)
TableColumnRowsVec(av, ix, col, ai)
for bi := 0; bi <= ai; bi++ { // lower diag
sdim[1] = bi
TableColRowsVec(bv, ix, col, bi)
TableColumnRowsVec(bv, ix, col, bi)
cv := mfun(av, bv)
cmat.SetFloat(sdim, cv)
}
Expand Down Expand Up @@ -137,9 +137,9 @@ func CovarTensor(cmat tensor.Tensor, tsr tensor.Tensor, mfun metric.Func64) erro
return nil
}

// TableColRowsVec extracts row-wise vector from given cell index into vec.
// TableColumnRowsVec extracts row-wise vector from given cell index into vec.
// vec must be of size ix.Len() -- number of rows
func TableColRowsVec(vec []float64, ix *table.IndexView, col tensor.Tensor, cidx int) {
func TableColumnRowsVec(vec []float64, ix *table.IndexView, col tensor.Tensor, cidx int) {
rows := ix.Len()
ln := col.Len()
sz := ln / col.DimSize(0) // size of cell
Expand All @@ -161,7 +161,7 @@ func TensorRowsVec(vec []float64, tsr tensor.Tensor, cidx int) {
}
}

// CovarTableColStd generates a covariance matrix from given column name
// CovarTableColumnStd generates a covariance matrix from given column name
// in given IndexView of an table.Table, and given metric function
// (typically Covariance or Correlation -- use Covar if vars have similar
// overall scaling, which is typical in neural network models, and use
Expand All @@ -172,8 +172,8 @@ func TensorRowsVec(vec []float64, tsr tensor.Tensor, cidx int) {
// This is the input to the PCA eigenvalue decomposition of the resulting
// covariance matrix.
// This Std version is usable e.g., in Python where the func cannot be passed.
func CovarTableColStd(cmat tensor.Tensor, ix *table.IndexView, column string, met metric.StdMetrics) error {
return CovarTableCol(cmat, ix, column, metric.StdFunc64(met))
func CovarTableColumnStd(cmat tensor.Tensor, ix *table.IndexView, column string, met metric.StdMetrics) error {
return CovarTableColumn(cmat, ix, column, metric.StdFunc64(met))
}

// CovarTensorStd generates a covariance matrix from given tensor.Tensor,
Expand Down
30 changes: 15 additions & 15 deletions tensor/stats/pca/pca.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (pa *PCA) Init() {
pa.Values = nil
}

// TableCol is a convenience method that computes a covariance matrix
// TableColumn is a convenience method that computes a covariance matrix
// on given column of table and then performs the PCA on the resulting matrix.
// If no error occurs, the results can be read out from Vectors and Values
// or used in Projection methods.
Expand All @@ -48,11 +48,11 @@ func (pa *PCA) Init() {
// This is the input to the PCA eigenvalue decomposition of the resulting
// covariance matrix, which extracts the eigenvectors as directions with maximal
// variance in this matrix.
func (pa *PCA) TableCol(ix *table.IndexView, column string, mfun metric.Func64) error {
func (pa *PCA) TableColumn(ix *table.IndexView, column string, mfun metric.Func64) error {
if pa.Covar == nil {
pa.Init()
}
err := CovarTableCol(pa.Covar, ix, column, mfun)
err := CovarTableColumn(pa.Covar, ix, column, mfun)
if err != nil {
return err
}
Expand Down Expand Up @@ -83,7 +83,7 @@ func (pa *PCA) Tensor(tsr tensor.Tensor, mfun metric.Func64) error {
return pa.PCA()
}

// TableColStd is a convenience method that computes a covariance matrix
// TableColumnStd is a convenience method that computes a covariance matrix
// on given column of table and then performs the PCA on the resulting matrix.
// If no error occurs, the results can be read out from Vectors and Values
// or used in Projection methods.
Expand All @@ -97,8 +97,8 @@ func (pa *PCA) Tensor(tsr tensor.Tensor, mfun metric.Func64) error {
// covariance matrix, which extracts the eigenvectors as directions with maximal
// variance in this matrix.
// This Std version is usable e.g., in Python where the func cannot be passed.
func (pa *PCA) TableColStd(ix *table.IndexView, column string, met metric.StdMetrics) error {
return pa.TableCol(ix, column, metric.StdFunc64(met))
func (pa *PCA) TableColumnStd(ix *table.IndexView, column string, met metric.StdMetrics) error {
return pa.TableColumn(ix, column, metric.StdFunc64(met))
}

// TensorStd is a convenience method that computes a covariance matrix
Expand Down Expand Up @@ -145,20 +145,20 @@ func (pa *PCA) PCA() error {
return nil
}

// ProjectCol projects values from the given column of given table (via IndexView)
// ProjectColumn projects values from the given column of given table (via IndexView)
// onto the idx'th eigenvector (0 = largest eigenvalue, 1 = next, etc).
// Must have already called PCA() method.
func (pa *PCA) ProjectCol(vals *[]float64, ix *table.IndexView, column string, idx int) error {
func (pa *PCA) ProjectColumn(vals *[]float64, ix *table.IndexView, column string, idx int) error {
col, err := ix.Table.ColumnByName(column)
if err != nil {
return err
}
if pa.Vectors == nil {
return fmt.Errorf("PCA.ProjectCol Vectors are nil -- must call PCA first")
return fmt.Errorf("PCA.ProjectColumn Vectors are nil -- must call PCA first")
}
nr := pa.Vectors.DimSize(0)
if idx >= nr {
return fmt.Errorf("PCA.ProjectCol eigenvector index > rank of matrix")
return fmt.Errorf("PCA.ProjectColumn eigenvector index > rank of matrix")
}
cvec := make([]float64, nr)
eidx := nr - 1 - idx // eigens in reverse order
Expand All @@ -173,7 +173,7 @@ func (pa *PCA) ProjectCol(vals *[]float64, ix *table.IndexView, column string, i
ln := col.Len()
sz := ln / col.DimSize(0) // size of cell
if sz != nr {
return fmt.Errorf("PCA.ProjectCol column cell size != pca eigenvectors")
return fmt.Errorf("PCA.ProjectColumn column cell size != pca eigenvectors")
}
rdim := []int{0}
for row := 0; row < rows; row++ {
Expand All @@ -188,17 +188,17 @@ func (pa *PCA) ProjectCol(vals *[]float64, ix *table.IndexView, column string, i
return nil
}

// ProjectColToTable projects values from the given column of given table (via IndexView)
// ProjectColumnToTable projects values from the given column of given table (via IndexView)
// onto the given set of eigenvectors (idxs, 0 = largest eigenvalue, 1 = next, etc),
// and stores results along with labels from column labNm into results table.
// Must have already called PCA() method.
func (pa *PCA) ProjectColToTable(projections *table.Table, ix *table.IndexView, column, labNm string, idxs []int) error {
func (pa *PCA) ProjectColumnToTable(projections *table.Table, ix *table.IndexView, column, labNm string, idxs []int) error {
_, err := ix.Table.ColumnByName(column)
if err != nil {
return err
}
if pa.Vectors == nil {
return fmt.Errorf("PCA.ProjectCol Vectors are nil -- must call PCA first")
return fmt.Errorf("PCA.ProjectColumn Vectors are nil -- must call PCA first")
}
rows := ix.Len()
projections.DeleteAll()
Expand All @@ -214,7 +214,7 @@ func (pa *PCA) ProjectColToTable(projections *table.Table, ix *table.IndexView,

for ii, idx := range idxs {
pcol := projections.Columns[pcolSt+ii].(*tensor.Float64)
pa.ProjectCol(&pcol.Values, ix, column, idx)
pa.ProjectColumn(&pcol.Values, ix, column, idx)
}

if labNm != "" {
Expand Down
6 changes: 3 additions & 3 deletions tensor/stats/pca/pca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func TestPCAIris(t *testing.T) {
}
ix := table.NewIndexView(dt)
pc := &PCA{}
// pc.TableCol(ix, "data", metric.Covariance64)
// pc.TableColumn(ix, "data", metric.Covariance64)
// fmt.Printf("covar: %v\n", pc.Covar)
err = pc.TableCol(ix, "data", metric.Correlation64)
err = pc.TableColumn(ix, "data", metric.Correlation64)
if err != nil {
t.Error(err)
}
Expand All @@ -47,7 +47,7 @@ func TestPCAIris(t *testing.T) {
}

prjt := &table.Table{}
err = pc.ProjectColToTable(prjt, ix, "data", "class", []int{0, 1})
err = pc.ProjectColumnToTable(prjt, ix, "data", "class", []int{0, 1})
if err != nil {
t.Error(err)
}
Expand Down
Loading
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载