# Getting the Taxus baccata forests data set
data(taxus_bin)
# Removing taxa occurring in only one relevé in order to
# reproduce the example in the original article of the data set
taxus_bin_wmt <- taxus_bin[rowSums(taxus_bin) > 1, ]
# Obtaining a partition that maximizes TDV using the Simulated Annealing
# algorithm
result <- optim_tdv_simul_anne(
m_bin = taxus_bin_wmt,
k = 3,
p_initial = "random",
n_runs = 5,
n_sol = 5,
use_grasp = FALSE,
full_output = TRUE
)
# Inspect the result
# The TDV of each run
sapply(result[["SANN"]], function(x) x$tdv)
# The best partition that was found (i.e., with highest TDV)
result[["SANN"]][[1]]$par
# A TDV of 0.1958471 indicates you are probably reproducing the three
# groups (Estrela, Gerês and Galicia) from the original article. A solution
# with TDV = 0.2005789 might also occur, but note that one group has only two
# elements. For now, a minimum group size is not implemented in function
# optim_tdv_simul_anne() as it is in the function optim_tdv_hill_climb().
# Inspect how the optimization progressed (should increase towards the right)
plot(
result[["SANN"]][[1]]$current.tdv,
type = "l",
xlab = "Iteration number",
ylab = "TDV of the currently accepted solution"
)
for (run in 2:length(result[["SANN"]])) {
lines(result[["SANN"]][[run]]$current.tdv)
}
# Plot the sorted (or tabulated) phytosociological table, using the best
# partition that was found
tabul <- tabulation(
m_bin = taxus_bin_wmt,
p = result[["SANN"]][[1]]$par,
taxa_names = rownames(taxus_bin_wmt),
plot_im = "normal"
)
Run the code above in your browser using DataLab