Change this whole loop into function: Change this whole loop into a function:…
- User
Change this whole loop into function: Change this whole loop into a function: crossover_point<-7 population_size <- 100 num_generations <- 20000 tournament_size <- 2 probability<-0.09 penalty<-1 parents<-pop_init
global_best<-pop_init[1,] global_best_value<-target(global_best)
for (gen in 1:num_generations) {
parent_pop<- as.data.frame(matrix(NA, n_rows, length(position_vectors))) for(c in 1:(population_size)){ parent_pop[c,]<-tournament_selection (parents,t_size=2,penalty=penalty)
}
offspring_temp<- as.data.frame(matrix(NA, 1, length(position_vectors)))
for (c in seq(1, population_size, by = 2)){ parent1<-parent_pop[c,] parent2<-parent_pop[c+1,]
offsprings<-crossover(parent1, parent2,corssover_point) o1<-unlist(offsprings[1,]) o2<-unlist(offsprings[2,]) offspring_temp<-rbind(offspring_temp,o1) offspring_temp<-rbind(offspring_temp,o2)} offspring_temp <- offspring_temp[-1, ]
parents<- mutate(offspring_temp, position_vectors_list, probability=probability) row.names(parents) <- 1:population_size solutions<-apply(parents, 1, target) idx_sol<-which.min(solutions)[[1]] temp_best<-parents[idx_sol[[1]],] temp_target_value<-solutions[idx_sol[[1]]]
if(temp_target_value<=global_best_value){ global_best<-temp_best global_best_value<-temp_target_value
}
penalty<-penalty+0.5 if(penalty>=9){ penalty<-0 }
}
that returns : global_best_fin<-as.matrix(global_best,nrow=1) parent_data <- Data[global_best_fin, ]
target(global_best)
Now I want to iterate by num_generations from 1000:1000:50000 using parrallel processing and I also want to collect the results into a dataframe (in which I also need to know from which current num_generations the current output is).
- Assistant
- User
Do the same but for probability 0:0.05:1
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.