MCPcopy Create free account
hub / github.com/cogentcore/core / TableCol

Method TableCol

tensor/stats/simat/simat.go:50–130  ·  view source on GitHub ↗

TableCol generates a similarity / distance matrix from given column name in given IndexView of an table.Table, and given metric function. if labNm is not empty, uses given column name for labels, which if blankRepeat is true are filtered so that any sequentially repeated labels are blank.

(ix *table.IndexView, column, labNm string, blankRepeat bool, mfun metric.Func64)

Source from the content-addressed store, hash-verified

48// if labNm is not empty, uses given column name for labels, which if blankRepeat
49// is true are filtered so that any sequentially repeated labels are blank.
50func (smat *SimMat) TableCol(ix *table.IndexView, column, labNm string, blankRepeat bool, mfun metric.Func64) error {
51 col, err := ix.Table.ColumnByNameTry(column)
52 if err != nil {
53 return err
54 }
55 smat.Init()
56 sm := smat.Mat
57
58 rows := ix.Len()
59 nd := col.NumDims()
60 if nd < 2 || rows == 0 {
61 return fmt.Errorf("simat.Tensor: must have 2 or more dims and rows != 0")
62 }
63 ln := col.Len()
64 sz := ln / col.DimSize(0) // size of cell
65
66 sshp := []int{rows, rows}
67 sm.SetShape(sshp)
68
69 av := make([]float64, sz)
70 bv := make([]float64, sz)
71 ardim := []int{0}
72 brdim := []int{0}
73 sdim := []int{0, 0}
74 for ai := 0; ai < rows; ai++ {
75 ardim[0] = ix.Indexes[ai]
76 sdim[0] = ai
77 ar := col.SubSpace(ardim)
78 ar.Floats(&av)
79 for bi := 0; bi <= ai; bi++ { // lower diag
80 brdim[0] = ix.Indexes[bi]
81 sdim[1] = bi
82 br := col.SubSpace(brdim)
83 br.Floats(&bv)
84 sv := mfun(av, bv)
85 sm.SetFloat(sdim, sv)
86 }
87 }
88 // now fill in upper diagonal with values from lower diagonal
89 // note: assumes symmetric distance function
90 fdim := []int{0, 0}
91 for ai := 0; ai < rows; ai++ {
92 sdim[0] = ai
93 fdim[1] = ai
94 for bi := ai + 1; bi < rows; bi++ { // upper diag
95 fdim[0] = bi
96 sdim[1] = bi
97 sv := sm.Float(fdim)
98 sm.SetFloat(sdim, sv)
99 }
100 }
101
102 if nm, has := ix.Table.MetaData["name"]; has {
103 sm.SetMetaData("name", nm+"_"+column)
104 } else {
105 sm.SetMetaData("name", column)
106 }
107 if ds, has := ix.Table.MetaData["desc"]; has {

Callers 3

TableColStdMethod · 0.95
TestSimMatFunction · 0.95
TestClustFunction · 0.95

Calls 13

InitMethod · 0.95
ColumnByNameTryMethod · 0.80
LenMethod · 0.65
NumDimsMethod · 0.65
ErrorfMethod · 0.65
DimSizeMethod · 0.65
SetShapeMethod · 0.65
SubSpaceMethod · 0.65
FloatsMethod · 0.65
SetFloatMethod · 0.65
FloatMethod · 0.65
SetMetaDataMethod · 0.65

Tested by 2

TestSimMatFunction · 0.76
TestClustFunction · 0.76