# Looking for a script that runs the same code with different set of parameters and saves the results in different folders

**URL:** https://discourse.julialang.org/t/looking-for-a-script-that-runs-the-same-code-with-different-set-of-parameters-and-saves-the-results-in-different-folders/35437
**Category:** Data
**Created:** [March 3, 2020, 1:47am UTC](https://discourse.julialang.org/t/looking-for-a-script-that-runs-the-same-code-with-different-set-of-parameters-and-saves-the-results-in-different-folders/35437 "2020-03-03T01:47:59Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Ujku\_KU](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ujku_ku/32/13159_2.png) [@Ujku\_KU](https://discourse.julialang.org/u/Ujku_KU)
#### Post date: [March 3, 2020, 1:47am UTC](https://discourse.julialang.org/t/looking-for-a-script-that-runs-the-same-code-with-different-set-of-parameters-and-saves-the-results-in-different-folders/35437/1 "2020-03-03T01:47:59Z")

</div>

Hi guys, I am running a set of experiments and each of experiment differs from the rest by the set of the parameters which are picked by the same pool of parameters. I would like to run the experiments in a loop automatically till all the possible sets of parameters run out. I also would like to save the results in different folders named after the set of the parameters used for that same experiment.

As I hate to reinvent the wheel, my question is if there exist any piece of code that does this and if not is it possible to give me some hints how you would have solved this problem.

I thank you in advance for your time and help.

Cheers.

Ergnoor

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [March 3, 2020, 2:01am UTC](https://discourse.julialang.org/t/looking-for-a-script-that-runs-the-same-code-with-different-set-of-parameters-and-saves-the-results-in-different-folders/35437/2 "2020-03-03T02:01:18Z")

</div>

[https://github.com/JuliaDynamics/DrWatson.jl](https://github.com/JuliaDynamics/DrWatson.jl)

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [March 3, 2020, 2:08am UTC](https://discourse.julialang.org/t/looking-for-a-script-that-runs-the-same-code-with-different-set-of-parameters-and-saves-the-results-in-different-folders/35437/3 "2020-03-03T02:08:23Z")

</div>

You have a extremely vague description of what you are looking for. Each sentence in the first paragraph is basicallly literally one line of code, saving the complex part that you didn’t mention. (In another word, you basicallly said you want to write a loop and save data to files).

You won’t be reinventing any wheels if that’s exactly what you need. If you have any other requirements then that’ll be time to see what others do.

---

<div class="post-metadata">

### Author: ![Ujku\_KU](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ujku_ku/32/13159_2.png) [@Ujku\_KU](https://discourse.julialang.org/u/Ujku_KU)
#### Post date: [March 3, 2020, 7:10am UTC](https://discourse.julialang.org/t/looking-for-a-script-that-runs-the-same-code-with-different-set-of-parameters-and-saves-the-results-in-different-folders/35437/4 "2020-03-03T07:10:40Z")

</div>

hi guys and thank you very much for your time and attention payed to my problem. Following I am giving a NOT working piece of code extracted from my not looping code that I intend to convert into looping one.

```julia
abstract type Metric end

struct Euclidean <: Metric end

struct PowerEuclidean <: Metric
    α::Int64
end

function (covMat::Euclidean)(covA::AbstractVecOrMat{<: Number}, covB::AbstractVecOrMat{<: Number})
    distance = sum(log.(F.values).^2)
end

function (covMat::PowerEuclidean)(covA::AbstractVecOrMat{<: Number}, covB::AbstractVecOrMat{<: Number})
    α = covMat.α
    PEcovA = covA^α
    PEcovB = covB^α
    distance = (1/α) * norm(PEcovA - PEcovB, 2)
end

function calFeatFunction(img::AbstractVecOrMat, featParam::whateverWillBeThisObject)
     imHeight, imWidth = size(img[:, :, iN])
     x = repeat(collect(1:imHeight), outer = (1,imWidth))
     y = repeat(transpose(collect(1:imHeight)), outer = (imHeight,1))
     Gy, Gx = imgradients(Gray.(img[:, :, iN]), KernelFactors.ando3)
     angles = atan.(Gy, Gx) * (180/π)
     magnitudes = sqrt.(Gy.^2 + Gx.^2)

     return angles, magnitude # suppose I am returning these two features
end

distSetParams = (Euclidean, PowerEuclidean) # what type of object is suitable to contain this set of metrics? 
featSetParams = (x, y, Gy, Gx, angles, magnitudes) # what type of object is suitable to contain this set of features?

for distParam in distSetParams # supose 'distParam' is "PowerEuclidean", here it is alright to select only one distance
    for featParam in featSetParams # I need to be able to select more than one feat here, supose we selected "angles" and "magnitude"
        calFeats = calFeatFunction(img, featParam)
	result = myFunction(img, calFeats, distParam()) # here the problem is that 'distParam' could be even 'distParam(α)'

	# save result in a folder with name in this case "PowerEuclidean_angles_magnitudes"
	# how to do this part?
    end
end 

```

Notice that I have asked the questions next to the relevant parts of the code itself.

I again thank you guys for your time and support.

Cheers.

Ergnoor

---

<div class="post-metadata">

### Author: ![orialb](https://avatars.discourse-cdn.com/v4/letter/o/65b543/32.png) [@orialb](https://discourse.julialang.org/u/orialb)
#### Post date: [March 3, 2020, 8:26am UTC](https://discourse.julialang.org/t/looking-for-a-script-that-runs-the-same-code-with-different-set-of-parameters-and-saves-the-results-in-different-folders/35437/5 "2020-03-03T08:26:15Z")

</div>

I’m not sure exactly in which part you are having trouble, but let me give you a few hints.

For iterating over a bunch of parameter lists you could either write a nested for loop `for p1 in p1_list, p2 in p2_list, p3 in p3_list` (which is basically what you already did) or you could use `Iterators.product(p1_list,p2_list,p3_list)`.

For generating the folder name you can use string interpolation `folder_name="my_awesome_experiment_p1_$(p1)_p2_$(p2)_p3_$(p3)"`, then you can create the folder with `mkdir`. You might want to use `$(float(p1))` instead to make sure that `p1=1` and `p1=1.0` end up in the same folder. Alternatively take a look at the DrWinston.jl package as suggested above whose purpose is to help with organizing experiments, data and projects.

---

<div class="post-metadata">

### Author: ![Ujku\_KU](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ujku_ku/32/13159_2.png) [@Ujku\_KU](https://discourse.julialang.org/u/Ujku_KU)
#### Post date: [March 4, 2020, 2:10am UTC](https://discourse.julialang.org/t/looking-for-a-script-that-runs-the-same-code-with-different-set-of-parameters-and-saves-the-results-in-different-folders/35437/6 "2020-03-04T02:10:41Z")

</div>

@orialb Hi orialb and thank you for your help. Now that I have explored a little bit the area related to my problems I know that I can do the following with tuples of arguments of a function:

```julia
julia> myTupleOne = (7)
7

julia> myTupleTwo = (4, 6, 3)
(4, 6, 3)

julia> F(a, b, c, d, e, h, j, k) = +(a, b, c, d, e, h, j, k)
F (generic function with 1 method)

julia> F(5, myTupleOne..., 4, 8, myTupleTwo..., 9)
46

```

I also know that there is this ` Combinatorics.jl` that is able to generate the Powerset of a vector. My question here is if there exists any package similar to ` Combinatorics.jl` that generates the Powerset of a tuple, for example:

```julia
julia> myTuple = (1, 2, 3)
(1, 2, 3)
julia> tuplePowerset(myTuple)
(1, 2, 3, (1, 2), (1, 3), (2, 3))

```

The other problem for me is the following

```julia
result = myFunction(img, calFeats, distParam()) # here the problem is that 'distParam' could be even 'distParam(α)'

```

how would you have managed this situation?

Thank you very much for your time and support.

Cheers.

Ergnoor

---

<div class="post-metadata">

### Author: ![orialb](https://avatars.discourse-cdn.com/v4/letter/o/65b543/32.png) [@orialb](https://discourse.julialang.org/u/orialb)
#### Post date: [March 4, 2020, 10:12am UTC](https://discourse.julialang.org/t/looking-for-a-script-that-runs-the-same-code-with-different-set-of-parameters-and-saves-the-results-in-different-folders/35437/7 "2020-03-04T10:12:06Z")

</div>

I have never used `Combinatorics.jl`, but I am guessing that if the function you are talking about works for an array it should also work for a tuple. Did you try just passing the tuple?

I don’t understand what is the other problem you are referring to.

---

<div class="post-metadata">

### Author: ![Ujku\_KU](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ujku_ku/32/13159_2.png) [@Ujku\_KU](https://discourse.julialang.org/u/Ujku_KU)
#### Post date: [March 5, 2020, 1:38am UTC](https://discourse.julialang.org/t/looking-for-a-script-that-runs-the-same-code-with-different-set-of-parameters-and-saves-the-results-in-different-folders/35437/8 "2020-03-05T01:38:41Z")

</div>

@ararslan

Hi Alex, I hope this message will not bother you.

I have seen that you dealt with the powerset function in Combinatorics.jl.

My question is if it possible to build a powerset function for some tuple?

You see I have a tuple of features and I would like to get the powerset of subtuples of that tuple in order to run experiments with all possible combinations of those features.

Thank you very much in advance for your time and support.

Cheers.

Ergnoor
