When using Sacred
it is necessary to pass all variables from the experiment config, into the main function, for example
ex = Experiment('iris_rbf_svm')
@ex.config
def cfg():
C = 1.0
gamma = 0.7
@ex.automain
def run(C, gamma):
iris = datasets.load_iris()
per = permutation(iris.target.size)
iris.data = iris.data[per]
iris.target = iris.target[per]
clf = svm.SVC(C, 'rbf', gamma=gamma)
clf.fit(iris.data[:90],
iris.target[:90])
return clf.score(iris.data[90:],
iris.target[90:])
As you can see, in this experiment there are 2 variables, C
and gamma
, and they are passed into the main function.
In real scenarios, there are dozens of experiment variables, and the passing all of them into the main function gets really cluttered. Is there a way to pass them all as a dictionary? Or maybe as an object with attributes?
A good solution will result in something like follows:
@ex.automain
def run(config):
config.C # Option 1
config['C'] # Option 2