Closed abbgrade closed 10 years ago
I like the concept, but can you show me an example of how you would use this, just so I can understand what your end goal is?
here is a snippet
import cStringIO as string_io
evolution.observer = inspyred.ec.observers.file_observer
statistics_file = string_io.StringIO()
individuals_file = string_io.StringIO()
final_population = evolution.evolve(
generator=problem.generator,
evaluator=problem.evaluator,
pop_size=500,
bounder=problem.bounder,
maximize=problem.maximize,
max_evaluations=5000,
statistics_file=statistics_file,
individuals_file=individuals_file
)
statistics_file.seek(0)
individuals_file.seek(0)
inspyred.ec.analysis.generation_plot(file=statistics_file)
inspyred.ec.analysis.allele_plot(file=individuals_file)
OK. In that case, it seems like a better approach would be just to change the "filename" parameter to instead be "file" and act as a file-like object. The client code would just have to make sure that they pass the already-opened file to the plot functions, if they save the data in an actual disk file.
How do you feel about that change? Does it have any issues that you can see? (It slightly changes the way those few functions accept parameters, which would make it not backward compatible to older code, but I'm not all that concerned about that if it makes the system cleaner, overall.)
Cleaner is better! ;)
It think, it is not so complex to call open outside if it is required.
I made the changes in the current version of the repo. Thanks for the suggestion.
now the file_overser can write into an StringIO, which can be passed to the analysis function