This function will take a pipeline parameter and create configuration files with ranges of values. These configuration files will be the input for the two previous sets of scripts.


In [1]:
import yaml
import datetime

In [2]:
def create_config(original_file, module, parameter_to_change, values, exp):
    f_folders =[]
    with open(original_file, 'r') as ymlfile:
        l2v_cfg = yaml.load(ymlfile)

    print("module: ", module)    
    print("parameter_to_change: ", parameter_to_change)
    print("current value: ", l2v_cfg[module][parameter_to_change])
    
    print("values to add: ", values)    
    
    old_l2v_cfg = l2v_cfg.copy()
    
    for value in values:
        l2v_cfg[module][parameter_to_change] = value
        
        today = datetime.datetime.now().strftime("%m%d%y")
        v = "ex" + str(exp) + "-" +l2v_cfg["LLR"]["options"][0] + l2v_cfg["LLR"]["useroritem"][0] + str(l2v_cfg["LLR"]["threshold"]).replace(".", "")
        l = "d" + str(l2v_cfg["EMBEDDINGS"]["dim"]) + "w" + str(l2v_cfg["EMBEDDINGS"]["numWalks"]) + "l" + str(l2v_cfg["EMBEDDINGS"]["walkLength"]) + "n" +str(l2v_cfg["EMBEDDINGS"]["window"]) + "d" + str(l2v_cfg["EMBEDDINGS"]["degree"]) + "p" + str(l2v_cfg["EMBEDDINGS"]["p"]) + "q" + str(l2v_cfg["EMBEDDINGS"]["q"])
        k = "-" + str(l2v_cfg["PREDICTIONS"]["neighbors"]) + "-"
        filename = v + l + k + today + "-params.yml"
        
        with open(filename, 'w') as outfile:
            yaml.dump(l2v_cfg, outfile, default_flow_style=False)
        
        l2v_cfg = old_l2v_cfg.copy()
        print("Created file: ", filename)
        f_folders.append(filename)
        exp = exp + 1
    return f_folders

In this example I will use "EMBEDDINGS" module and the "p" parameter to be assigned the range from 6 to 9


In [3]:
f_thr = create_config("CONFIGS/ex3-du03d100w10l80n10d30p1q1-1000-081417-params.yml", "LLR", "threshold", [0.4, 0.5, 0.6, 0.7, 0.8, 0.9], 3)


module:  LLR
parameter_to_change:  threshold
current value:  0.3
values to add:  [0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
Created file:  ex3-du04d100w10l80n10d30p1q1-1000-081417-params.yml
Created file:  ex4-du05d100w10l80n10d30p1q1-1000-081417-params.yml
Created file:  ex5-du06d100w10l80n10d30p1q1-1000-081417-params.yml
Created file:  ex6-du07d100w10l80n10d30p1q1-1000-081417-params.yml
Created file:  ex7-du08d100w10l80n10d30p1q1-1000-081417-params.yml
Created file:  ex8-du09d100w10l80n10d30p1q1-1000-081417-params.yml

In [ ]: