• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang cluster.DistanceMatrix类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang base.Horner函数代码示例发布时间:2022-05-28
下一篇:
Golang gosnmp.GoSNMP类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap