當前位置: 首頁>>代碼示例>>Golang>>正文


Golang cluster.DistanceMatrix類代碼示例

本文整理匯總了Golang中github.com/soniakeys/cluster.DistanceMatrix的典型用法代碼示例。如果您正苦於以下問題:Golang DistanceMatrix類的具體用法?Golang DistanceMatrix怎麽用?Golang DistanceMatrix使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了DistanceMatrix類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ExampleDistanceMatrix_NeighborJoin

func ExampleDistanceMatrix_NeighborJoin() {
	d := cluster.DistanceMatrix{
		{0, 23, 27, 20},
		{23, 0, 30, 28},
		{27, 30, 0, 30},
		{20, 28, 30, 0},
	}
	tree, wt := d.NeighborJoin()
	fmt.Println("n1  n2  weight")
	for n, to := range tree.LabeledAdjacencyList {
		for _, h := range to {
			fmt.Printf("%d  %2d   %6.3f\n", n, h.To, wt[h.Label])
		}
	}
	// Output:
	// n1  n2  weight
	// 0   5    8.000
	// 1   4   13.500
	// 2   4   16.500
	// 3   5   12.000
	// 4   5    2.000
	// 4   1   13.500
	// 4   2   16.500
	// 5   3   12.000
	// 5   0    8.000
	// 5   4    2.000
}
開發者ID:soniakeys,項目名稱:cluster,代碼行數:27,代碼來源:dist_matrix_test.go

示例2: ExampleDistanceMatrix_AdditiveTree

func ExampleDistanceMatrix_AdditiveTree() {
	d := cluster.DistanceMatrix{
		{0, 13, 21, 22},
		{13, 0, 12, 13},
		{21, 12, 0, 13},
		{22, 13, 13, 0},
	}
	t, wts := d.AdditiveTree()
	for n, to := range t.LabeledAdjacencyList {
		for _, to := range to {
			fmt.Printf("%d: to %d label %d weight %g\n",
				n, to.To, to.Label, wts[to.Label])
		}
	}
	// Output:
	// 0: to 4 label 1 weight 11
	// 1: to 4 label 0 weight 2
	// 2: to 5 label 2 weight 6
	// 3: to 5 label 4 weight 7
	// 4: to 1 label 0 weight 2
	// 4: to 0 label 1 weight 11
	// 4: to 5 label 3 weight 4
	// 5: to 2 label 2 weight 6
	// 5: to 4 label 3 weight 4
	// 5: to 3 label 4 weight 7
}
開發者ID:soniakeys,項目名稱:cluster,代碼行數:26,代碼來源:dist_matrix_test.go

示例3: ExampleDistanceMatrix_Square

func ExampleDistanceMatrix_Square() {
	d1 := cluster.DistanceMatrix{
		{0, 3},
		{3, 0},
	}
	d2 := cluster.DistanceMatrix{}
	d3 := cluster.DistanceMatrix{
		{0},
		{3, 0},
	}
	fmt.Println(d1.Square())
	fmt.Println(d2.Square())
	fmt.Println(d3.Square())
	// Output:
	// true
	// true
	// false
}
開發者ID:soniakeys,項目名稱:cluster,代碼行數:18,代碼來源:dist_matrix_test.go

示例4: ExampleDistanceMatrix_Ultrametric

func ExampleDistanceMatrix_Ultrametric() {
	d := cluster.DistanceMatrix{
		{0, 20, 17, 11},
		{20, 0, 20, 13},
		{17, 20, 0, 10},
		{11, 13, 10, 0},
	}
	pl, ul := d.Ultrametric(cluster.DAVG)
	fmt.Println("node  leaves  parent  weight     age")
	for n, p := range pl.Paths {
		fmt.Printf(">%3d     %3d     %3d  %6.3f  %6.3f\n",
			n, p.Len, p.From, ul[n].Weight, ul[n].Age)
	}
	// Output:
	// node  leaves  parent  weight     age
	// >  0       1       5   7.000   0.000
	// >  1       1       6   8.833   0.000
	// >  2       1       4   5.000   0.000
	// >  3       1       4   5.000   0.000
	// >  4       2       5   2.000   5.000
	// >  5       3       6   1.833   7.000
	// >  6       4      -1     NaN   8.833
}
開發者ID:soniakeys,項目名稱:cluster,代碼行數:23,代碼來源:dist_matrix_test.go

示例5: ExampleDistanceMatrix_Additive

func ExampleDistanceMatrix_Additive() {
	a := cluster.DistanceMatrix{
		{0, 13, 21, 22},
		{13, 0, 12, 13},
		{21, 12, 0, 13},
		{22, 13, 13, 0},
	}
	na := cluster.DistanceMatrix{
		{0, 3, 4, 3},
		{3, 0, 4, 5},
		{4, 4, 0, 2},
		{3, 5, 2, 0},
	}
	fmt.Println(a.Additive())
	fmt.Println(na.Additive())
	// Output:
	// true 0 0 0 0
	// false 3 1 0 2
}
開發者ID:soniakeys,項目名稱:cluster,代碼行數:19,代碼來源:dist_matrix_test.go

