Skip to content

Commit

Permalink
all tests on generated data for julia 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kdomino committed Oct 3, 2018
1 parent e7aba6a commit 3c16dba
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 55 deletions.
114 changes: 61 additions & 53 deletions test/jkfs_select.jl
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,71 +11,79 @@ using Random
@everywhere import CumulantsFeatures: reduceband
@everywhere using DatagenCopulaBased
@everywhere using CumulantsFeatures

@everywhere cut_order(x) = (x->x[3]).(x)

ν = parse(Int64, ARGS[1])
println(ν)

function main(args)
s = ArgParseSettings("description")
@add_arg_table s begin
"--nu", "-u"
default = 5
help = "the number of degrees of freedom for the t-Student copula"
arg_type = Int
end
parsed_args = parse_args(s)
ν = parsed_args["nu"]

@everywhere t = 100_000
@everywhere n = 50
@everywhere malf_size = 10
data_dir = "jkfsdata_select"
test_number = 25
filename = "tstudent_$(ν)-t_size-$(n)_malfsize-$malf_size-t_$t.jld2"
println(ν)
@everywhere t = 100_000
@everywhere n = 50
@everywhere malf_size = 10
data_dir = "jkfsdata_select"
test_number = 25
filename = "tstudent_$(ν)-t_size-$(n)_malfsize-$malf_size-t_$t.jld2"

data = Dict{String, Any}("variables_no" => n,
"sample_number" => t,
"ν" => ν,
"test_number" => test_number,
"malf_size" => malf_size,
"data" => Dict{String, Dict{String,Any}}())
data = Dict{String, Any}("variables_no" => n,
"sample_number" => t,
"ν" => ν,
"test_number" => test_number,
"malf_size" => malf_size,
"data" => Dict{String, Dict{String,Any}}())


known_data_size = 0
if isfile("$data_dir/$filename")
data["data"] = load("$data_dir/$filename")["data"]
known_data_size += length(data["data"])
println("Already have $known_data_size samples \n Will generate $(test_number-known_data_size) more")
end
known_data_size = 0
if isfile("$data_dir/$filename")
data["data"] = load("$data_dir/$filename")["data"]
known_data_size += length(data["data"])
println("Already have $known_data_size samples \n Will generate $(test_number-known_data_size) more")
end

#true calculations
println("Calculation started")
for m=(known_data_size+1):test_number
@time begin
println(" > $m ()")
malf = randperm(n)[1:malf_size]
Σ = cormatgen_rand(n)
samples_orig = Array(rand(MvNormal(Σ), t)')
#true calculations
println("Calculation started")
for m=(known_data_size+1):test_number
@time begin
println(" > $m ()")
malf = randperm(n)[1:malf_size]
Σ = cormatgen_rand(n)
samples_orig = Array(rand(MvNormal(Σ), t)')

versions = [(x->x, "original"),
(x->gcop2tstudent(x, malf, ν), "malf")]
versions = [(x->x, "original"),
(x->gcop2tstudent(x, malf, ν), "malf")]

cur_dict = Dict{String, Any}("malf" => malf,
"cor_source" => Σ)
cur_dict = Dict{String, Any}("malf" => malf,
"cor_source" => Σ)

data_dict = @distributed (merge) for (sampler, label)=versions
println(label)
samples = Array(sampler(samples_orig))
Σ_malf = SymmetricTensor(cov(samples))
cum = cumulants(samples, 4)
bands2 = cut_order(cumfsel(Σ_malf))
bands3 = cut_order(cumfsel(cum[2], cum[3], "hosvd"))
bands4 = cut_order(cumfsel(cum[2], cum[4], "hosvd"))
bands4n = cut_order(cumfsel(cum[2], cum[4], "norm", n-1))
bands4n = vcat(bands4n, setdiff(collect(1:n), bands4n))
Dict("cor_$label" => Σ_malf,
"bands_MEV_$label" => bands2,
"bands_JSBS_$label" => bands3,
"bands_JKFS_$label" => bands4,
"bands_JKN_$label" => bands4n)
end
data_dict = @distributed (merge) for (sampler, label)=versions
println(label)
samples = Array(sampler(samples_orig))
Σ_malf = SymmetricTensor(cov(samples))
cum = cumulants(samples, 4)
bands2 = cut_order(cumfsel(Σ_malf))
bands3 = cut_order(cumfsel(cum[2], cum[3], "hosvd"))
bands4 = cut_order(cumfsel(cum[2], cum[4], "hosvd"))
bands4n = cut_order(cumfsel(cum[2], cum[4], "norm", n-1))
bands4n = vcat(bands4n, setdiff(collect(1:n), bands4n))
Dict("cor_$label" => Σ_malf,
"bands_MEV_$label" => bands2,
"bands_JSBS_$label" => bands3,
"bands_JKFS_$label" => bands4,
"bands_JKN_$label" => bands4n)
end

data["data"]["$m"] = merge(cur_dict, data_dict)
save("$data_dir/$filename", data)
data["data"]["$m"] = merge(cur_dict, data_dict)
save("$data_dir/$filename", data)
end
end
end

rmprocs(procs_id)
exit()
main(ARGS)
4 changes: 2 additions & 2 deletions test/jkfsdata_select/jkfs_data_analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ function plotdata(plot_data, data_parts_label, ν, malf_size, var_number, repeat
data_y = plot_data[data_label]
data_x = collect(0:(length(data_y)-1))
println(data_y)
d = replace(data_label, "bands_", "")
plot(data_x, data_y/repeating, p[i], label=replace(d, "_malf", ""), color = cols[i], linewidth = 0.8, markersize = 3.)
d = replace(data_label, "bands_"=>"")
plot(data_x, data_y/repeating, p[i], label=replace(d, "_malf"=>""), color = cols[i], linewidth = 0.8, markersize = 3.)
end
data_x = 0:malf_size
#data_y = map(i-> theoretical(var_number, malf_size, i), data_x)
Expand Down

0 comments on commit 3c16dba

Please sign in to comment.