def run_experiments(
    train_hilo: str,
    test_hilo: str,
    train_length: int,
    static: bool,
    ignore_vars: Optional[List[str]] = None,
    run_regression: bool = True,
    all_models: bool = False,
):
    # run baseline model
    print("\n\nBASELINE MODEL:")
    persistence()
    print("\n\n")

    # RUN EXPERIMENTS
    if run_regression:
        regression(ignore_vars=ignore_vars, include_static=static)

    if static:
        # 'embeddings' or 'features'
        try:
            earnn(pretrained=False,
                  ignore_vars=ignore_vars,
                  static="embeddings")
        except RuntimeError:
            print(f"\n{'*'*10}\n FAILED: EALSTM \n{'*'*10}\n")

        if all_models:  # run all other models ?
            try:
                linear_nn(ignore_vars=ignore_vars, static="embeddings")
            except RuntimeError:
                print(f"\n{'*'*10}\n FAILED: LinearNN \n{'*'*10}\n")

            try:
                rnn(ignore_vars=ignore_vars, static="embeddings")
            except RuntimeError:
                print(f"\n{'*'*10}\n FAILED: RNN \n{'*'*10}\n")

            try:
                earnn(pretrained=False, ignore_vars=ignore_vars, static=None)
            except RuntimeError:
                print(f"\n{'*'*10}\n FAILED: EALSTM \n{'*'*10}\n")

    else:  # NO STATIC data
        try:
            rnn(ignore_vars=ignore_vars, static=None)
        except RuntimeError:
            print(f"\n{'*'*10}\n FAILED: RNN \n{'*'*10}\n")

        if all_models:  # run all other models ?
            try:
                linear_nn(ignore_vars=ignore_vars, static=None)
            except RuntimeError:
                print(f"\n{'*'*10}\n FAILED: LinearNN \n{'*'*10}\n")

    # RENAME DIRECTORY
    data_dir = get_data_path()
    rename_experiment_dir(data_dir,
                          train_hilo=train_hilo,
                          test_hilo=test_hilo,
                          train_length=train_length)
    print(
        f"\n**Experiment finished**\n",
        "train_length: " + str(train_length),
        "test_hilo: " + test_hilo,
        "train_hilo: " + train_hilo,
        "\ntrain_years:\n",
        train_years,
        "\n",
        "test_years:\n",
        test_years,
    )
예제 #2
0
def run_all_models_as_experiments(
    vars_to_include: List[str],
    ignore_vars: List[str],
    static: bool,
    run_regression: bool = True,
):
    print(f"Experiment {vars_to_include} Static: {static}")

    # RUN EXPERIMENTS
    if run_regression:
        regression(ignore_vars=ignore_vars, include_static=static)

    if static:
        # 'embeddings' or 'features'
        try:
            linear_nn(ignore_vars=ignore_vars, static="embeddings")
        except KeyboardInterrupt:
            raise
        except Exception as e:
            logging.debug(
                f"\n{'*'*10}\n FAILED: LinearNN for vars={vars_to_include} static={static}\n{'*'*10}\n"
            )
            logging.debug(e)

        try:
            rnn(ignore_vars=ignore_vars, static="embeddings")
        except KeyboardInterrupt:
            raise
        except Exception as e:
            logging.debug(
                f"\n{'*'*10}\n FAILED: RNN for vars={vars_to_include} static={static}\n{'*'*10}\n"
            )
            logging.debug(e)

        try:
            earnn(pretrained=False,
                  ignore_vars=ignore_vars,
                  static="embeddings")
        except KeyboardInterrupt:
            raise
        except Exception as e:
            logging.debug(
                f"\n{'*'*10}\n FAILED: EALSTM for vars={vars_to_include} static={static}\n{'*'*10}\n"
            )
            logging.debug(e)

    else:
        try:
            linear_nn(ignore_vars=ignore_vars, static=None)
        except KeyboardInterrupt:
            raise
        except Exception as e:
            logging.debug(
                f"\n{'*'*10}\n FAILED: LinearNN for vars={vars_to_include} static={static}\n{'*'*10}\n"
            )
            logging.debug(e)

        try:
            rnn(ignore_vars=ignore_vars, static=None)
        except KeyboardInterrupt:
            raise
        except Exception as e:
            logging.debug(
                f"\n{'*'*10}\n FAILED: RNN for vars={vars_to_include} static={static}\n{'*'*10}\n"
            )
            logging.debug(e)

        try:
            # NO NEED to run the EALSTM without static data because
            # just equivalent to the RNN
            earnn(pretrained=False, ignore_vars=ignore_vars, static=None)
        except KeyboardInterrupt:
            raise
        except Exception as e:
            logging.debug(
                f"\n{'*'*10}\n FAILED: EALSTM for vars={vars_to_include} static={static}\n{'*'*10}\n"
            )
            logging.debug(e)

    # RENAME DIRECTORY
    data_dir = get_data_path().absolute()
    rename_model_experiment_file(data_dir, vars_to_include, static)
    print(f"Experiment {vars_to_include} finished")
    regression(
        ignore_vars=always_ignore_vars,
        experiment="one_month_forecast",
        include_pred_month=True,
        surrounding_pixels=None,
        explain=False,
    )

    # # gbdt(ignore_vars=always_ignore_vars)
    linear_nn(
        ignore_vars=always_ignore_vars,
        experiment="one_month_forecast",
        include_pred_month=True,
        surrounding_pixels=None,
        explain=False,
        num_epochs=num_epochs,
        early_stopping=early_stopping,
        layer_sizes=[hidden_size],
        include_latlons=True,
        include_yearly_aggs=False,
        clear_nans=True,
    )

    # -------------
    # LSTM
    # -------------
    rnn(
        experiment="one_month_forecast",
        include_pred_month=True,
        surrounding_pixels=None,
        explain=False,