Types and constants

    Functions and macros


    partition(data, logfitness=:cash, logprior=:p0, progress=false, ...)

    Return an array of optimal change points for a set of one-dimensional data (observations or an histogram of them). This is the implementation of the bayesian blocks algorithm, as outlined in [1].


    • data: numeric array or a StatsBase.Histogram
    • logfitness: log of the block fitness function to be used, choose between [:cash]
    • logprior: log of the prior distribution on the number of blocks to be used, choose between [:gamma, :p0]
    • gamma, p0...: set the parameter value for the specified prior distribution
    • progress: display a progress bar for long computations


    using Distributions, StatsBase, Plots, LinearAlgebra
    data = vcat(rand(Normal(0),1000),rand(Cauchy(5),1000))
    data = data[(data .> -5) .& (data .< 10)]
    h = fit(Histogram, data, -5:0.1:10)
    # choose to use all data or an histogram of it!
    hb = fit(Histogram, data, BayesianBlocks.partition(data))
    hb = fit(Histogram, data, BayesianBlocks.partition(h))
    plot(data, normalized=true, st=:stephist, nbins=1000)
    plot!(normalize(hb), st=:step, w = 3)

    Performance tips

    You can convert your data container to a less precise representation to improve the performance a bit, e.g.

    x::Array{Float32} = [1.1, π, (√5-1)/2]
    • 1Scargle, J et al. (2012) [https://doi.org/10.1088/0004-637X/764/2/167]