コード例 #1
0
 def get_assay_control(self):
     control_model = modelbank.control_to_yield_model('ridge', 1)
     if self.compare_test:
         return control_model.model_stats[
             'test_avg_loss'], control_model.model_stats['test_std_loss']
     else:
         return control_model.model_stats[
             'cv_avg_loss'], control_model.model_stats['cv_std_loss']
コード例 #2
0
 def get_assay_control(self):
     ## Initally a control_to_yield object is created from the submodels_module.py program,
     ## with the model architecture of ridge and sample fraction as 1 and saved as control_model
     control_model=modelbank.control_to_yield_model('ridge',1)
     if self.compare_test:
         ## If the compare_test class variable is true then a tuple containing the average loss and standard deviation loss of the testing data
         ## is returned
         return control_model.model_stats['test_avg_loss'],control_model.model_stats['test_std_loss']
     else:
         ## Else the average loss and standard deviation loss of the cross validation is returned in the tuple
         return control_model.model_stats['cv_avg_loss'],control_model.model_stats['cv_std_loss']
コード例 #3
0
def main():
    '''
    compare test performances when reducing training sample size. This version is for first paper, predicting yield from assays and one-hot encoded sequence. 
    '''

    a = int(sys.argv[1])
    if a < 4:
        b = 0
    elif a < 8:
        a = a - 4
        b = 1
    elif a < 12:
        a = a - 8
        b = 2
    elif a == 12:
        b = 3
        a = a - 12
    else:
        print('incorrect toggle number')

    arch_list = ['ridge', 'svm', 'forest', 'fnn']

    # size_list=[0.055,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]
    size_list = [0.7, 0.8, 0.9, 1]

    for size in size_list:
        if b == 0:
            mdl = modelbank.seqandassay_to_yield_model([1, 8, 10],
                                                       arch_list[a], size)
        elif b == 1:  #1,5,9,12
            mdl = modelbank.assay_to_yield_model([1, 8, 10], arch_list[a],
                                                 size)
        elif b == 2:
            mdl = modelbank.seq_to_yield_model(arch_list[a], size)
        elif b == 3:
            mdl = modelbank.control_to_yield_model(arch_list[a], size)

        for seed in range(9):  #no seed is seed=42
            mdl.change_sample_seed(seed)
            mdl.cross_validate_model()
            mdl.limit_test_set([1, 8, 10])
            mdl.test_model()
コード例 #4
0
                                                               arch, 1)
        if mdl.model_stats['cv_avg_loss'] < cv_loss:
            cv_loss = mdl.model_stats['cv_avg_loss']
            test_loss = mdl.model_stats['test_avg_loss']
            test_std = mdl.model_stats['test_std_loss']
    loss_per_model.append(test_loss)
    std_per_model.append(test_std)

seq_model = modelbank.seq_to_yield_model('forest', 1)
seq_loss = seq_model.model_stats['test_avg_loss']
seq_std = seq_model.model_stats['test_std_loss']
x = [-0.3, 0.8]
seq_plus = [seq_loss + seq_std] * 2
seq_min = [seq_loss - seq_std] * 2

control_model = modelbank.control_to_yield_model('ridge', 1)
control_loss = control_model.model_stats['test_avg_loss']
control_model.limit_test_set([1, 8, 10])
exploded_df, _, _ = load_format_data.explode_yield(control_model.testing_df)
exp_var = np.average(np.square(np.array(exploded_df['y_std'])))

fig, ax = plt.subplots(1, 1, figsize=[2, 2], dpi=300)

xloc = [0, 0.5]
ax.axhline(seq_loss,
           -0.5,
           4.5,
           color='green',
           linestyle='--',
           label='Sequence Model')
ax.axhline(control_loss,
コード例 #5
0
def main():
    '''
    compare test performances when reducing training sample size. This version is for first paper, predicting yield from assays and one-hot encoded sequence. 
    '''
    ## A command line input is required when running this program. The integer input
    ## should be between 0-12.
    a=int(sys.argv[1])
    if a<4:
        b=0
        ## if the input is less than 4 then b value is set to 0
    elif a<8:
        a=a-4
        b=1
        ## if a is between 4-8 then the b value is set to 1 and a is reduced by 4
    elif a<12:
        a=a-8
        b=2
        ## if a is between 8-12 then the b value is set to 2 and a is reduced by 8
    elif a==12:
        b=3
        a=a-12
        ## if a is equal to 12 then the b value is set to 3 and a is set to 0. 
    else:
        print('incorrect toggle number')
        ## If the inout is out of bounds then an error message is printed. 
    arch_list=['ridge','svm','forest','fnn']
    ## A string list is created containing the names of the different regression models and stored as arch_list
    # size_list=[0.055,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]
    size_list=[0.7,0.8,0.9,1]
    ## A float list is created containing varying amounts of sample fractions and stored as size_list
    for size in size_list:
        ## each element in the size_list array, we check the value of the b value created in the above if-else
        ## statements and this dictates the kind of submodel_module.py object created
        ## if b = 0, then a seqandassay_to_yield_model object is created with an assay list of [1,8,10]
        ## a regression model dictated by the 'a' index of the arch_list and the size determined by the iteration of size_list
        if b==0:
            mdl=modelbank.seqandassay_to_yield_model([1,8,10],arch_list[a],size)
        ## if b = 1, then a assay_to_yield_model object is created with an assay list of [1,8,10]
        ## a regression model dictated by the 'a' index of the arch_list and the size determined by the iteration of size_list
        elif b==1: #1,5,9,12
            mdl=modelbank.assay_to_yield_model([1,8,10],arch_list[a],size)
        ## if b = 2, then a seq_to_yield_model object is created with a regression model dictated by
        ## the 'a' index of the arch_list and the size determined by the iteration of size_list
        elif b==2: 
            mdl=modelbank.seq_to_yield_model(arch_list[a],size)
        ## if b = 3, then a control_to_yield_model object is created with a regression model dictated by
        ## the 'a' index of the arch_list and the size determined by the iteration of size_list
        elif b==3:
            mdl=modelbank.control_to_yield_model(arch_list[a],size)
            
        for seed in range(9): #no seed is seed=42
            ## For each element in the int range [0,9). The sample_seed class int to the element
            ## Then the trial data, model data and plots are updated to reflect the new sample_seed size
            mdl.change_sample_seed(seed)
            ## Then the best hyperparameters for the given model and seed size is determined using the cross_validate_model()
            ## function from the model object 
            mdl.cross_validate_model()
            ## Following this limit_test_set() function defined in the x_to_yield_model parent class to update the
            ## testing_df class dataframe to reflect the 1,8,10 assays.
            mdl.limit_test_set([1,8,10])
            ## Finally using the test_model() function from the model parent class  is run to
            ## train the model using the hyperparameters defined above and the training data to predict the testing dataset.
            mdl.test_model()