大工至善|大学至真分享 http://blog.sciencenet.cn/u/lcj2212916

博文

[转载]【源码】基于二进制搜索的快速直方图算法

已有 1499 次阅读 2019-5-17 19:01 |系统分类:科研笔记|文章来源:转载


本代码与Matlab内置的histcounts函数相比具有更快的运算速度,并提供了一个自动选择最快方法的自适应函数(hist_adaptive_method)。

This project demonstrates superior speed to Matlab's inbuilt histcounts function and provides an adaptive function (hist_adaptive_method) that automatically picks the fastest method.


直方图的最直接最简单算法是将每个bin与每个数据值(或*count*)进行比较,然后给出一个复杂度**O(n·m)**,其中*n*是数据值的数量,*m*是bin的数量。这可以通过以下两种算法进行改进。

The brute force approach to histogramming is to compare each bin to each data value (or *count*) and gives a complexity **O(n·m)** where *n* is the number of data values and *m* is the number of bins. This can be improved by two algorithms.


1. **Bin Search, O(n·log(m))**: For each count do a binary search for the histogram bin that it should go into and then increment that bin. Because the bins are already ordered then there is no sorting needed. Best when m>>n (sparse histogramming). 

to use: 

bin_counts=hist_bin_search(data,edges)


2. **Count Search, O(m·log(n))**: For each bin edge do a binary search to find the nearest data index. Use the difference in this data index between bins to give the number of counts. Must have ordered data for the search to work, sorting first would cost **O(n·log(n))** and would make this method slower unless repeated histogramming was needed. Best when n>>m (dense histogramming) which is the more common use case. (this is the method shown in the logo) 

to use: 

bin_counts=hist_count_search(data,edges) (WARNING SORTED DATA REQUIRED)


完整源码下载地址:

http://page2.dfpan.com/fs/6ldc8j52a2a1b249166/ 


更多精彩文章请关注微信号:qrcode_for_gh_60b944f6c215_258.jpg




https://blog.sciencenet.cn/blog-69686-1179643.html

上一篇:[转载]【信息技术】【2014.12】复音:定义、模型与检测
下一篇:[转载]【图片新闻】美国海军可能会独立发展下一代战机
收藏 IP: 60.169.68.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-25 21:19

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部