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

在这里插入图片描述

本代码与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)

  1. 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/

更多精彩文章请关注微信号:在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值