fza fzt vc lc Ra
1 0.50 0.10 40 emulsion 1.915556
2 1.25 0.10 40 emulsion 3.515556
3 0.50 0.20 40 emulsion 1.065556
4 1.25 0.20 40 emulsion 1.965556
5 0.50 0.15 20 emulsion 1.765556
6 1.25 0.15 20 emulsion 3.265556
MRR optimization subject to roughness constraint learning 1
Loading libraries, defining experimental design, and getting measurement results.
The same as done previously.
Cubist model
<-
normalized_rec recipe(Ra ~ ., data = plan_train) %>%
step_normalize(fza,fzt,vc) %>%
step_dummy(all_nominal_predictors())
<-
cubist_spec cubist_rules(committees = 78, neighbors = 7) %>%
set_engine("Cubist")
<-
cubist_wflow workflow() %>%
add_model(cubist_spec) %>%
add_recipe(normalized_rec)
<- fit(cubist_wflow, data = plan_train) cubist_final_fit
augment(cubist_final_fit, new_data = plan_test) %>%
rsq(truth = Ra, estimate = .pred)
# A tibble: 1 × 3
.metric .estimator .estimate
<chr> <chr> <dbl>
1 rsq standard 0.916
augment(cubist_final_fit, new_data = plan_test) %>%
rmse(truth = Ra, estimate = .pred)
# A tibble: 1 × 3
.metric .estimator .estimate
<chr> <chr> <dbl>
1 rmse standard 0.288
<- cubist(x = plan_train[,1:4],
cubist_fit y = plan_train$Ra,
committees = 78, neighbors = 7)
tidyRules(cubist_fit)
# A tibble: 78 × 9
id LHS RHS support mean min max error committee
<int> <chr> <chr> <int> <dbl> <dbl> <dbl> <dbl> <int>
1 1 <NA> (1.7705557) + (2.48 * … 30 2.36 0.866 4.72 0.402 1
2 2 <NA> (1.7705556) + (2.48 * … 30 2.36 0.866 4.72 0.402 2
3 3 <NA> (1.7705558) + (2.48 * … 30 2.36 0.866 4.72 0.402 3
4 4 <NA> (1.7705556) + (2.48 * … 30 2.36 0.866 4.72 0.402 4
5 5 <NA> (1.7705558) + (2.48 * … 30 2.36 0.866 4.72 0.402 5
6 6 <NA> (1.7705556) + (2.48 * … 30 2.36 0.866 4.72 0.402 6
7 7 <NA> (1.7705558) + (2.48 * … 30 2.36 0.866 4.72 0.402 7
8 8 <NA> (1.7705556) + (2.48 * … 30 2.36 0.866 4.72 0.402 8
9 9 <NA> (1.7705558) + (2.48 * … 30 2.36 0.866 4.72 0.402 9
10 10 <NA> (1.7705556) + (2.48 * … 30 2.36 0.866 4.72 0.402 10
# ℹ 68 more rows
Optimization of material removal rate with Ra contraint learning
First MRR function is defined.
<- function(x){
MRR
<- 2
z <- 25
Db <- 14
Dt <- Db-Dt
Dh
<- 250*z*(Db^3/(Dh*Dt))*x[3]*((x[1]*10^-3)/x[2])*sqrt((x[1]*10^-3)^2 + (x[2]*Dh/Db)^2)
f1
return(f1)
}
Writing Cubist constraint. Change lc ("emulsion"
or "mql"
) as desired.
<- function(x) {
g1 <- predict(cubist_final_fit, new_data = data.frame(fza = x[1],
g1 fzt = x[2],
vc = x[3],
lc = "emulsion")) - (2 - 0.4381)
return(g1)
}
Testing objective function and constraint.
<- c(0.875, 0.15, 40)
x_test MRR(x_test)
[1] 781.3187
g1(x_test)
.pred
1 0.4802455
Fitness function considering Objective function and penalty term regarding constraint.
<- function(x)
fitness
{ <- MRR(x)
f <- sqrt(.Machine$double.xmax) # penalty term
pen <- max(g1(x),0)*pen # penalisation for 1st inequality constraint
penalty1 - penalty1 # fitness function value
f }
Defining algorithims to the optimization.
<- c("ALO", "DA", "GWO", "MFO", "WOA")
ALGOS
# c("ABC", "ALO", "BA", "BHO", "CLONALG", "CS", "CSO", "DA", "DE", "FFA", "GA", "GBS", "GOA", "GWO", "HS", "KH", "MFO", "PSO", "SCA", "SFL", "WOA")
# Convergiram:
# "ABC", "ALO", "DA", "DE", "GWO", "MFO", "PSO", "WOA"
# Tempo satisfatorio entre os que convergiram:
# "ALO", "DA", "GWO", "MFO", "WOA"
Optimization.
result_meta
$result
var1 var2 var3
ALO 0.8657019 0.2 60.00000
DA 0.8657019 0.2 60.00000
GWO 0.8656254 0.2 59.98611
MFO 0.8657019 0.2 60.00000
WOA 0.8657018 0.2 60.00000
$optimumValue
optimum_value
ALO 1159.478
DA 1159.478
GWO 1159.107
MFO 1159.478
WOA 1159.478
$timeElapsed
user system elapsed
ALO 68.00 1.86 71.14
DA 70.67 1.75 72.98
GWO 64.83 1.67 67.06
MFO 58.75 1.65 60.44
WOA 60.79 1.66 63.02
Plotting MRR function
<- c(0.5, 1.25)
x1_range <- c(0.1, 0.2)
x2_range <- c(20, 60)
x3_range
<- seq(x1_range[1], x1_range[2], length.out = 50)
x1 <- seq(x2_range[1], x2_range[2], length.out = 50)
x2 <- seq(x3_range[1], x3_range[2], length.out = 50)
x3
<- array(0, dim = c(length(x1), length(x2), length(x3)))
z
for (i in 1:length(x1)) {
for (j in 1:length(x2)) {
for (k in 1:length(x3)) {
<- MRR(c(x1[i], x2[j], x3[k]))
z[i, j, k]
}
}
}
library(ggpubr)
library(reshape2)
Attaching package: 'reshape2'
The following object is masked from 'package:tidyr':
smiths
<- melt(z)
df colnames(df) <- c("x1", "x2", "x3", "z")
<- ggplot(df, aes(x = x1, y = x2, z = z)) +
contour_plot geom_tile(aes(fill=z)) +
scale_fill_distiller(palette = "RdBu",
direction = -1) +
geom_contour(color = "black") +
labs(x = "fza", y = "fzt", fill = "MRR") +
theme_bw() #+
# ggtitle("MRR(fza, fzt)")
<- ggplot(df, aes(x = x1, y = x3, z = z)) +
contour_plot2 geom_tile(aes(fill=z)) +
scale_fill_distiller(palette = "RdBu",
direction = -1) +
geom_contour(color = "black") +
labs(x = "fza", y = "vc", fill = "MRR") +
theme_bw() #+
# ggtitle("MRR(fza, vc)")
<- ggplot(df, aes(x = x2, y = x3, z = z)) +
contour_plot3 geom_tile(aes(fill=z)) +
scale_fill_distiller(palette = "RdBu",
direction = -1) +
geom_contour(color = "black") +
labs(x = "fzt", y = "vc", fill = "MRR") +
theme_bw() #+
# ggtitle("MRR(fzt, vc)")
ggarrange(contour_plot,contour_plot2,contour_plot3, common.legend = TRUE, nrow = 1)
plotting decision space with objective function and learned constraint
<- function(x) {
h_x_add_err <- as.numeric(predict(cubist_final_fit, new_data = data.frame(fza = x[1],
h fzt = x[2],
vc = x[3],
lc = "emulsion"))) - 2
return(h)
}
<- function(x3, x2) {
find_x1 <- 0.82
lower <- 1
upper
while (upper - lower > 1e-6) {
<- (lower + upper) / 2
mid <- g1(c(mid, x2, x3))
result
if (result == 0) {
return(mid)
else if (result < 0) {
} <- mid
lower else {
} <- mid
upper
}
}
return((lower + upper) / 2)
}
<- seq(20, 60, length = 200)
x3_values <- 0.200
x2 <- sapply(x3_values, find_x1, x2 = x2)
x1_values
<- data.frame(x1 = x1_values, x3 = x3_values) result_df
<- function(x3, x2) {
find_x1_ # Define um intervalo inicial para x1
<- 1
lower <- 1.2
upper
while (upper - lower > 1e-6) {
<- (lower + upper) / 2
mid <- h_x_add_err(c(mid, x2, x3))
result
if (result == 0) {
return(mid)
else if (result < 0) {
} <- mid
lower else {
} <- mid
upper
}
}
return((lower + upper) / 2)
}
<- sapply(x3_values, find_x1_, x2 = x2)
x1_values2
<- data.frame(x1 = x1_values2, x3 = x3_values)
result_df2
<- expand.grid(x1=x1,x3=x3)
xys <- data.frame(x1 = xys$x1,
xys x2 = 0.2,
x3 = xys$x3)
<- matrix(apply(xys,1,MRR), nrow = length(x1)) # previsao modelo MRR
zs2
contour(x=x1, y=x3, z=zs2, col = "royalblue3", # "#C71585",
labcex = 1, method = "edge",
xlab = "fza", ylab = "vc", lwd = 1.5)
lines(result_df, col = "red", lwd = 1.5)
lines(result_df2, col = "red", lty = 2, lwd = 1.5)
points(0.8657019, 60, pch = "*", col = "seagreen3", cex = 2)
legend(0.6, 34, legend=c("MRR"),
col=c("royalblue3"), lty=c(1), pch = c(NA),
cex = .8, box.lty=0)
legend(0.55, 30, legend=c("Ra = 2 - Err_T"),
col=c("red"), lty=c(1), pch = c(NA),
cex = .8, box.lty=0)
legend(0.55, 26, legend=c("Ra = 2"),
col=c("red"), lty=c(2), pch = c(NA),
cex = .8, box.lty=0)
legend(0.55, 22, legend=c("max{MRR}"),
col=c("seagreen3"), pch = c("*"),
cex = .8, box.lty=0)