Using SKlean decision tree in scenic

Is it possible to give python arguments to a scenic simulation, such as a decision tree from the SKlearn library, and then make a behavior dependent on the prediction from the decision tree?

If you are running Scenic from inside a Python file (i.e. using a function like scenarioFromFile()), you can pass the decision tree as a global parameter, which you can retrieve inside the Scenic file.

Example:

dt.py:

decision_tree = sklearn.tree.DecisionTreeClassifier()
params = {'decision_tree':decision_tree}
scenario = scenic.scenarioFromFile('your_file.scenic', params=params)

your_file.scenic:

decision_tree = globalParameters['decision_tree']

Then you can pass that variable into a behavior.

You could also just import sklearn and train the decision tree inside the Scenic file, as if it is Python. But I’m assuming the above method is closer to what you wanted.

Thank you very much!