aliases.R 2.77 KB
Newer Older
1
2
3
# Central location for parameter aliases.
# See https://lightgbm.readthedocs.io/en/latest/Parameters.html#core-parameters

4
5
6
# [description] List of respected parameter aliases specific to lgb.Dataset. Wrapped in a function to
#               take advantage of lazy evaluation (so it doesn't matter what order
#               R sources files during installation).
Nikita Titov's avatar
Nikita Titov committed
7
# [return] A named list, where each key is a parameter relevant to lgb.Dataset and each value is a character
8
9
#          vector of corresponding aliases.
.DATASET_PARAMETERS <- function() {
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
    all_aliases <- .PARAMETER_ALIASES()
    return(all_aliases[c(
        "bin_construct_sample_cnt"
        , "categorical_feature"
        , "data_random_seed"
        , "enable_bundle"
        , "feature_pre_filter"
        , "forcedbins_filename"
        , "group_column"
        , "header"
        , "ignore_column"
        , "is_enable_sparse"
        , "label_column"
        , "linear_tree"
        , "max_bin"
        , "max_bin_by_feature"
        , "min_data_in_bin"
        , "pre_partition"
        , "precise_float_parser"
        , "two_round"
        , "use_missing"
        , "weight_column"
        , "zero_as_missing"
    )])
34
35
}

36
37
38
39
# [description] Non-exported environment, used for caching details that only need to be
#               computed once per R session.
.lgb_session_cache_env <- new.env()

40
41
42
43
# [description] List of respected parameter aliases. Wrapped in a function to take advantage of
#               lazy evaluation (so it doesn't matter what order R sources files during installation).
# [return] A named list, where each key is a main LightGBM parameter and each value is a character
#          vector of corresponding aliases.
44
.PARAMETER_ALIASES <- function() {
45
46
47
    if (exists("PARAMETER_ALIASES", where = .lgb_session_cache_env)) {
        return(get("PARAMETER_ALIASES", envir = .lgb_session_cache_env))
    }
48
49
50
    params_to_aliases <- jsonlite::fromJSON(
        .Call(
            LGBM_DumpParamAliases_R
51
        )
52
    )
53
54
55
56
    for (main_name in names(params_to_aliases)) {
        aliases_with_main_name <- c(main_name, unlist(params_to_aliases[[main_name]]))
        params_to_aliases[[main_name]] <- aliases_with_main_name
    }
57
58
59
60
61
62
    # store in cache so the next call to `.PARAMETER_ALIASES()` doesn't need to recompute this
    assign(
        x = "PARAMETER_ALIASES"
        , value = params_to_aliases
        , envir = .lgb_session_cache_env
    )
63
    return(params_to_aliases)
64
}
65
66
67
68
69
70
71

# [description]
#     Per https://github.com/microsoft/LightGBM/blob/master/docs/Parameters.rst#metric,
#     a few different strings can be used to indicate "no metrics".
# [returns]
#     A character vector
.NO_METRIC_STRINGS <- function() {
72
73
74
75
76
77
78
79
    return(
        c(
            "na"
            , "None"
            , "null"
            , "custom"
        )
    )
80
}