0

I need to run svm-light and test different parameters to generate model and OUT files.

Example of my command line (-t, -g, -j and -c are my parameters; t is always 2; g/j/c to be tested with different values):

svm_learn -t 2 -g ? -j ? -c ? inputfile1 model1 > OUT1

I would like to test the parameters g/j/c (all possible combinations):

g=(0.1, 0.01, 0.001, 0.0001, 0.00001, 1, 10)
c=(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 25, 50, 100)
j=(1, 2, 3)

How can I create a loop to test all these different parameters/combinations?

I tried this, but I got just 6 combinations (0.0001-4/0.001-3/0.01-2/0.1-1/10-6/1-5):

#!/bin/sh
var1="0.1 0.01 0.001 0.0001 1 10"
var2="1 2 3 4 5 6 7 8 9 10 15 25 50 100"

set -- $var2
for i in $var1
do
    svm_learn -t 2 -g $i -c $1 trainingset1 model1-${i}-${1} > OUT1-${i}-${1}
    shift
done

1 Answer 1

1

Use nested loops:

gs=(0.1 0.01 0.001 0.0001 0.00001 1 10)
cs=(1 2 3 4 5 6 7 8 9 10 15 25 50 100)
js=(1 2 3)


for g in "${gs[@]}"
do
  for c in "${cs[@]}"
  do
    for j in "${js[@]}"
    do 
      svm_learn -t 2 -g "$g" -j "$j" -c "$c" ...
    done
  done
done

Or even just:

for g in 0.1 0.01 0.001 0.0001 0.00001 1 10
do
  for c in 1 2 3 4 5 6 7 8 9 10 15 25 50 100
  do
    for j in 1 2 3
    do 
      svm_learn -t 2 -g "$g" -j "$j" -c "$c" ...
    done
  done
done
1
  • great solution. thanks
    – Alex
    May 27, 2020 at 15:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .