From 3c16dba22756dd672ac42438377a8195566f5b21 Mon Sep 17 00:00:00 2001 From: kdomino Date: Wed, 3 Oct 2018 15:33:41 +0200 Subject: [PATCH] all tests on generated data for julia 1.0 --- test/jkfs_select.jl | 114 +++++++++++---------- test/jkfsdata_select/jkfs_data_analysis.jl | 4 +- 2 files changed, 63 insertions(+), 55 deletions(-) mode change 100644 => 100755 test/jkfs_select.jl diff --git a/test/jkfs_select.jl b/test/jkfs_select.jl old mode 100644 new mode 100755 index 57d3acd..2ba6b39 --- a/test/jkfs_select.jl +++ b/test/jkfs_select.jl @@ -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) diff --git a/test/jkfsdata_select/jkfs_data_analysis.jl b/test/jkfsdata_select/jkfs_data_analysis.jl index 4d87c85..a281f1a 100755 --- a/test/jkfsdata_select/jkfs_data_analysis.jl +++ b/test/jkfsdata_select/jkfs_data_analysis.jl @@ -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)