Skip to content
Open
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
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/rebeku/metric-multidimensional-scaling

go 1.24.4

require gonum.org/v1/gonum v0.16.0 // indirect
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
8 changes: 4 additions & 4 deletions mms.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func NewMMS(nComponents, maxIter int, epsilon float64) *MMS {
// along with the final minimum value of the stress function.
func (mms *MMS) FitTransform(d *mat.SymDense) (*mat.Dense, float64) {
mms.dissimilarity = d
init := randomMatrix(d.Symmetric(), mms.nComponents)
init := randomMatrix(d.SymmetricDim(), mms.nComponents)
return mms.smacof(0, init)
}

Expand Down Expand Up @@ -120,7 +120,7 @@ func rowDistance(i, j int, X *mat.Dense) float64 {
// current and ideal distances for each point.
func stress(Xdis *mat.SymDense, d *mat.SymDense) float64 {
sigma := 0.0
n := Xdis.Symmetric()
n := Xdis.SymmetricDim()
pairs := pairwiseIterator(n)
for _, pair := range pairs {
i, j := pair[0], pair[1]
Expand All @@ -145,7 +145,7 @@ func pairwiseIterator(n int) [][]int {
}

func guttmanTransformation(X *mat.Dense, Xdis, dis *mat.SymDense) {
n := Xdis.Symmetric()
n := Xdis.SymmetricDim()
replaceZeros(Xdis)
B := mat.NewDense(n, n, nil)
B.DivElem(dis, Xdis)
Expand All @@ -157,7 +157,7 @@ func guttmanTransformation(X *mat.Dense, Xdis, dis *mat.SymDense) {
}

func replaceZeros(Xdis *mat.SymDense) {
n := Xdis.Symmetric()
n := Xdis.SymmetricDim()
pairs := pairwiseIterator(n)
for _, pair := range pairs {
i, j := pair[0], pair[1]
Expand Down
10 changes: 0 additions & 10 deletions mms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,6 @@ func TestImpossibleSetup(t *testing.T) {
}
}

func TestEmpty(t *testing.T) {
d := mat.NewSymDense(0, nil)
mms := NewMMS(2, 30, .01)
_, stress := mms.FitTransform(d)

if stress != 0.0 {
t.Error("Expected 0 but found ", stress)
}
}

func TestStressPerfect(t *testing.T) {
a := math.Sqrt(2)
u := make([]float64, 9) // Unit vectors along X, Y, Z axes
Expand Down