예제 #1
0
def run_models(target_var: str):
    parsimonious()
    # -------
    # LSTM
    # -------
    rnn(  # earnn(
        experiment="one_month_forecast",
        include_pred_month=True,
        surrounding_pixels=None,
        explain=False,
        static=None,  # "features",
        ignore_vars=None,
        num_epochs=50,  # 50
        early_stopping=5,  # 5
        hidden_size=256,
        predict_delta=False,
        normalize_y=True,
        include_prev_y=False,
        include_latlons=False,
    )

    # -------
    # EALSTM
    # -------

    # rename the output file
    data_path = get_data_path()

    _rename_directory(
        from_path=data_path / "models" / "one_month_forecast",
        to_path=data_path / "models" /
        f"one_month_forecast_adede_only_target_{target_var}",
        with_datetime=False,
    )
def main(target_var, all_vars):
    # RUN engineer
    engineer(target_var=target_var)

    autoregressive = [target_var]  # 'VCI3M'
    dynamic = ["precip", "t2m", "pet", "E", "SMroot", "SMsurf"]
    static_list = [False, False, True]

    for vars_to_include, static_bool in zip(
        [autoregressive, autoregressive + dynamic, autoregressive + dynamic],
            static_list,
    ):
        print(
            f'\n{"-" * 10}\nRunning experiment with: {vars_to_include} with static: {static_bool} for {target_var}\n{"-" * 10}'
        )

        # FIT models
        vars_to_exclude = [v for v in all_vars if v not in vars_to_include]

        parsimonious()
        if static_bool:
            lstm(vars_to_exclude, static="features")
            ealstm(vars_to_exclude, static="features")
        else:
            lstm(vars_to_exclude, static=None)

        # RENAME model directories
        data_dir = get_data_path()
        rename_model_experiment_file(data_dir,
                                     vars_to_include,
                                     static=static_bool,
                                     target_var=target_var)
예제 #3
0
def models(target_var: str = "VCI1M"):
    # NO IGNORE VARS
    ignore_vars = None
    # drop the target variable from ignore_vars
    # ignore_vars = [v for v in ignore_vars if v != target_var]
    # assert target_var not in ignore_vars

    # -------------
    # persistence
    # -------------
    parsimonious()

    # regression(ignore_vars=ignore_vars)
    # gbdt(ignore_vars=ignore_vars)
    # linear_nn(ignore_vars=ignore_vars)

    # -------------
    # LSTM
    # -------------
    rnn(
        experiment="one_month_forecast",
        include_pred_month=True,
        surrounding_pixels=None,
        explain=False,
        static="features",
        ignore_vars=ignore_vars,
        num_epochs=50,
        early_stopping=5,
        hidden_size=256,
        include_latlons=True,
    )

    # -------------
    # EALSTM
    # -------------
    earnn(
        experiment="one_month_forecast",
        include_pred_month=True,
        surrounding_pixels=None,
        pretrained=False,
        explain=False,
        static="features",
        ignore_vars=ignore_vars,
        num_epochs=50,
        early_stopping=5,
        hidden_size=256,
        static_embedding_size=64,
        include_latlons=True,
    )

    # rename the output file
    data_path = get_data_path()

    _rename_directory(
        from_path=data_path / "models" / "one_month_forecast",
        to_path=data_path / "models" /
        f"one_month_forecast_BOKU_{target_var}_adede_only_vars",
    )
예제 #4
0
    always_ignore_vars = [
        "VCI",
        "ndvi",
        "p84.162",
        "sp",
        "tp",
        "Eb",
        "tprate_std_1",
        "tprate_mean_1",
        "tprate_std_2",
        "tprate_mean_2",
        "tprate_std_3",
        "tprate_mean_3",
    ]

    parsimonious(experiment="nowcast")
    # regression(ignore_vars=always_ignore_vars)
    # gbdt(ignore_vars=always_ignore_vars)
    # linear_nn(ignore_vars=always_ignore_vars)
    # rnn(ignore_vars=always_ignore_vars)
    earnn(
        experiment="nowcast",
        include_pred_month=True,
        surrounding_pixels=None,
        pretrained=False,
        explain=False,
        static="features",
        ignore_vars=always_ignore_vars,
        num_epochs=1,  #  50,
        early_stopping=5,
        hidden_size=256,
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:")
    parsimonious()
    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")

    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,
    )
예제 #6
0
def models(
    target_var: str = "boku_VCI",
    adede_only=False,
    experiment_name=None,
    check_inversion=False,
):
    if adede_only:
        ignore_vars = [
            "p84.162",
            "sp",
            "tp",
            "Eb",
            "VCI",
            "modis_ndvi",
            "pev",
            "t2m",
            "E",
            "SMroot",
            "SMsurf",
        ]
    else:
        ignore_vars = [
            "p84.162",
            "sp",
            "tp",
            "Eb",
            "VCI",
            "modis_ndvi",
            "SMroot",
            "SMsurf",
        ]

    # drop the target variable from ignore_vars
    ignore_vars = [v for v in ignore_vars if v != target_var]
    assert target_var not in ignore_vars

    # -------------
    # persistence
    # -------------
    parsimonious()

    # regression(ignore_vars=ignore_vars)
    # gbdt(ignore_vars=ignore_vars)
    # linear_nn(ignore_vars=ignore_vars)

    # -------------
    # LSTM
    # -------------
    rnn(
        experiment="one_month_forecast",
        include_pred_month=True,
        surrounding_pixels=None,
        explain=False,
        static="features",
        ignore_vars=ignore_vars,
        num_epochs=50,  # 1,  # 50 ,
        early_stopping=5,
        hidden_size=256,
        include_latlons=True,
        check_inversion=check_inversion,
    )

    # -------------
    # EALSTM
    # -------------
    earnn(
        experiment="one_month_forecast",
        include_pred_month=True,
        surrounding_pixels=None,
        pretrained=False,
        explain=False,
        static="features",
        ignore_vars=ignore_vars,
        num_epochs=50,  # 1,  # 50 ,
        early_stopping=5,
        hidden_size=256,
        static_embedding_size=64,
        include_latlons=True,
        check_inversion=check_inversion,
    )

    # rename the output file
    data_path = get_data_path()
    if experiment_name is None:
        experiment_name = (
            f"one_month_forecast_BOKU_{target_var}_our_vars_{'only_P_VCI' if adede_only else 'ALL'}",
        )

    _rename_directory(
        from_path=data_path / "models" / "one_month_forecast",
        to_path=data_path / "models" / experiment_name,
    )
예제 #7
0
from scripts.utils import _rename_directory, get_data_path
from _base_models import parsimonious, regression, linear_nn, rnn, earnn


if __name__ == "__main__":
    # NOTE: why have we downloaded 2 variables for ERA5 evaporaton
    # important_vars = ["VCI", "precip", "t2m", "pev", "p0005", "SMsurf", "SMroot"]
    # always_ignore_vars = ["ndvi", "p84.162", "sp", "tp", "Eb", "E", "p0001"]
    important_vars = ["VCI", "precip", "t2m", "pev", "E", "SMsurf", "SMroot"]
    always_ignore_vars = ["p84.162", "sp", "tp", "Eb", "VCI1M", "RFE1M"]  # "ndvi",

    # -------------
    # persistence
    # -------------
    parsimonious()

    # regression(ignore_vars=always_ignore_vars)
    # gbdt(ignore_vars=always_ignore_vars)
    # linear_nn(ignore_vars=always_ignore_vars)

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