From b4fb5c6de6d6a34827a697dc51e5cc875081df65 Mon Sep 17 00:00:00 2001 From: Shivam Gupta Date: Sun, 16 May 2021 02:01:01 -0500 Subject: [PATCH] Added all the tests --- constant_vs_k.py | 31 +++++++++++++++++++++++++++++++ constant_vs_m.py | 31 +++++++++++++++++++++++++++++++ gd.py | 24 ++++++++++++------------ lhiding_vs_k.py | 31 +++++++++++++++++++++++++++++++ lhiding_vs_m.py | 31 +++++++++++++++++++++++++++++++ que_vs_k.py | 31 +++++++++++++++++++++++++++++++ que_vs_m.py | 31 +++++++++++++++++++++++++++++++ tflip_vs_k.py | 31 +++++++++++++++++++++++++++++++ tflip_vs_m.py | 31 +++++++++++++++++++++++++++++++ 9 files changed, 260 insertions(+), 12 deletions(-) create mode 100644 constant_vs_k.py create mode 100644 constant_vs_m.py create mode 100644 lhiding_vs_k.py create mode 100644 lhiding_vs_m.py create mode 100644 que_vs_k.py create mode 100644 que_vs_m.py create mode 100644 tflip_vs_k.py create mode 100644 tflip_vs_m.py diff --git a/constant_vs_k.py b/constant_vs_k.py new file mode 100644 index 0000000..756df81 --- /dev/null +++ b/constant_vs_k.py @@ -0,0 +1,31 @@ +import robustlib as rl +import matplotlib.pyplot as plt +trials_rsm3 = 10 +figsize=(8,4) +fontname='serif' +fsize=20 +fpad=10 +d_rsm3, eps_rsm3, m_rsm3 = 300, 0.1, 5000 +nItrs_rsm3 = 200 + +k_bounds_rsm3 = (1, 100, 5) + +model_rsm3 = rl.DenseNoiseModel(-2) + +keys_rsm3 = [rl.Oracle, rl.RME_sp, rl.NP_sp, rl.ransacGaussianMean, rl.GDAlgs] +#keys_rsm3 = [rl.GDAlgs] +model_params_rsm3 = rl.Params(d=d_rsm3, m=m_rsm3, eps=eps_rsm3, nItrs=nItrs_rsm3) +ylims_rsm3 = (0, 1) +xs = [] + +inputfilename_rsm3 = 'data/constant-loss-vs-k-pkl' +outputfilename_rsm3 = 'figs/constant-loss-vs-k.pdf' +plot_m_loss_rsm3 = rl.load_data(model_rsm3, model_params_rsm3, rl.err, keys_rsm3) +plot_m_loss_rsm3.setdata_tofile(inputfilename_rsm3, 'k', k_bounds_rsm3, trials_rsm3, ylims_rsm3, explicit_xs=False, xs=xs) +title_rsm3 = 'd = {d}, m = {m}, eps = {eps}, Noise is constant +2 biased'.format(d=d_rsm3, m=m_rsm3, eps=eps_rsm3) +xlabel_rsm3 = 'k' +ylabel_rsm3 = 'L2 loss' +plot_m_loss_rsm3_plt = rl.plot_data(model_rsm3, model_params_rsm3, rl.err, keys_rsm3) +plot_m_loss_rsm3_plt.plotxy_fromfile(outputfilename_rsm3, inputfilename_rsm3, 'k', k_bounds_rsm3, (0, 1), title_rsm3, xlabel_rsm3, ylabel_rsm3, figsize=figsize, fsize=fsize, fpad=fpad, fontname=fontname, explicit_xs = False, xs = xs) +plt.savefig('constant-loss-vs-k') + diff --git a/constant_vs_m.py b/constant_vs_m.py new file mode 100644 index 0000000..e291a91 --- /dev/null +++ b/constant_vs_m.py @@ -0,0 +1,31 @@ +import robustlib as rl +import matplotlib.pyplot as plt +trials_rsm3 = 10 +figsize=(8,4) +fontname='serif' +fsize=20 +fpad=10 +d_rsm3, k_rsm3, eps_rsm3 = 300, 10, 0.1 +nItrs_rsm3 = 200 + +m_bounds_rsm3 = (5, 350, 25) + +model_rsm3 = rl.DenseNoiseModel(-2) + +keys_rsm3 = [rl.Oracle, rl.RME_sp, rl.NP_sp, rl.ransacGaussianMean, rl.GDAlgs] +#keys_rsm3 = [rl.GDAlgs] +model_params_rsm3 = rl.Params(d=d_rsm3, k=k_rsm3, eps=eps_rsm3, nItrs=nItrs_rsm3) +ylims_rsm3 = (0, 1) +xs = [] + +inputfilename_rsm3 = 'data/constant-loss-vs-m-pkl' +outputfilename_rsm3 = 'figs/constant-loss-vs-m.pdf' +plot_m_loss_rsm3 = rl.load_data(model_rsm3, model_params_rsm3, rl.err, keys_rsm3) +plot_m_loss_rsm3.setdata_tofile(inputfilename_rsm3, 'm', m_bounds_rsm3, trials_rsm3, ylims_rsm3, explicit_xs=False, xs=xs) +title_rsm3 = 'd = {d}, k = {k}, eps = {eps}, Noise is constant +2 biased'.format(d=d_rsm3, k=k_rsm3, eps=eps_rsm3) +xlabel_rsm3 = 'm' +ylabel_rsm3 = 'L2 loss' +plot_m_loss_rsm3_plt = rl.plot_data(model_rsm3, model_params_rsm3, rl.err, keys_rsm3) +plot_m_loss_rsm3_plt.plotxy_fromfile(outputfilename_rsm3, inputfilename_rsm3, 'm', m_bounds_rsm3, (0, 1), title_rsm3, xlabel_rsm3, ylabel_rsm3, figsize=figsize, fsize=fsize, fpad=fpad, fontname=fontname, explicit_xs = False, xs = xs) +plt.savefig('constant-loss-vs-m') + diff --git a/gd.py b/gd.py index 93adc9a..ca8796b 100644 --- a/gd.py +++ b/gd.py @@ -5,27 +5,27 @@ fontname='serif' fsize=20 fpad=10 -d_rsm3, k_rsm3, eps_rsm3 = 1000, 40, 0.1 +d_rsm3, eps_rsm3, m_rsm3 = 300, 0.1, 5000 nItrs_rsm3 = 200 -m_bounds_rsm3 = (2000, 3000, 500) +k_bounds_rsm3 = (1, 100, 5) -model_rsm3 = rl.BimodalModel() +model_rsm3 = rl.TailFlipModel() -keys_rsm3 = [rl.Oracle, rl.RME_sp_L, rl.RME_sp, rl.NP_sp, rl.RME, rl.GDAlgs] +keys_rsm3 = [rl.Oracle, rl.RME_sp, rl.NP_sp, rl.ransacGaussianMean, rl.GDAlgs] #keys_rsm3 = [rl.GDAlgs] -model_params_rsm3 = rl.Params(d=d_rsm3, k=k_rsm3, eps=eps_rsm3, nItrs=nItrs_rsm3) +model_params_rsm3 = rl.Params(d=d_rsm3, m=m_rsm3, eps=eps_rsm3, nItrs=nItrs_rsm3) ylims_rsm3 = (0, 1) xs = [] -inputfilename_rsm3 = 'data/lhiding-loss-vs-m-pkl' -outputfilename_rsm3 = 'figs/lhiding-loss-vs-m.pdf' +inputfilename_rsm3 = 'data/tflip-loss-vs-k-pkl' +outputfilename_rsm3 = 'figs/tflip-loss-vs-k.pdf' plot_m_loss_rsm3 = rl.load_data(model_rsm3, model_params_rsm3, rl.err, keys_rsm3) -plot_m_loss_rsm3.setdata_tofile(inputfilename_rsm3, 'm', m_bounds_rsm3, trials_rsm3, ylims_rsm3, explicit_xs=False, xs=xs) -title_rsm3 = 'd = {d}, k = {k}, eps = {eps}, Noise is linear hiding'.format(d=d_rsm3, k=k_rsm3, eps=eps_rsm3) -xlabel_rsm3 = 'm' +plot_m_loss_rsm3.setdata_tofile(inputfilename_rsm3, 'k', k_bounds_rsm3, trials_rsm3, ylims_rsm3, explicit_xs=False, xs=xs) +title_rsm3 = 'd = {d}, m = {m}, eps = {eps}, Noise is tail flipping'.format(d=d_rsm3, m=m_rsm3, eps=eps_rsm3) +xlabel_rsm3 = 'k' ylabel_rsm3 = 'L2 loss' plot_m_loss_rsm3_plt = rl.plot_data(model_rsm3, model_params_rsm3, rl.err, keys_rsm3) -plot_m_loss_rsm3_plt.plotxy_fromfile(outputfilename_rsm3, inputfilename_rsm3, 'm', m_bounds_rsm3, (0, 1), title_rsm3, xlabel_rsm3, ylabel_rsm3, figsize=figsize, fsize=fsize, fpad=fpad, fontname=fontname, explicit_xs = False, xs = xs) -plt.savefig('lhiding-loss-vs-m') +plot_m_loss_rsm3_plt.plotxy_fromfile(outputfilename_rsm3, inputfilename_rsm3, 'k', k_bounds_rsm3, (0, 1), title_rsm3, xlabel_rsm3, ylabel_rsm3, figsize=figsize, fsize=fsize, fpad=fpad, fontname=fontname, explicit_xs = False, xs = xs) +plt.savefig('tflip-loss-vs-k') diff --git a/lhiding_vs_k.py b/lhiding_vs_k.py new file mode 100644 index 0000000..4f8fadb --- /dev/null +++ b/lhiding_vs_k.py @@ -0,0 +1,31 @@ +import robustlib as rl +import matplotlib.pyplot as plt +trials_rsm3 = 10 +figsize=(8,4) +fontname='serif' +fsize=20 +fpad=10 +d_rsm3, eps_rsm3, m_rsm3 = 300, 0.1, 5000 +nItrs_rsm3 = 200 + +k_bounds_rsm3 = (1, 200, 20) + +model_rsm3 = rl.BimodalModel() + +keys_rsm3 = [rl.Oracle, rl.RME_sp, rl.NP_sp, rl.ransacGaussianMean, rl.GDAlgs] +#keys_rsm3 = [rl.GDAlgs] +model_params_rsm3 = rl.Params(d=d_rsm3, m=m_rsm3, eps=eps_rsm3, nItrs=nItrs_rsm3) +ylims_rsm3 = (0, 1) +xs = [] + +inputfilename_rsm3 = 'data/lhiding-loss-vs-k-pkl' +outputfilename_rsm3 = 'figs/lhiding-loss-vs-k.pdf' +plot_m_loss_rsm3 = rl.load_data(model_rsm3, model_params_rsm3, rl.err, keys_rsm3) +plot_m_loss_rsm3.setdata_tofile(inputfilename_rsm3, 'k', k_bounds_rsm3, trials_rsm3, ylims_rsm3, explicit_xs=False, xs=xs) +title_rsm3 = 'd = {d}, m = {m}, eps = {eps}, Noise is linear hiding'.format(d=d_rsm3, m=m_rsm3, eps=eps_rsm3) +xlabel_rsm3 = 'k' +ylabel_rsm3 = 'L2 loss' +plot_m_loss_rsm3_plt = rl.plot_data(model_rsm3, model_params_rsm3, rl.err, keys_rsm3) +plot_m_loss_rsm3_plt.plotxy_fromfile(outputfilename_rsm3, inputfilename_rsm3, 'k', k_bounds_rsm3, (0, 1), title_rsm3, xlabel_rsm3, ylabel_rsm3, figsize=figsize, fsize=fsize, fpad=fpad, fontname=fontname, explicit_xs = False, xs = xs) +plt.savefig('lhiding-loss-vs-k') + diff --git a/lhiding_vs_m.py b/lhiding_vs_m.py new file mode 100644 index 0000000..9ae2080 --- /dev/null +++ b/lhiding_vs_m.py @@ -0,0 +1,31 @@ +import robustlib as rl +import matplotlib.pyplot as plt +trials_rsm3 = 10 +figsize=(8,4) +fontname='serif' +fsize=20 +fpad=10 +d_rsm3, k_rsm3, eps_rsm3 = 1000, 40, 0.1 +nItrs_rsm3 = 200 + +m_bounds_rsm3 = (1000, 13000, 1000) + +model_rsm3 = rl.BimodalModel() + +keys_rsm3 = [rl.Oracle, rl.RME_sp, rl.NP_sp, rl.ransacGaussianMean, rl.GDAlgs] +#keys_rsm3 = [rl.GDAlgs] +model_params_rsm3 = rl.Params(d=d_rsm3, k=k_rsm3, eps=eps_rsm3, nItrs=nItrs_rsm3) +ylims_rsm3 = (0, 1) +xs = [] + +inputfilename_rsm3 = 'data/lhiding-loss-vs-m-pkl' +outputfilename_rsm3 = 'figs/lhiding-loss-vs-m.pdf' +plot_m_loss_rsm3 = rl.load_data(model_rsm3, model_params_rsm3, rl.err, keys_rsm3) +plot_m_loss_rsm3.setdata_tofile(inputfilename_rsm3, 'm', m_bounds_rsm3, trials_rsm3, ylims_rsm3, explicit_xs=False, xs=xs) +title_rsm3 = 'd = {d}, k = {k}, eps = {eps}, Noise is linear hiding'.format(d=d_rsm3, k=k_rsm3, eps=eps_rsm3) +xlabel_rsm3 = 'm' +ylabel_rsm3 = 'L2 loss' +plot_m_loss_rsm3_plt = rl.plot_data(model_rsm3, model_params_rsm3, rl.err, keys_rsm3) +plot_m_loss_rsm3_plt.plotxy_fromfile(outputfilename_rsm3, inputfilename_rsm3, 'm', m_bounds_rsm3, (0, 1), title_rsm3, xlabel_rsm3, ylabel_rsm3, figsize=figsize, fsize=fsize, fpad=fpad, fontname=fontname, explicit_xs = False, xs = xs) +plt.savefig('lhiding-loss-vs-m') + diff --git a/que_vs_k.py b/que_vs_k.py new file mode 100644 index 0000000..0ae0ca0 --- /dev/null +++ b/que_vs_k.py @@ -0,0 +1,31 @@ +import robustlib as rl +import matplotlib.pyplot as plt +trials_rsm3 = 10 +figsize=(8,4) +fontname='serif' +fsize=20 +fpad=10 +d_rsm3, eps_rsm3, m_rsm3 = 300, 0.1, 5000 +nItrs_rsm3 = 200 + +k_bounds_rsm3 = (1, 200, 20) + +model_rsm3 = rl.QUESyntheticModel() + +keys_rsm3 = [rl.Oracle, rl.RME_sp, rl.NP_sp, rl.ransacGaussianMean, rl.GDAlgs] +#keys_rsm3 = [rl.GDAlgs] +model_params_rsm3 = rl.Params(d=d_rsm3, m=m_rsm3, eps=eps_rsm3, nItrs=nItrs_rsm3) +ylims_rsm3 = (0, 1) +xs = [] + +inputfilename_rsm3 = 'data/que-loss-vs-k-pkl' +outputfilename_rsm3 = 'figs/que-loss-vs-k.pdf' +plot_m_loss_rsm3 = rl.load_data(model_rsm3, model_params_rsm3, rl.err, keys_rsm3) +plot_m_loss_rsm3.setdata_tofile(inputfilename_rsm3, 'k', k_bounds_rsm3, trials_rsm3, ylims_rsm3, explicit_xs=False, xs=xs) +title_rsm3 = 'd = {d}, m = {m}, eps = {eps}, Noise is in multiple directions'.format(d=d_rsm3, m=m_rsm3, eps=eps_rsm3) +xlabel_rsm3 = 'k' +ylabel_rsm3 = 'L2 loss' +plot_m_loss_rsm3_plt = rl.plot_data(model_rsm3, model_params_rsm3, rl.err, keys_rsm3) +plot_m_loss_rsm3_plt.plotxy_fromfile(outputfilename_rsm3, inputfilename_rsm3, 'k', k_bounds_rsm3, (0, 1), title_rsm3, xlabel_rsm3, ylabel_rsm3, figsize=figsize, fsize=fsize, fpad=fpad, fontname=fontname, explicit_xs = False, xs = xs) +plt.savefig('que-loss-vs-k') + diff --git a/que_vs_m.py b/que_vs_m.py new file mode 100644 index 0000000..8d2f6c8 --- /dev/null +++ b/que_vs_m.py @@ -0,0 +1,31 @@ +import robustlib as rl +import matplotlib.pyplot as plt +trials_rsm3 = 10 +figsize=(8,4) +fontname='serif' +fsize=20 +fpad=10 +d_rsm3, k_rsm3, eps_rsm3 = 1000, 40, 0.1 +nItrs_rsm3 = 200 + +m_bounds_rsm3 = (1000, 13000, 1000) + +model_rsm3 = rl.QUESyntheticModel() + +keys_rsm3 = [rl.Oracle, rl.RME_sp, rl.NP_sp, rl.ransacGaussianMean, rl.GDAlgs] +#keys_rsm3 = [rl.GDAlgs] +model_params_rsm3 = rl.Params(d=d_rsm3, k=k_rsm3, eps=eps_rsm3, nItrs=nItrs_rsm3) +ylims_rsm3 = (0, 1) +xs = [] + +inputfilename_rsm3 = 'data/que-loss-vs-m-pkl' +outputfilename_rsm3 = 'figs/que-loss-vs-m.pdf' +plot_m_loss_rsm3 = rl.load_data(model_rsm3, model_params_rsm3, rl.err, keys_rsm3) +plot_m_loss_rsm3.setdata_tofile(inputfilename_rsm3, 'm', m_bounds_rsm3, trials_rsm3, ylims_rsm3, explicit_xs=False, xs=xs) +title_rsm3 = 'd = {d}, k = {k}, eps = {eps}, Noise is in multiple directions'.format(d=d_rsm3, k=k_rsm3, eps=eps_rsm3) +xlabel_rsm3 = 'm' +ylabel_rsm3 = 'L2 loss' +plot_m_loss_rsm3_plt = rl.plot_data(model_rsm3, model_params_rsm3, rl.err, keys_rsm3) +plot_m_loss_rsm3_plt.plotxy_fromfile(outputfilename_rsm3, inputfilename_rsm3, 'm', m_bounds_rsm3, (0, 1), title_rsm3, xlabel_rsm3, ylabel_rsm3, figsize=figsize, fsize=fsize, fpad=fpad, fontname=fontname, explicit_xs = False, xs = xs) +plt.savefig('que-loss-vs-m') + diff --git a/tflip_vs_k.py b/tflip_vs_k.py new file mode 100644 index 0000000..ca8796b --- /dev/null +++ b/tflip_vs_k.py @@ -0,0 +1,31 @@ +import robustlib as rl +import matplotlib.pyplot as plt +trials_rsm3 = 10 +figsize=(8,4) +fontname='serif' +fsize=20 +fpad=10 +d_rsm3, eps_rsm3, m_rsm3 = 300, 0.1, 5000 +nItrs_rsm3 = 200 + +k_bounds_rsm3 = (1, 100, 5) + +model_rsm3 = rl.TailFlipModel() + +keys_rsm3 = [rl.Oracle, rl.RME_sp, rl.NP_sp, rl.ransacGaussianMean, rl.GDAlgs] +#keys_rsm3 = [rl.GDAlgs] +model_params_rsm3 = rl.Params(d=d_rsm3, m=m_rsm3, eps=eps_rsm3, nItrs=nItrs_rsm3) +ylims_rsm3 = (0, 1) +xs = [] + +inputfilename_rsm3 = 'data/tflip-loss-vs-k-pkl' +outputfilename_rsm3 = 'figs/tflip-loss-vs-k.pdf' +plot_m_loss_rsm3 = rl.load_data(model_rsm3, model_params_rsm3, rl.err, keys_rsm3) +plot_m_loss_rsm3.setdata_tofile(inputfilename_rsm3, 'k', k_bounds_rsm3, trials_rsm3, ylims_rsm3, explicit_xs=False, xs=xs) +title_rsm3 = 'd = {d}, m = {m}, eps = {eps}, Noise is tail flipping'.format(d=d_rsm3, m=m_rsm3, eps=eps_rsm3) +xlabel_rsm3 = 'k' +ylabel_rsm3 = 'L2 loss' +plot_m_loss_rsm3_plt = rl.plot_data(model_rsm3, model_params_rsm3, rl.err, keys_rsm3) +plot_m_loss_rsm3_plt.plotxy_fromfile(outputfilename_rsm3, inputfilename_rsm3, 'k', k_bounds_rsm3, (0, 1), title_rsm3, xlabel_rsm3, ylabel_rsm3, figsize=figsize, fsize=fsize, fpad=fpad, fontname=fontname, explicit_xs = False, xs = xs) +plt.savefig('tflip-loss-vs-k') + diff --git a/tflip_vs_m.py b/tflip_vs_m.py new file mode 100644 index 0000000..edc1d11 --- /dev/null +++ b/tflip_vs_m.py @@ -0,0 +1,31 @@ +import robustlib as rl +import matplotlib.pyplot as plt +trials_rsm3 = 10 +figsize=(8,4) +fontname='serif' +fsize=20 +fpad=10 +d_rsm3, k_rsm3, eps_rsm3 = 10, 1, 0.1 +nItrs_rsm3 = 200 + +m_bounds_rsm3 = (2, 1000, 10) + +model_rsm3 = rl.TailFlipModel() + +keys_rsm3 = [rl.Oracle, rl.RME_sp, rl.NP_sp, rl.ransacGaussianMean, rl.GDAlgs] +#keys_rsm3 = [rl.GDAlgs] +model_params_rsm3 = rl.Params(d=d_rsm3, k=k_rsm3, eps=eps_rsm3, nItrs=nItrs_rsm3) +ylims_rsm3 = (0, 1) +xs = [] + +inputfilename_rsm3 = 'data/tailflip-loss-vs-m-pkl' +outputfilename_rsm3 = 'figs/tailflip-loss-vs-m.pdf' +plot_m_loss_rsm3 = rl.load_data(model_rsm3, model_params_rsm3, rl.err, keys_rsm3) +plot_m_loss_rsm3.setdata_tofile(inputfilename_rsm3, 'm', m_bounds_rsm3, trials_rsm3, ylims_rsm3, explicit_xs=False, xs=xs) +title_rsm3 = 'd = {d}, k = {k}, eps = {eps}, Noise is tail flipping'.format(d=d_rsm3, k=k_rsm3, eps=eps_rsm3) +xlabel_rsm3 = 'm' +ylabel_rsm3 = 'L2 loss' +plot_m_loss_rsm3_plt = rl.plot_data(model_rsm3, model_params_rsm3, rl.err, keys_rsm3) +plot_m_loss_rsm3_plt.plotxy_fromfile(outputfilename_rsm3, inputfilename_rsm3, 'm', m_bounds_rsm3, (0, 1), title_rsm3, xlabel_rsm3, ylabel_rsm3, figsize=figsize, fsize=fsize, fpad=fpad, fontname=fontname, explicit_xs = False, xs = xs) +plt.savefig('tailfip-loss-vs-m') +