I wrote a python function for particle filtering. I need to write a loop for the below function to save the best cost(Variable) for a csv file and get the average.
#loop should start here
pop_size=50
#128 to #135 loop
W = initial_population(region, scale , pop_size)
pop = PatternPosePopulation(W, pat)
pop.set_distance_image(imd)
pop.temperature = 5
Lw, Lc = pop.particle_filter_search(int(1000/pop_size),log=True)
#Loop should end here for example run pop 50 x n times and store best_cost, take average of bestcost save to csv file.
plt.plot(Lc)
plt.title('Cost vs generation index')
plt.show()
print(pop.best_w)
print(pop.best_cost)
Any help would be greatly appreciated.
This will write the best cost and the average to
results.csv
with;
as delimiter. For a more specific approach, more information would be needed...Edit: You're right, the writing to csv part should be after the loop