# Exploring all combinations of parameters

I often need to explore a large parameter space, e.g. making dozens of plots using a range of parameters. This looks something like:

explore[a, b, c, d]

a = {1, 3, 6, 8, 9}
b = {"a", "b", "c"}
c = {2, 6}
d = {"X", "I", "k", "l"}


I then usually use n nested loops (4 in this case) to explore all combinations of parameters, and in each loop export a plot. I would suppose there is a more efficient, or at least a simpler way to code this. I tried Map, but would need more than one slot, and also Table, but could not fully reproduce exploring the entire parameter set.

• Do you mean something like explore @@@ Tuples[{a, b, c, d}]? Commented Jun 23, 2017 at 11:51
• That is not working. explore is a self written command, something like explore[a_, b_, c_, d_] := Module[{},], where a, b, c, d are parameters that are used in a longer and complex subprogram stored in module and executed using the explore command. Commented Jun 23, 2017 at 12:01
• That should give you a list of all the outputs obtained by feeding all possible combinations of those parameters into your explore function, whatever the specifics of that function might be. Do the parameters come from a discrete set, as in your example? Commented Jun 23, 2017 at 12:20
• That is beautiful! Working now. I just had to make some slight adjustments to values appearing only once, i.e. putting them into brackets. Thanks! Commented Jun 23, 2017 at 13:40

Tuples and Subsets and their associates are really handy when you're working with discrete sets. In your case:

a = {1, 3, 6, 8, 9};
b = {"a", "b", "c"};
c = {2, 6};
d = {"X", "I", "k", "l"};
explore @@@ Tuples[{a, b, c, d}]

(* Out= {explore[1, "a", 2, "X"], explore[1, "a", 2, "I"],... , explore[9, "c", 6, "l"]} *)


Depending on your explore function (i.e., if it takes a while and isn't already parallelized) and your actual parameters, you might also be able to speed things up with

Parallelize[explore @@@ Tuples[{a, b, c, d}], Method -> "FinestGrained"]


But probably not worth it if explore is fast already due to the overheads.

• Thanks – it is worth to parallelise, and I wouldn't have done it without your hint. Commented Jun 23, 2017 at 18:28