Ejemplo n.º 1
0
    def train(self):
    
        # Unwrap the matrices (put the most recent data on the bottom)
        pivot = self.row_count % self.matrix_length
        data = self.X[pivot:, :self.num_features]
        data = np.concatenate((data, self.X[:pivot, :self.num_features]), axis=0)
        y = self.X[pivot:, self.num_features]
        y = np.concatenate((y, self.X[:pivot, self.num_features]), axis=0)

        if (self.init_training or runnable(data) > 0.5):
            #self.w_opt, self.a_opt, self.b_opt, self.S_N = normalTrain(data, y)
            self.w_opt, self.a_opt, self.b_opt, self.S_N = train(data, y)
            self.init_training = True
            
        # Log current training windows as pickle files
        if self.using_backup:
            with open(self.X_backup_file, 'wb') as outfile:
                pickle.dump(self.X, outfile)
Ejemplo n.º 2
0
    def train(self):
    
        # Unwrap the matrices (put the most recent data on the bottom)
        pivot = self.row_count % self.matrix_length
        data = self.X[pivot:, :self.num_features]
        data = np.concatenate((data, self.X[:pivot, :self.num_features]), axis=0)
        y = self.X[pivot:, self.num_features]
        y = np.concatenate((y, self.X[:pivot, self.num_features]), axis=0)

        if (self.init_training or runnable(data) > 0.5):
            #self.w_opt, self.a_opt, self.b_opt, self.S_N = normalTrain(data, y)
            self.w_opt, self.a_opt, self.b_opt, self.S_N = train(data, y)
            self.init_training = True
            
        # Log current training windows as pickle files
        if self.using_backup:
            with open(self.X_backup_file, 'wb') as outfile:
                pickle.dump(self.X, outfile)
Ejemplo n.º 3
0
        '''
    print "X_og: \n",X_og
    print "X: \n",X[cur_row]
    
    # Train the model
    if (row_count % forecasting_interval == 0 and
        (row_count >= matrix_length or init_training)):

        # Unwrap the matrices (put the most recent data on the bottom)
        data = X[cur_row:, :num_sensors]
        data = np.concatenate((data, X[:cur_row, :num_sensors]), axis=0)
        y = X[cur_row:, num_sensors]
        y = np.concatenate((y, X[:cur_row, num_sensors]), axis=0)

        # BLR train:
        w_opt, a_opt, b_opt, S_N = train(data, y)

        init_training = True

        # Log current training windows as pickle files
        with open(XLOG_FILENAME, 'w') as logfile:
            pickle.dump(X, logfile)
        with open(Xog_LOG_FILENAME, 'w') as logfile:
            pickle.dump(X_og, logfile)
        
    # Make a prediction
    if init_training:

        # Prediction is dot product of data and weights
        x_n = X[(row_count) % matrix_length][:num_sensors]
        print "w_opt,\n", w_opt
Ejemplo n.º 4
0
        '''
    print "X_og: \n", X_og
    print "X: \n", X[cur_row]

    # Train the model
    if (row_count % forecasting_interval == 0
            and (row_count >= matrix_length or init_training)):

        # Unwrap the matrices (put the most recent data on the bottom)
        data = X[cur_row:, :num_sensors]
        data = np.concatenate((data, X[:cur_row, :num_sensors]), axis=0)
        y = X[cur_row:, num_sensors]
        y = np.concatenate((y, X[:cur_row, num_sensors]), axis=0)

        # BLR train:
        w_opt, a_opt, b_opt, S_N = train(data, y)

        init_training = True

        # Log current training windows as pickle files
        with open(XLOG_FILENAME, 'w') as logfile:
            pickle.dump(X, logfile)
        with open(Xog_LOG_FILENAME, 'w') as logfile:
            pickle.dump(X_og, logfile)

    # Make a prediction
    if init_training:

        # Prediction is dot product of data and weights
        x_n = X[(row_count) % matrix_length][:num_sensors]
        print "w_opt,\n", w_opt