def __init__(self,
                 concat_train_sales,
                 feature_range=(0, 1),
                 startDay=350,
                 config_path=''):
        """
        Load parameters for scaling features in input data.

        Args:
          concat_train_sales (dataframe): input daily data of sales, presence of events and SNAP program
          feature_range ((int, int)): the scaling range
          startDay (int): start day
          config_path (str): file path for config.yaml

        Attributes:
          concat_train_sales (dataframe): input daily data of sales, presence of events and SNAP program
          feature_range ((int, int)): the scaling range
          X_train (arr): training inputs
          y_train (arr): test inputs
          startDay (int): start day
          config (dict): parameter configurations from config.yaml
          timesteps (int): number of timesteps
        """
        self.concat_train_sales = concat_train_sales
        self.feature_range = feature_range
        self.X_train = []
        self.y_train = []
        self.startDay = startDay
        self.config = Config(config_path)
        self.timesteps = self.config.timesteps
    def __init__(self, X_train, y_train, config_path=''):
        """
        Load the training and test inputs and input shape of training to CNN-LSTM model.

        Args:
          X_train (arr): training inputs with dimensions
            [n_timeseries , n_timesteps, n_products]
          y_train (arr): test inputs with dimensions
            [n_timeseries, n_pred_products]
          config_path (str): file path for config.yaml

        Attributes:
          X_train (arr): training inputs with dimensions
            [n_timeseries , n_timesteps, n_products]
          y_train (arr): test inputs with dimensions
            [n_timeseries, n_pred_products]
          n_timesteps (int): number of timesteps
          n_products (int): number of features
          config (dict): parameter configurations from config.yaml
        """
        self.X_train = X_train
        self.y_train = y_train
        self.n_timesteps = X_train.shape[1]
        self.n_products = X_train.shape[2]
        self.config = Config(config_path)
    def __init__(self, config_path=''):
        """
        Load number of epochs and splits for multi-label stratified k-fold cross validation.

        Args:
          config_path (str): file path for config.yaml

        Attributes:
          config (dict): parameter configurations from config.yaml
          tabnet_params (dict): parameter configurations for TabNet
        """
        self.config = Config(config_path)
        self.tabnet_params = dict(n_d=self.config.n_d,
                                  n_a=self.config.n_a,
                                  n_steps=self.config.n_steps,
                                  gamma=self.config.gamma,
                                  lambda_sparse=self.config.lambda_sparse,
                                  optimizer_fn=optim.Adam,
                                  optimizer_params=dict(lr=2e-2,
                                                        weight_decay=1e-5),
                                  mask_type="entmax",
                                  scheduler_params=dict(mode="min",
                                                        patience=5,
                                                        min_lr=1e-5,
                                                        factor=0.9),
                                  scheduler_fn=ReduceLROnPlateau,
                                  seed=42,
                                  verbose=10)
    def __init__(self, config_path='config.yaml'):
        self.config = Config(config_path)

        self.padded = []
        self.testing_padded = []
        self.df = DataProcessing().run()

        self.training_sentences = []
        self.training_labels = np.array([])

        self.testing_sentences = []
        self.testing_labels = np.array([])
def run_model():
    """Run the following deep learning models based on specified parameters in config.yaml"""
    config = Config('config.yaml')
    if config.model == 'GRU':
        model = GRU()
    elif config.model == 'LSTM':
        model = LSTM()
    elif config.model == 'CNN':
        model = CNN()
    else:
        model = CNN_LSTM()
    model.run()
    def __init__(self, sc=MinMaxScaler(feature_range=(0, 1)), config_path=''):
        """
        Load the parameters for sales forecasting.

        Args:
          sc (obj): scaler
          config_path (str): file path for config.yaml

        Attributes:
          config (dict): parameter configurations from config.yaml
          timesteps (int): number of timesteps
          sc (obj): scaler
        """
        self.config = Config(config_path)
        self.timesteps = self.config.timesteps
        self.sc = sc
    def __init__(self, config_path, in_dim: int):
        """
        Load model parameters for sequence encoder.

        Args:
          config_path (str): file path for config.yaml
          in_dim (int): dimension of input data

        Attributes:
          conv0 (obj): first stacked convolution block
          conv1 (obj): second stacked convolution block
          conv2 (obj): third stacked convolution block
          conv3 (obj): fourth stacked convolution block
        """
        super(SeqEncoder, self).__init__()
        cfg = Config(config_path)
        self.conv0 = Conv1dStack(in_dim, cfg.units1, cfg.kernel_size1, padding=cfg.padding1)
        self.conv1 = Conv1dStack(cfg.units1, cfg.units2, cfg.kernel_size2, padding=cfg.padding2, dilation=cfg.dilation2)
        self.conv2 = Conv1dStack(cfg.units2, cfg.units3, cfg.kernel_size3, padding=cfg.padding3, dilation=cfg.dilation3)
        self.conv3 = Conv1dStack(cfg.units3, cfg.units4, cfg.kernel_size4, padding=cfg.padding4, dilation=cfg.dilation4)
 def __init__(self, config_path='config.yaml'):
     self.config = Config(config_path)
     self.training_labels, self.testing_labels, self.padded, self.testing_padded = ModelPreProcessing(
     ).run()
     self.model = []
     self.history = []
Example #9
0
from torch.utils.tensorboard import SummaryWriter
from pathlib import Path

from ae_model.preprocessing import Load, CreateLoader, VacDataset
from ae_model.autoencoder import AEModel, TrainAE, FromAeModel
from ae_model.prediction import Loss, Predict
from data_processing.helpers import Config

if __name__ == '__main__':
    ### Configure file names and device
    train_data_filename = './datasets/stanford-covid-vaccine/train.json'
    test_data_filename = './datasets/stanford-covid-vaccine/test.json'
    yaml_filename = './config.yaml'
    bpps_dirname = f'./datasets/stanford-covid-vaccine/bpps/'
    device = "cuda" if torch.cuda.is_available() else "cpu"
    cfg = Config(yaml_filename)

    ### Load and preprocess training data and test data to feed into denoising Auto Encoder (AE) model
    load = Load(base_train_data=train_data_filename, base_test_data=test_data_filename)
    denoised_train_data = load.denoise()
    public_df, private_df = load.query_seq_length()
    features, _ = load.preprocess(denoised_train_data, True)
    features_tensor = torch.from_numpy(features)

    create_loader = CreateLoader()
    structure_adj0 = create_loader.get_structure_adj(denoised_train_data)
    distance_matrix0 = create_loader.get_distance_matrix(structure_adj0.shape[1])
    dataset0 = VacDataset(features_tensor, denoised_train_data, structure_adj0, distance_matrix0, bpps_dirname, None)
    features, _ = load.preprocess(public_df, True)
    features_tensor = torch.from_numpy(features)
Example #10
0
 def __init__(self, config_path='config.yaml'):
     self.config = Config(config_path)
     self.dictionary, self.corpus = LDAPreProcessing().run()
     self.NUM_TOPICS = self.config.NUM_TOPICS