示例6: ExampleDistanceMatrix_Validate

func ExampleDistanceMatrix_Validate() {
	d1 := cluster.DistanceMatrix{
		{0, 13, 21, 22},
		{13, 0, 12, 13},
		{21, 12, 0, 13},
		{22, 13, 13, 0},
	}
	d2 := cluster.DistanceMatrix{
		{0, 4, 6, 1}, // false
		{4, 0, 3, 2},
		{6, 3, 0, 5},
		{1, 2, 5, 0},
	}
	fmt.Println(d1.Validate())
	fmt.Println(d2.Validate())
	// Output:
	// <nil>
	// triangle inequality not satisfied: d[1][3] + d[3][0] < d[1][0]
}
開發者ID:soniakeys,項目名稱:cluster,代碼行數:19,代碼來源:dist_matrix_test.go

示例7: ExampleDistanceMatrix_Symmetric

func ExampleDistanceMatrix_Symmetric() {
	d1 := cluster.DistanceMatrix{
		{0, 3}, // true
		{3, 0},
	}
	d2 := cluster.DistanceMatrix{
		{0, 3}, // false
		{7, 0},
	}
	d3 := cluster.DistanceMatrix{
		{0, math.NaN()}, // false (NaNs do not compare equal)
		{math.NaN(), 0},
	}
	d4 := cluster.DistanceMatrix{
		{0, 3}, // true (diagonal is not checked)
		{3, math.NaN()},
	}
	fmt.Println(d1.Symmetric())
	fmt.Println(d2.Symmetric())
	fmt.Println(d3.Symmetric())
	fmt.Println(d4.Symmetric())
	// Output:
	// true
	// false
	// false
	// true
}
開發者ID:soniakeys,項目名稱:cluster,代碼行數:27,代碼來源:dist_matrix_test.go

示例8: ExampleDistanceMatrix_ZeroDiagonal

func ExampleDistanceMatrix_ZeroDiagonal() {
	d1 := cluster.DistanceMatrix{
		{0, 3}, // true
		{3, 0},
	}
	d2 := cluster.DistanceMatrix{
		{0}, // true
		{7, 0},
	}
	d3 := cluster.DistanceMatrix{} // true
	d4 := cluster.DistanceMatrix{
		{0, 3},
		{3, 1e-300}, // false
	}
	fmt.Println(d1.ZeroDiagonal())
	fmt.Println(d2.ZeroDiagonal())
	fmt.Println(d3.ZeroDiagonal())
	fmt.Println(d4.ZeroDiagonal())
	// Output:
	// true
	// true
	// true
	// false
}
開發者ID:soniakeys,項目名稱:cluster,代碼行數:24,代碼來源:dist_matrix_test.go

示例9: ExampleDistanceMatrix_NonNegative

func ExampleDistanceMatrix_NonNegative() {
	d1 := cluster.DistanceMatrix{
		{0, -1}, // false
		{-1, 0},
	}
	d2 := cluster.DistanceMatrix{
		{0}, // true
		{1, 2},
	}
	d3 := cluster.DistanceMatrix{} // true (no negatives present)
	d4 := cluster.DistanceMatrix{
		{0, math.NaN()}, // true
		{3, 0},
	}
	fmt.Println(d1.NonNegative())
	fmt.Println(d2.NonNegative())
	fmt.Println(d3.NonNegative())
	fmt.Println(d4.NonNegative())
	// Outpupt:
	// false
	// true
	// true
	// true
}
開發者ID:soniakeys,項目名稱:cluster,代碼行數:24,代碼來源:dist_matrix_test.go

示例10: ExampleDistanceMatrix_TriangleInequality

func ExampleDistanceMatrix_TriangleInequality() {
	d1 := cluster.DistanceMatrix{
		{0, 13, 21, 22}, // true
		{13, 0, 12, 13},
		{21, 12, 0, 13},
		{22, 13, 13, 0},
	}
	d2 := cluster.DistanceMatrix{
		{0, 13, 21, math.NaN()}, // true
		{13, 0, 12, 13},
		{21, 12, 0, 13},
		{22, 13, 13, 0},
	}
	d3 := cluster.DistanceMatrix{}
	d4 := cluster.DistanceMatrix{
		{0, 4, 6, 1}, // false
		{4, 0, 3, 2},
		{6, 3, 0, 5},
		{1, 2, 5, 0},
	}
	fmt.Println(d1.TriangleInequality())
	fmt.Println(d2.TriangleInequality())
	fmt.Println(d3.TriangleInequality())
	fmt.Println(d4.TriangleInequality())
	// Output:
	// true 0 0 0
	// true 0 0 0
	// true 0 0 0
	// false 1 3 0
}
開發者ID:soniakeys,項目名稱:cluster,代碼行數:30,代碼來源:dist_matrix_test.go


注:本文中的github.com/soniakeys/cluster.DistanceMatrix類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。