| Title: | Provides an R Interface to the 'FuzzyCoCo' C++ Library and Extends It |
|---|---|
| Description: | Provides and extends the 'Fuzzy Coco' algorithm by wrapping the 'FuzzyCoCo' 'C++' Library, cf <https://github.com/Lonza-RND-Data-Science/fuzzycoco>. 'Fuzzy Coco' constructs systems that predict the outcome of a human decision-making process while providing an understandable explanation of a possible reasoning leading to it. The constructed fuzzy systems are composed of rules and linguistic variables. This package provides a 'S3' classic interface (fit_xy()/fit()/predict()/evaluate()) and a 'tidymodels'/'parsnip' interface, a custom engine with custom iteration stop criterion and progress bar support as well as a systematic implementation that do not rely on genetic programming but rather explore all possible combinations. |
| Authors: | Karl Forner [aut, cre] |
| Maintainer: | Karl Forner <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.0 |
| Built: | 2026-05-20 08:10:09 UTC |
| Source: | https://github.com/lonza-rnd-data-science/rfuzzycoco |
Provides and extends the 'Fuzzy Coco' algorithm by wrapping the 'FuzzyCoCo' 'C++' Library, cf https://github.com/Lonza-RND-Data-Science/fuzzycoco. 'Fuzzy Coco' constructs systems that predict the outcome of a human decision-making process while providing an understandable explanation of a possible reasoning leading to it. The constructed fuzzy systems are composed of rules and linguistic variables. This package provides a 'S3' classic interface (fit_xy()/fit()/predict()/evaluate()) and a 'tidymodels'/'parsnip' interface, a custom engine with custom iteration stop criterion and progress bar support as well as a systematic implementation that do not rely on genetic programming but rather explore all possible combinations.
Rfuzzycoco provides the FuzzyCoCo algorithm, cf Fuzzy CoCo: a cooperative-coevolutionary approach to fuzzy modeling from Carlos Andrés Peña-Reyes
Maintainer: Karl Forner [email protected]
Useful links:
Report bugs at https://github.com/Lonza-RND-Data-Science/Rfuzzycoco/issues
computes the optimal fuzzy set positions based on the distribution of the data
compute_optimal_quantile_fuzzy_set_positions(df, nb_sets)compute_optimal_quantile_fuzzy_set_positions(df, nb_sets)
df |
the data as a data frame |
nb_sets |
the number of fuzzy sets |
a list, named after the df column names, holding the vector of positions per variable
pos <- compute_optimal_quantile_fuzzy_set_positions(mtcars, 3) print("position for 2nd fuzzy set for qsec var", pos$qsec[[2]])pos <- compute_optimal_quantile_fuzzy_set_positions(mtcars, 3) print("position for 2nd fuzzy set for qsec var", pos$qsec[[2]])
evaluate the fuzzy system from a fit on some given data
evaluate_fuzzy_system(fs, data, params, verbose = FALSE)evaluate_fuzzy_system(fs, data, params, verbose = FALSE)
fs |
the fuzzy system to evaluate (as a named list) |
data |
the data to evaluate the fuzzy system on |
params |
the fuzzycoco parameters. probably not needed... |
verbose |
whether to be verbose |
the evaluation as a named list:
fitness: the fitness value
metrics: the evaluation metrics as a named list
model <- fuzzycoco("regression", example_mtcars()$params, seed = 123) x <- mtcars[c("mpg", "hp", "wt")] y <- mtcars["qsec"] fit <- fit_xy(model, x, y, progress = FALSE) res <- evaluate_fuzzy_system(fit$fuzzy_system, cbind(x, y), fit$params) print(res$metrics$rmse)model <- fuzzycoco("regression", example_mtcars()$params, seed = 123) x <- mtcars[c("mpg", "hp", "wt")] y <- mtcars["qsec"] fit <- fit_xy(model, x, y, progress = FALSE) res <- evaluate_fuzzy_system(fit$fuzzy_system, cbind(x, y), fit$params) print(res$metrics$rmse)
N.B: just a S3 method method wrapping the evaluate_fuzzy_system() function
## S3 method for class 'fuzzycoco_fit' evaluate(x, data, verbose = FALSE, ...)## S3 method for class 'fuzzycoco_fit' evaluate(x, data, verbose = FALSE, ...)
x |
the fuzzycoco_fit object containing the fuzzy system to evaluate |
data |
the data to evaluate the fuzzy system on |
verbose |
whether to be verbose |
... |
not used. Only for S3 generic consistency |
the evaluation as a named list:
fitness: the fitness value
metrics: the evaluation metrics as a named list
model <- fuzzycoco("regression", example_mtcars()$params, seed = 123) df <- mtcars[c("mpg", "hp", "wt", "qsec")] fit <- fit(model, qsec ~ ., df, engine = "rcpp", seed = 456, max_generations = 20) res <- evaluate(fit, df) print(res$fitness)model <- fuzzycoco("regression", example_mtcars()$params, seed = 123) df <- mtcars[c("mpg", "hp", "wt", "qsec")] fit <- fit(model, qsec ~ ., df, engine = "rcpp", seed = 456, max_generations = 20) res <- evaluate(fit, df) print(res$fitness)
an example dataset based on iris with a binary categorical (non-factor) response
example_iris_binary_categorical()example_iris_binary_categorical()
the example as a named list with:
params: the model parameters
data: the data to fit as a data frame
model <- fuzzycoco("classification", example_iris_binary_categorical()$params) fit <- fit(model, Species ~ ., example_iris_binary_categorical()$data, max_generations = 20, progress = FALSE)model <- fuzzycoco("classification", example_iris_binary_categorical()$params) fit <- fit(model, Species ~ ., example_iris_binary_categorical()$data, max_generations = 20, progress = FALSE)
a small (36 rows) dataset extracted from iris with a binary 0/1 outcome OUT response variable
example_iris36()example_iris36()
the example as a named list with:
params: the model parameters
data: the data to fit as a data frame
model <- fuzzycoco("classification", example_iris36()$params, seed = 123) fit <- fit(model, OUT ~ ., example_iris36()$data, max_generations = 20, progress = FALSE)model <- fuzzycoco("classification", example_iris36()$params, seed = 123) fit <- fit(model, OUT ~ ., example_iris36()$data, max_generations = 20, progress = FALSE)
model parameters and data for the mtcars regression example
example_mtcars()example_mtcars()
the example as a named list with:
params: the model parameters
data: the data to fit as a data frame
model <- fuzzycoco("regression", example_mtcars()$params) fit <- fit(model, qsec ~ ., example_mtcars()$data, max_generations = 20, progress = FALSE)model <- fuzzycoco("regression", example_mtcars()$params) fit <- fit(model, qsec ~ ., example_mtcars()$data, max_generations = 20, progress = FALSE)
a one-row overview of a fuzzy system with the usage of variables, the fitness, number of generations and optionally a metric
fit_to_df(fit, metric = NULL)fit_to_df(fit, metric = NULL)
fit |
a fit object, as returned by [fit. |
metric |
an optional metric name to report (e.g. |
a one-row data frame
Other fit_utils:
fs_rules_to_df(),
fs_used_vars_to_df()
model <- fuzzycoco("regression", example_mtcars()$params, seed = 123) df <- mtcars[c("mpg", "hp", "wt", "qsec")] fit <- fit(model, qsec ~ ., df, seed = 456, max_generations = 10, progress = FALSE) print(fit_to_df(fit))model <- fuzzycoco("regression", example_mtcars()$params, seed = 123) df <- mtcars[c("mpg", "hp", "wt", "qsec")] fit <- fit(model, qsec ~ ., df, seed = 456, max_generations = 10, progress = FALSE) print(fit_to_df(fit))
N.B: the underlying C++ implementation is able to automatically set some missing parameters (NA).
The final parameters are those returned by the function, is the params slot.
## S3 method for class 'fuzzycoco_model' fit_xy( object, x, y, engine = FUZZY_COCO_HYBRID_ENGINE, max_generations = object$params$global_params$max_generations, max_fitness = object$params$global_params$max_fitness, seed = object$seed, verbose = object$verbose, ... )## S3 method for class 'fuzzycoco_model' fit_xy( object, x, y, engine = FUZZY_COCO_HYBRID_ENGINE, max_generations = object$params$global_params$max_generations, max_fitness = object$params$global_params$max_fitness, seed = object$seed, verbose = object$verbose, ... )
object |
the fuzzycoco_model object to fit |
x |
the input variables data (usually to fit) as a dataframe |
y |
the output variables data (usually to fit) as a dataframe |
engine |
the fuzzy coco fit engine to use, one of rcpp and hybrid |
max_generations |
The maximum number of iterations of the algorithm. Each iteration produces a new generation of the rules and membership functions populations. |
max_fitness |
a stop condition: the iterations stop as soon as a generated fuzzy system fitness reaches that threshold. |
seed |
the RNG seed to use (to fit the model) |
verbose |
whether to be verbose |
... |
Arguments passed on to
|
the fit as a named list
model <- fuzzycoco("regression", example_mtcars()$params, seed = 123) x <- mtcars[c("mpg", "hp", "wt")] y <- mtcars["qsec"] fit <- fit_xy(model, x, y, progress = FALSE) print(names(fit))model <- fuzzycoco("regression", example_mtcars()$params, seed = 123) x <- mtcars[c("mpg", "hp", "wt")] y <- mtcars["qsec"] fit <- fit_xy(model, x, y, progress = FALSE) print(names(fit))
N.B: fix_xy() is the workhorse, fit() is a simple formula-based layer
## S3 method for class 'fuzzycoco_model' fit( object, formula, data, engine = FUZZY_COCO_HYBRID_ENGINE, max_generations = object$params$global_params$max_generations, max_fitness = object$params$global_params$max_fitness, seed = object$seed, verbose = object$verbose, ... )## S3 method for class 'fuzzycoco_model' fit( object, formula, data, engine = FUZZY_COCO_HYBRID_ENGINE, max_generations = object$params$global_params$max_generations, max_fitness = object$params$global_params$max_fitness, seed = object$seed, verbose = object$verbose, ... )
object |
the fuzzycoco_model object to fit |
formula |
the fuzzy coco model as a formula |
data |
the data to fit as a data frame. The output variables must be grouped AFTER the input variables |
engine |
the fuzzy coco fit engine to use, one of rcpp and hybrid |
max_generations |
The maximum number of iterations of the algorithm. Each iteration produces a new generation of the rules and membership functions populations. |
max_fitness |
a stop condition: the iterations stop as soon as a generated fuzzy system fitness reaches that threshold. |
seed |
the RNG seed to use (to fit the model) |
verbose |
whether to be verbose |
... |
Arguments passed on to
|
the fit as a named list
model <- fuzzycoco("regression", example_mtcars()$params, seed = 123) df <- mtcars[c("mpg", "hp", "wt", "qsec")] fit <- fit(model, qsec ~ ., df, seed = 456, max_generations = 10, progress = FALSE) print(names(fit))model <- fuzzycoco("regression", example_mtcars()$params, seed = 123) df <- mtcars[c("mpg", "hp", "wt", "qsec")] fit <- fit(model, qsec ~ ., df, seed = 456, max_generations = 10, progress = FALSE) print(names(fit))
format the fuzzy rules as a data frame
fs_rules_to_df(fuzzy_system_desc)fs_rules_to_df(fuzzy_system_desc)
fuzzy_system_desc |
a fuzzy system description as a named list |
a data frame, one row per rule, including the default rule, in columns the input and output variables. The values are the corresponding fuzzy set number.
Other fit_utils:
fit_to_df(),
fs_used_vars_to_df()
model <- fuzzycoco("regression", example_mtcars()$params, seed = 123) df <- mtcars[c("mpg", "hp", "wt", "qsec")] fit <- fit(model, qsec ~ ., df, seed = 456, max_generations = 10, progress = FALSE) print(fs_rules_to_df(fit$fuzzy_system))model <- fuzzycoco("regression", example_mtcars()$params, seed = 123) df <- mtcars[c("mpg", "hp", "wt", "qsec")] fit <- fit(model, qsec ~ ., df, seed = 456, max_generations = 10, progress = FALSE) print(fs_rules_to_df(fit$fuzzy_system))
extract the usage of the variables by a fuzzy system
fs_used_vars_to_df(fuzzy_system_desc)fs_used_vars_to_df(fuzzy_system_desc)
fuzzy_system_desc |
a fuzzy system description as a named list |
a one-row data frame, in columns the input and output variables, with TRUE iff the variable is used.
Other fit_utils:
fit_to_df(),
fs_rules_to_df()
model <- fuzzycoco("regression", example_mtcars()$params, seed = 123) df <- mtcars[c("mpg", "hp", "wt", "qsec")] fit <- fit(model, qsec ~ ., df, seed = 456, max_generations = 10, progress = FALSE) print(fs_rules_to_df(fit$fuzzy_system))model <- fuzzycoco("regression", example_mtcars()$params, seed = 123) df <- mtcars[c("mpg", "hp", "wt", "qsec")] fit <- fit(model, qsec ~ ., df, seed = 456, max_generations = 10, progress = FALSE) print(fs_rules_to_df(fit$fuzzy_system))
parsnip model function
fuzzy_coco_parsnip( mode = "unknown", params, engine = FUZZY_COCO_HYBRID_ENGINE, seed = sample.int(10^5, 1), verbose = FALSE )fuzzy_coco_parsnip( mode = "unknown", params, engine = FUZZY_COCO_HYBRID_ENGINE, seed = sample.int(10^5, 1), verbose = FALSE )
mode |
the type of model, either classification or regression |
params |
fuzzy coco parameters, as a recursive named list, cf |
engine |
the fuzzy coco fit engine to use, one of rcpp and hybrid |
seed |
the RNG seed to use (to fit the model) |
verbose |
whether to be verbose |
a parsnip model
spec <- fuzzy_coco_parsnip("regression", params = example_mtcars()$params, seed = 123) fit <- spec |> parsnip::set_engine("hybrid") |> parsnip::fit(qsec ~ ., data = example_mtcars()$data)spec <- fuzzy_coco_parsnip("regression", params = example_mtcars()$params, seed = 123) fit <- spec |> parsnip::set_engine("hybrid") |> parsnip::fit(qsec ~ ., data = example_mtcars()$data)
This is a R implementation of a systematic search, where the fuzzy set positions are determined
by the distribution of the data (cf compute_optimal_quantile_fuzzy_set_positions() and the rules
are systematically explored
fuzzy_coco_systematic_fit(x, y, params, fitter)fuzzy_coco_systematic_fit(x, y, params, fitter)
x |
the input variables data (usually to fit) as a dataframe |
y |
the output variables data (usually to fit) as a dataframe |
params |
fuzzy coco parameters, as a recursive named list, cf |
fitter |
a function metrics –> fitness value providing the objective/fitness function to optimize TODO: describe the metrics |
N.B: this is experimental, only possible for a small number of variables. Not all parameters are used, obviously, and currently fitness_params$output_vars_defuzz_thresholds has to be set explicitly.
a list of the best results (all ties). Each result is also a named list(metric=,fs=) holding the corresponding metric value and the fuzzy system.
fitter <- function(metrics) 2^-metrics$rms params <- example_mtcars()$params params$fitness_params$output_vars_defuzz_thresholds <- 0 params$global_params$nb_rules <- 1 params$global_params$nb_max_var_per_rule <- 2 params$output_vars_params$nb_sets <- 2 x <- mtcars[c("mpg", "hp", "wt")] y <- mtcars["qsec"] fit <- fuzzy_coco_systematic_fit(x, y, params, fitter)fitter <- function(metrics) 2^-metrics$rms params <- example_mtcars()$params params$fitness_params$output_vars_defuzz_thresholds <- 0 params$global_params$nb_rules <- 1 params$global_params$nb_max_var_per_rule <- 2 params$output_vars_params$nb_sets <- 2 x <- mtcars[c("mpg", "hp", "wt")] y <- mtcars["qsec"] fit <- fuzzy_coco_systematic_fit(x, y, params, fitter)
creates a model for the Fuzzy Coco algorithm
fuzzycoco( mode = c("classification", "regression"), params, seed = sample.int(10^5, 1), verbose = FALSE )fuzzycoco( mode = c("classification", "regression"), params, seed = sample.int(10^5, 1), verbose = FALSE )
mode |
the type of model, either classification or regression |
params |
fuzzy coco parameters, as a recursive named list, cf |
seed |
the RNG seed to use (to fit the model) |
verbose |
whether to be verbose |
a fuzzycoco_model object (named list)
model <- fuzzycoco("regression", params(nb_rules = 1, nb_max_var_per_rule = 3), seed = 123)model <- fuzzycoco("regression", params(nb_rules = 1, nb_max_var_per_rule = 3), seed = 123)
lowest-level implementation of the fitting of a fuzzy coco model using the hybrid engine
fuzzycoco_fit_df_hybrid( model, x, y, until = stop_engine_on_first_of(max_generations = model$params$global_params$max_generations, max_fitness = model$params$global_params$max_fitness), verbose = model$verbose, progress = TRUE )fuzzycoco_fit_df_hybrid( model, x, y, until = stop_engine_on_first_of(max_generations = model$params$global_params$max_generations, max_fitness = model$params$global_params$max_fitness), verbose = model$verbose, progress = TRUE )
model |
a Fuzzy Coco model as a |
x |
the input variables data (usually to fit) as a dataframe |
y |
the output variables data (usually to fit) as a dataframe |
until |
function that takes an |
verbose |
whether to be verbose |
progress |
whether to display the computation progress (using progressr, if available) |
a named list as a fuzzy_coco fit object
model <- fuzzycoco("regression", example_mtcars()$params) fit <- fuzzycoco_fit_df_hybrid(model, mtcars[c("mpg", "hp", "wt")], mtcars["qsec"])model <- fuzzycoco("regression", example_mtcars()$params) fit <- fuzzycoco_fit_df_hybrid(model, mtcars[c("mpg", "hp", "wt")], mtcars["qsec"])
utility to build the Fuzzy Coco parameters data structure
params( nb_rules, nb_max_var_per_rule, max_generations = 100, max_fitness = 1, nb_cooperators = 2, influence_rules_initial_population = FALSE, influence_evolving_ratio = 0.8, ivars.nb_sets = 3, ivars.nb_bits_vars = NA_integer_, ivars.nb_bits_sets = NA_integer_, ivars.nb_bits_pos = NA_integer_, ovars.nb_sets = 3, ovars.nb_bits_vars = NA_integer_, ovars.nb_bits_sets = NA_integer_, ovars.nb_bits_pos = NA_integer_, rules.pop_size = 100, rules.elite_size = 5, rules.cx_prob = 0.5, rules.mut_flip_genome = 0.5, rules.mut_flip_bit = 0.025, mfs.pop_size = 100, mfs.elite_size = 5, mfs.cx_prob = 0.5, mfs.mut_flip_genome = 0.5, mfs.mut_flip_bit = 0.025, output_vars_defuzz_thresholds = NA, metricsw.sensitivity = 1, metricsw.specificity = 0.8, metricsw.accuracy = 0, metricsw.ppv = 0, metricsw.rmse = 0, metricsw.rrse = 0, metricsw.rae = 0, metricsw.mse = 0, metricsw.distanceThreshold = 0, metricsw.distanceMinThreshold = 0, metricsw.nb_vars = 0, metricsw.overLearn = 0, metricsw.true_positives = 0, metricsw.false_positives = 0, metricsw.true_negatives = 0, metricsw.false_negatives = 0, features_weights = list() )params( nb_rules, nb_max_var_per_rule, max_generations = 100, max_fitness = 1, nb_cooperators = 2, influence_rules_initial_population = FALSE, influence_evolving_ratio = 0.8, ivars.nb_sets = 3, ivars.nb_bits_vars = NA_integer_, ivars.nb_bits_sets = NA_integer_, ivars.nb_bits_pos = NA_integer_, ovars.nb_sets = 3, ovars.nb_bits_vars = NA_integer_, ovars.nb_bits_sets = NA_integer_, ovars.nb_bits_pos = NA_integer_, rules.pop_size = 100, rules.elite_size = 5, rules.cx_prob = 0.5, rules.mut_flip_genome = 0.5, rules.mut_flip_bit = 0.025, mfs.pop_size = 100, mfs.elite_size = 5, mfs.cx_prob = 0.5, mfs.mut_flip_genome = 0.5, mfs.mut_flip_bit = 0.025, output_vars_defuzz_thresholds = NA, metricsw.sensitivity = 1, metricsw.specificity = 0.8, metricsw.accuracy = 0, metricsw.ppv = 0, metricsw.rmse = 0, metricsw.rrse = 0, metricsw.rae = 0, metricsw.mse = 0, metricsw.distanceThreshold = 0, metricsw.distanceMinThreshold = 0, metricsw.nb_vars = 0, metricsw.overLearn = 0, metricsw.true_positives = 0, metricsw.false_positives = 0, metricsw.true_negatives = 0, metricsw.false_negatives = 0, features_weights = list() )
nb_rules |
(mandatory) the number of rules in the fuzzy system |
nb_max_var_per_rule |
(mandatory) The maximum number of antecedents (input variables) to use in each rule. |
max_generations, max_fitness, nb_cooperators, influence_rules_initial_population, influence_evolving_ratio, ivars.nb_sets, ivars.nb_bits_vars, ivars.nb_bits_sets, ivars.nb_bits_pos, ovars.nb_sets, ovars.nb_bits_vars, ovars.nb_bits_sets, ovars.nb_bits_pos, rules.pop_size, rules.elite_size, rules.cx_prob, rules.mut_flip_genome, rules.mut_flip_bit, mfs.pop_size, mfs.elite_size, mfs.cx_prob, mfs.mut_flip_genome, mfs.mut_flip_bit, output_vars_defuzz_thresholds, metricsw.sensitivity, metricsw.specificity, metricsw.accuracy, metricsw.ppv, metricsw.rmse, metricsw.rrse, metricsw.rae, metricsw.mse, metricsw.distanceThreshold, metricsw.distanceMinThreshold, metricsw.nb_vars, metricsw.overLearn, metricsw.true_positives, metricsw.false_positives, metricsw.true_negatives, metricsw.false_negatives, features_weights
|
a nested named list
pms <- params( nb_rules = 2, nb_max_var_per_rule = 3, rules.pop_size = 20, mfs.pop_size = 20, ivars.nb_sets = 3, ivars.nb_bits_vars = 3, ivars.nb_bits_sets = 2, ivars.nb_bits_pos = 8, ovars.nb_sets = 3, ovars.nb_bits_vars = 1, ovars.nb_bits_sets = 2, ovars.nb_bits_pos = 8, metricsw.sensitivity = 0, metricsw.specificity = 0, metricsw.rmse = 1, output_vars_defuzz_thresholds = list(3, 17) )pms <- params( nb_rules = 2, nb_max_var_per_rule = 3, rules.pop_size = 20, mfs.pop_size = 20, ivars.nb_sets = 3, ivars.nb_bits_vars = 3, ivars.nb_bits_sets = 2, ivars.nb_bits_pos = 8, ovars.nb_sets = 3, ovars.nb_bits_vars = 1, ovars.nb_bits_sets = 2, ovars.nb_bits_pos = 8, metricsw.sensitivity = 0, metricsw.specificity = 0, metricsw.rmse = 1, output_vars_defuzz_thresholds = list(3, 17) )
predict the outcome of a fuzzy system on some input data
predict_fuzzy_system(fs, x, verbose = FALSE)predict_fuzzy_system(fs, x, verbose = FALSE)
fs |
the fuzzy system to predict on (as a named list) |
x |
the input data to use with the fuzzy system to predict the output |
verbose |
whether to be verbose |
the predicted output data as a data frame
model <- fuzzycoco("regression", example_mtcars()$params, seed = 123) x <- mtcars[c("mpg", "hp", "wt")] y <- mtcars["qsec"] fit <- fit_xy(model, x, y, progress = FALSE) y2 <- predict_fuzzy_system(fit$fuzzy_system,x)model <- fuzzycoco("regression", example_mtcars()$params, seed = 123) x <- mtcars[c("mpg", "hp", "wt")] y <- mtcars["qsec"] fit <- fit_xy(model, x, y, progress = FALSE) y2 <- predict_fuzzy_system(fit$fuzzy_system,x)
N.B: just a S3 method method wrapping the predict_fuzzy_system() function
## S3 method for class 'fuzzycoco_fit' predict(object, x, verbose = FALSE, bin = TRUE, ...)## S3 method for class 'fuzzycoco_fit' predict(object, x, verbose = FALSE, bin = TRUE, ...)
object |
the fuzzycoco_fit object containing the fuzzy system to predict on |
x |
the input data to use with the fuzzy system to predict the output |
verbose |
whether to be verbose |
bin |
whether to transform the output data into a binary response. Only applies to classification models. |
... |
not used. Only for S3 generic consistency |
the predicted output data as a data frame
model <- fuzzycoco("regression", example_mtcars()$params, seed = 123) x <- mtcars[c("mpg", "hp", "wt")] y <- mtcars["qsec"] fit <- fit_xy(model, x, y, progress = FALSE) y2 <- predict(fit, x)model <- fuzzycoco("regression", example_mtcars()$params, seed = 123) x <- mtcars[c("mpg", "hp", "wt")] y <- mtcars["qsec"] fit <- fit_xy(model, x, y, progress = FALSE) y2 <- predict(fit, x)
an utility function to easily generate a stop function that stops when the convergence is stalling
stop_engine_if_stalling(nb_iterations)stop_engine_if_stalling(nb_iterations)
nb_iterations |
number of iterations of the stalling: stops if the fitness has not increased during that number of iterations. |
a function: (engine) –> logical that stops (i.e/ returns TRUE) if the convergence is stalling
until <- stop_engine_on_first_of(max_generations = 1000, other_func = stop_engine_if_stalling(5))until <- stop_engine_on_first_of(max_generations = 1000, other_func = stop_engine_if_stalling(5))
until parameter, as used by fuzzycoco_fit_df_hybrid()
an utility function to easily generate the commonly used until parameter, as used by fuzzycoco_fit_df_hybrid()
stop_engine_on_first_of( max_generations = NULL, max_fitness = NULL, other_func = NULL )stop_engine_on_first_of( max_generations = NULL, max_fitness = NULL, other_func = NULL )
max_generations |
The maximum number of iterations of the algorithm. Each iteration produces a new generation of the rules and membership functions populations. |
max_fitness |
a stop condition: the iterations stop as soon as a generated fuzzy system fitness reaches that threshold. |
other_func |
if not NULL, a function: (engine) –>logical that should return TRUE to stop the evolution
(cf |
a function: (engine) –> logical that stops (i.e/ returns TRUE) when the number of generations or the fitness
are reached, or when the other_func if provided returns TRUE
until <- stop_engine_on_first_of(max_generations = 100) until <- stop_engine_on_first_of(max_generations = 100, max_fitness = 0.8) until <- stop_engine_on_first_of(max_fitness = 0.9, other_func = stop_engine_if_stalling(5))until <- stop_engine_on_first_of(max_generations = 100) until <- stop_engine_on_first_of(max_generations = 100, max_fitness = 0.8) until <- stop_engine_on_first_of(max_fitness = 0.9, other_func = stop_engine_if_stalling(5))