View source: R/simulated_annealing_MI.R
| simulated_annealing_MI | R Documentation | 
This function performs simulated annealing to optimize a given objective (entropy, mutual information, etc.) using a given table modification function. The optimization stops once the target entropy is reached or after a maximum number of iterations.
simulated_annealing_MI(
  initial_table,
  obj,
  gen_fn,
  target,
  max_n = 5000,
  temp = 10,
  maxim = TRUE,
  readj = FALSE
)
| initial_table | A contingency table to start the optimization. | 
| obj | An objective function that calculates the value to be optimized (e.g., entropy, mutual information). | 
| gen_fn | A function that generates a new table based on the current table. | 
| target | The target value for the objective function (e.g., target entropy). | 
| max_n | The maximum number of iterations to run the algorithm (default is 5000). | 
| temp | The initial temperature for the simulated annealing process (default is 10). | 
| maxim | Logical: Should the algorithm maximize (TRUE) or minimize (FALSE) the objective function (default is TRUE). | 
| readj | Logical: If TRUE, the algorithm is in a readjusting state (default is FALSE). | 
A list containing:
best: The best table found during the optimization process.
best_eval: The best evaluation value (objective function value).
n: The number of iterations completed.
mutual_info_history: A data frame with the history of mutual information values (or objective function values)
during each iteration.
# Example of using simulated annealing for entropy maximization:
initial_table <- matrix(c(5, 3, 4, 2), nrow = 2, ncol = 2)
obj <- entropy_pair  # Example entropy function
gen_fn <- gen_number_max  # Example generation function
target <- 0.5
result <- simulated_annealing_MI(initial_table, obj, gen_fn, target)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.