def update_model(self,sequences, bootstrap=True):
            X=[]
            Y=[]
            for sequence in sequences:
                if sequence not in self.one_hot_sequences:# or self.batch_update:
                    x=translate_string_to_one_hot(sequence,self.alphabet)#.flatten()
                    y=self.measured_sequences[sequence]
                    self.one_hot_sequences[sequence]=(x,y)
                    X.append(x)
                    Y.append(y)
                else:
                    x,y=self.one_hot_sequences[sequence]
                    X.append(x)
                    Y.append(y)
            X=np.array(X)
            Y=np.array(Y)

            for i,model_dict in enumerate(self.list_of_models_dict):
                try:

                    y_pred=model_dict['model'].predict(X)
              #  self.noise_alpha=explained_variance_score(Y,y_pred)
                    self.model_performances[i]=r2_score(Y,y_pred)

                except:
                    pass
                indices=[]
                for k in range(int(len(X)/2)):
                    indices.append(random.randint(0,len(X)-1))
                model_dict['model'].fit(np.take(X,indices,axis=0),np.take(Y,indices,axis=0),epochs=model_dict['epochs'],validation_split=0,batch_size=model_dict['batch_size'],verbose=0)
            best_model_index=np.argmax(self.model_performances)
            self.best_model=self.list_of_models_dict[best_model_index]['model']
    def update_model(self,sequences):
        X=[]
        Y=[]
        for sequence in sequences:
            if sequence not in self.one_hot_sequences:# or self.batch_update:
                x=translate_string_to_one_hot(sequence,self.alphabet)#.flatten()
                y=self.measured_sequences[sequence]
                self.one_hot_sequences[sequence]=(x,y)
                X.append(x)
                Y.append(y)
            else:
                x,y=self.one_hot_sequences[sequence]
                X.append(x)
                Y.append(y)
        X=np.array(X)
        Y=np.array(Y)

        try:
            y_pred=self.skmodel.predict(X)
          #  self.noise_alpha=explained_variance_score(Y,y_pred)
            self.noise_alpha=r2_score(Y,y_pred)

        except:
            pass

        self.skmodel.fit(X,Y,epochs=self.epochs,validation_split=self.validation_split,batch_size=self.batch_size,verbose=0)
        if not self.batch_update:
            self.retrain_model()
    def update_model(self,sequences):
        X=[]
        Y=[]
        for sequence in sequences:
            if sequence not in self.one_hot_sequences:# or self.batch_update:
                #print (sequence)
                x=translate_string_to_one_hot(sequence,self.alphabet).flatten()
                y=self.measured_sequences[sequence]
                self.one_hot_sequences[sequence]=(x,y)
                X.append(x)
                Y.append(y)
            else:
                x,y=self.one_hot_sequences[sequence]
                X.append(x)
                Y.append(y)
        X=np.array(X)
        Y=np.array(Y)

        self.retrain_model()
        try:
            y_pred=self.skmodel.predict(X)
            self.noise_alpha=explained_variance_score(Y,y_pred)
            self.noise_alpha=r2_score(Y,y_pred)
        except:
            pass

        self.skmodel.fit(X,Y)
 def bootstrap(self,wt,alphabet):
     sequences=[wt]
     self.wt=wt
     self.alphabet=alphabet
     for i in range(len(wt)):
         tmp=list(wt)
         for j in range(len(alphabet)):
             tmp[i]=alphabet[j]
             sequences.append("".join(tmp))
     self.measure_true_landscape(sequences)
     self.one_hot_sequences={sequence:(translate_string_to_one_hot(sequence,self.alphabet),self.measured_sequences[sequence]) for sequence in sequences} #removed flatten for nn
     self.update_model(sequences)
        def get_uncertainty(self,sequence):
            x=np.array([translate_string_to_one_hot(sequence,self.alphabet)])#.flatten()]

            x_predicts=[m["model"].predict(x)[0][0] for m in self.list_of_models_dict]

            return np.mean(x_predicts), np.std(x_predicts), x_predicts
        def _fitness_function(self,sequence):
            x=np.array([translate_string_to_one_hot(sequence,self.alphabet)])#.flatten()]

            return max(min(200, self.best_model.predict(x)[0][0]),-200)