code: Ready to experiment with lmdk_sel
This commit is contained in:
		@ -1,5 +1,7 @@
 | 
			
		||||
#!/usr/bin/env python3
 | 
			
		||||
 | 
			
		||||
import sys
 | 
			
		||||
sys.path.insert(1, '../lib')
 | 
			
		||||
import argparse
 | 
			
		||||
import lmdk_lib
 | 
			
		||||
import lmdk_sel
 | 
			
		||||
@ -36,7 +38,7 @@ def main(args):
 | 
			
		||||
    plt.xlim(x_i.min() - x_margin, x_i.max() + x_margin)
 | 
			
		||||
    # The y axis
 | 
			
		||||
    plt.ylabel('Mean absolute error')  # Set y axis label.
 | 
			
		||||
    plt.ylim(0, len(seq)/3)
 | 
			
		||||
    # plt.ylim(0, len(seq)/3)
 | 
			
		||||
    # Bar offset
 | 
			
		||||
    x_offset = -(bar_width/2)*(len(epsilon) - 1)
 | 
			
		||||
    for e_i, e in enumerate(epsilon):
 | 
			
		||||
@ -45,9 +47,26 @@ def main(args):
 | 
			
		||||
        for r in range(args.reps):
 | 
			
		||||
          lmdks = lmdk_lib.get_lmdks(seq, n, d)
 | 
			
		||||
          hist, h = lmdk_lib.get_hist(seq, lmdks)
 | 
			
		||||
          opts = lmdk_sel.get_opts_from_top_h(seq, lmdks)
 | 
			
		||||
          delta = 1.0
 | 
			
		||||
          res, _ = exp_mech.exponential(hist, opts, exp_mech.score, delta, e)
 | 
			
		||||
          res = np.zeros([len(hist)])
 | 
			
		||||
          # Split sequence in parts of size h 
 | 
			
		||||
          pt_idx = []
 | 
			
		||||
          for idx in range(h, len(seq), h):
 | 
			
		||||
            pt_idx.append(idx)
 | 
			
		||||
          seq_pt = np.split(seq, pt_idx)
 | 
			
		||||
          for pt_i, pt in enumerate(seq_pt):
 | 
			
		||||
            # Find this part's landmarks
 | 
			
		||||
            lmdks_pt = np.intersect1d(pt, lmdks)
 | 
			
		||||
            # Find possible options for this part
 | 
			
		||||
            opts = lmdk_sel.get_opts_from_top_h(pt, lmdks_pt)
 | 
			
		||||
            # Turn part to histogram
 | 
			
		||||
            hist_pt, _ = lmdk_lib.get_hist(pt, lmdks_pt)
 | 
			
		||||
            # Get an option for this part
 | 
			
		||||
            res_pt = np.array([])
 | 
			
		||||
            if len(opts) > 0:
 | 
			
		||||
              res_pt, _ = exp_mech.exponential(hist_pt, opts, exp_mech.score, 1.0, e)
 | 
			
		||||
            # Merge options of all parts
 | 
			
		||||
            res[pt_i] = np.sum(res_pt)
 | 
			
		||||
          # Calculate MAE
 | 
			
		||||
          mae[n_i] += lmdk_lib.get_norm(hist, res)/args.reps
 | 
			
		||||
      # Plot bar for current epsilon
 | 
			
		||||
      plt.bar(
 | 
			
		||||
@ -59,7 +78,7 @@ def main(args):
 | 
			
		||||
      )
 | 
			
		||||
      # Change offset for next bar
 | 
			
		||||
      x_offset += bar_width
 | 
			
		||||
    path = str('/home/manos/Git/the-thing/code/expt_lmdk_sel/' + title)
 | 
			
		||||
    path = str('../../rslt/lmdk_sel/' + title)
 | 
			
		||||
    # Plot legend
 | 
			
		||||
    lmdk_lib.plot_legend()
 | 
			
		||||
    # Show plot
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user