This script will help you run grid search on any python script.
multiprocessing, numpy, csv
Your code should include the following elements:
- A main file which accepts arguments with argparse. Let's call is
main.py. - A function to compile the data returned by
main.py, let's call itcompile_func. This function should be able to take the data points iteratively. You'd have to call this frommain.py. A simple function called is already provided and can be imported asfrom grid_search import insert_to_csv.
It it best to open dummy_run.py as the library is quite intuitive and simple to run. You can use this file as your template.
- Import the library
from grid_search import GridSearch - Set name of main file,
main_file = 'dummy_main.py' - Create a function for compiling result. I am importing the
compile_csvfunction fromgrid_search. I am calling this from within mydummy_main.pyfile which saves the result of every run in a csv file. - Define arguments for running grid search:
- For every parameter you'd need one key containing it's name
- Each key can either be a list of all values of that parameter
- Or each key can be a dictionary with keys {'min', 'max', 'num', 'scale'} if you wish to uniformly choose values in a range. 'scale' can be 'linear' or 'log'. For log scale 'min' and 'max' should be the powers of 10. Eg. for 1e-1 to 1e3, 'min'=-1 and 'max'=3
- Create an object of
GridSearch.myGridSearch = GridSearch(main_file, compile_func, args, num_process=2) - Run grid search with
myGridSearch.run()