数据离散化
来源:互联网 发布:淘宝财富值在哪看 编辑:程序博客网 时间:2024/06/08 06:02
离散化:把无限空间中有限的个体映射到有限的空间中去,以此提高算法的时空效率。
通俗的说,离散化是在不改变数据相对大小的条件下,对数据进行相应的缩小。例如:
原数据:1,999,100000,15
离散化后:1,3,4,2
如果我们关注的不是数据本身的大小,而是数据的相对大小,则可以使用离散化处理。
实现:
把N个大小不确定的数映射到1-N的数列上:
package study;import java.util.*;/*** @file Discretization.java* @CopyRight (C) http://blog.csdn.net/x_iya* @Description 离散化* @author N3verL4nd* @email lgh1992314@qq.com* @date 2017/9/11*/public class Discretization { class Node implements Comparable<Node> { int pos; int value; public Node(int pos, int value) { this.pos = pos; this.value = value; } @Override public int compareTo(Node o) { if (value == o.value) { return pos - o.pos; } return value - o.value; } } public void discrete(int[] arr) { int len = arr.length; Node[] nodes = new Node[len]; for (int i = 0; i < len; i++) { nodes[i] = new Node(i, arr[i]); } Arrays.sort(nodes); int i, j; for (i = 0, j = 1; i < len - 1; i++, j++) { arr[nodes[i].pos] = j; if (nodes[i].value == nodes[i + 1].value) { j--; } } arr[nodes[i].pos] = j; } public static void main(String[] args) { // 构造随机序列 Random random = new Random(); int len = random.nextInt(10); int arr[] = new int[len]; for (int i = 0; i < len; i++) { arr[i] = random.nextInt(100); } // 打印随机序列 System.out.println(Arrays.toString(arr)); // 离散化 Discretization discretization = new Discretization(); discretization.discrete(arr); // 打印离散化后的随机序列 System.out.println(Arrays.toString(arr)); }}
相同的元素需要进行特殊处理。
阅读全文
0 0
- 数据的离散化
- 数据的离散化
- 数据的离散化
- 数据的离散化
- 数据离散化杂谈
- 数据离散化
- 数据离散化
- 数据的离散化
- 数据离散化
- 数据的离散化
- 数据的离散化
- 数据离散化
- 数据离散化
- 【学习】数据离散化
- 数据离散化
- 数据离散化
- 数据的离散化
- 浅谈数据离散化
- 使用HTML语言和CSS开发商业站点_浮动
- GitChat · 移动开发 | 征服React Native—列表组件
- POJ3349总结(第一次用hash解决问题)
- JS获取各类窗口大小
- RecyclerView.Adapter的某个item中EditText的输入后所有列表中Editetext全部被修改的问题
- 数据离散化
- LeetCode 98. Validate Binary Search Tree
- Docker安装(三)
- SQL Server2000在只有主库mdf文件下的恢复
- 我对不起党,对不起国家,对不起人民HDU6201 补题(disj)
- Ubuntu14.04 下 OpenCV3 安装
- 呵呵,作为一个胖子做不到的事情,作为一个产妇能做到
- SQL GUID和自增列做主键的优缺点
- .net c# for HttpWebResponse 抓取网页信息走多网卡,配置各种参数