Skip to content

Commit

Permalink
gendata and testondata correction in code and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kdomino committed Jun 23, 2017
1 parent f67d7c8 commit 7cf09d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 61 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,10 @@ All result files are saved in /res directory. To plot a graph run /res/plotcompt

For the computional example on data use the following.

The script `gandata.jl` generates `t = 75000000` realisations of `n = 4` dimensional data form the `t`-multivariate distribution with `\nu = 14` degrees of freedom.
The script `gandata.jl` generates `t = 100000000` realisations of `n = 4` dimensional data form the `t`-multivariate distribution with `\nu = 14` degrees of freedom, and theoretical
super-diagonal elements of those cumulants. Rasults are saved in `data/datafortests.jld`

The script `testondata.jl` computes cumulant tensors of order `m = 1 - 6` for those data and displays some of cumulants valuse on charts. For superdiagonal values the comparison with theoretical cumulants values of the distrubution is supplied.
The script `testondata.jl` computes cumulant tensors of order `m = 1 - 6` for `data/datafortests.jld`, results are saved in `data/cumulants.jld`.

# Citing this work

Expand Down
67 changes: 8 additions & 59 deletions test/testondata.jl
Original file line number Diff line number Diff line change
@@ -1,69 +1,18 @@
#!/usr/bin/env julia

using NPZ
using JLD
using Cumulants
addprocs()
@everywhere using Cumulants
using PyCall
@pyimport matplotlib as mpl
mpl.use("Agg")
using PyPlot
mpl.rc("text", usetex=true)
mpl.rc("font", family="serif", size = 12)


"""
pltdiag(l::Vector{String}, codd::Vector{Float64}, cev::Vector{Float64})
Plots a chart of superdiagonal elements of cumulants of odd and even order. Those
elements are in vectors codd and cev and are named by l. Theoretical values are
computed as those of t-student standard distribution with 14 degrees of freedom.
"""
function pltdiag(l::Vector{String}, codd::Vector{Float64}, cev::Vector{Float64})
n = length(codd)
k = parse(Int, l[2][2])
fig, ax = subplots(figsize = (4.6, 4.6))
ax[:plot](cev, "o", color = "blue", label = l[2], markersize=4)
ax[:plot]([fill(tcum(14, k), n)...], "--", color = "blue", label = "theoretical "*l[2])
ax[:plot](codd, "s", color = "red", label = l[1], markersize=4)
ax[:plot](zeros(n), "--", color = "red", label = "theoretical "*l[1])
ax[:set_ylabel]("superdiagonal element")
ax[:set_xlabel]("superdiagonal element number")
ax[:legend](fontsize = 12, loc = 5)
fig[:savefig]("res/diagcumel"*l[2][2:end]*".eps")
end

"""
pltall(l::Vector{String}, v::Vector{Float64}, v1::Vector{Float64})
Plots a chart of all elements of cumulants in a vectorised form v and v1 named by l.
"""

function pltall(l::Vector{String}, v::Vector{Float64}, v1::Vector{Float64})
fig, ax = subplots(figsize = (4.6, 4.6))
ax[:plot](v1, "o", color = "blue", label = l[2], markersize=3)
ax[:plot](v, "s", color = "red", label = l[1], markersize=3)
ax[:set_ylabel]("cumulant's element")
ax[:set_xlabel]("element's number of vectorised cumulat")
ax[:legend](fontsize = 12, loc = 4)
fig[:savefig]("res/allcumels"*l[2][2:end]*".eps")
end

"""
hypdiag{T <: AbstractFloat, N}(a::Array{T, N})
Returns a vector of hyperdiagonal elements of array a
"""
hypdiag{T <: AbstractFloat, N}(a::Array{T, N}) = [a[fill(i,N)...] for i in 1:size(a,1)]

function main()
x = npzread("testdata.npz")
c = cumulants(x, 6)
ct = [convert(Array, c[i]) for i in 1:length(c)]
pltdiag(["c3", "c4"], hypdiag(ct[3]), hypdiag(ct[4]))
pltdiag(["c5", "c6"], hypdiag(ct[5]), hypdiag(ct[6]))
pltall(["c3", "c4"], vec(ct[3]), vec(ct[4]))
pltall(["c5", "c6"], vec(ct[5]), vec(ct[6]))
d = try load("data/datafortests.jld")
catch
println("please run gendata.jl")
return ()
end
c = cumulants(d["data"], 6)
save("data/cumulants.jld", Dict("cumulant" => c))
end

main()

0 comments on commit 7cf09d9

Please sign in to comment.