Algorithms 练习2.5.19--Kendall tau距离
来源:互联网 发布:幼儿编程app 编辑:程序博客网 时间:2024/05/16 12:20
Kendall tau distance.Write a program KendallTau.javathat computes the Kendall tau distance between two permutations in linearithmic time
public class KendallTau { // return Kendall tau distance between two permutations public static long distance(int[] a, int[] b) { if (a.length != b.length) { throw new IllegalArgumentException("Array dimensions disagree"); } int n = a.length; int[] ainv = new int[n]; for (int i = 0; i < n; i++) ainv[a[i]] = i;//将a[]中元素和下标交换得ainv[] Integer[] bnew = new Integer[n]; for (int i = 0; i < n; i++) bnew[i] = ainv[b[i]];//将b[]中元素对应的a[]中元素的下标给bnew[],构成一个双下标数组bnew[],该数组下标为b[]的下标,该数组元素为a[]的下标 return Inversions.count(bnew);//计算bnew中的逆序数的个数即为逆序对数 } // return a random permutation of size n public static int[] permutation(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = i; StdRandom.shuffle(a); return a; } public static void main(String[] args) { // two random permutation of size n int n = Integer.parseInt(args[0]); int[] a = KendallTau.permutation(n); int[] b = KendallTau.permutation(n); // print initial permutation for (int i = 0; i < n; i++) StdOut.println(a[i] + " " + b[i]); StdOut.println(); StdOut.println("inversions = " + KendallTau.distance(a, b)); }}
阅读全文
0 0
- Algorithms 练习2.5.19--Kendall tau距离
- 公正的选举Unbiased election 《算法》2.5.16, 检测稳定性 《算法》2.5.17 , 强制稳定 《算法》2.5.18, Kendall tau距离 《算法》2.5.19
- Kendall tau距离:求两个排列之间的逆序数
- Kendall tau距离:求两个排列之间的逆序数
- Kendall's tau
- 九、排序算法的应用(找中位数、重复统计、Kendall tau距离等)
- 求两个数组的逆序数——Kendall tau距离
- Kendall tau rank correlation coefficient
- Kendall's tau 相似程度指标
- Kendall's tau -- 相似程度指标
- 相关性研究的非参数方法:Spearman的秩相关系数和Kendall tau秩相关系数
- 第八次作业Kendall's tau相似程度指标NO.3
- Algorithms 练习1.1.11
- Algorithms 练习1.1.13
- Algorithms 练习1.1.14
- Algorithms 练习1.1.15
- Algorithms 练习1.4.6
- Algorithms 练习1.5.7
- highcharts使用钻取图时去掉横坐标上的超链接样式 。
- nifi中使用PutElasticsearch
- react-native纯JS上下拉刷新组件
- Redis模糊操作
- 一大波代码------>自定义圆
- Algorithms 练习2.5.19--Kendall tau距离
- 将DNS改成8.8.8.8有什么利与弊?
- C#基础(6)——常量/枚举/结构/数组
- 一元多项式相加减(数据结构)
- 特殊的数字
- Codeforces 877D Olya and Energy Drinks【思维优化Bfs】
- C#中的 int?是什么意思
- spring配置文件头部xmlns配置解说
- gradle使用本地maven库