Skip to content

Cannot reshape array of size 0 into shape (0,newaxis)

Description

The error cannot reshape array of size 0 into shape (0,newaxis) shows up when trying to execute the following config on cartpole.

name           | predicates        | determinize   | impurity   | safe-pruning
----------------+-------------------+---------------+------------+----------------
another-config | ['linear-logreg'] | minnorm       | entropy    | False

On investigation, it turns out that the check_done(dataset.x, y) on line 120 of decision_tree.py is being called with both parameters being the empty list.

Stacktrace

Traceback (most recent call last):
  File "./dtcontrol/dtcontrol/benchmark_suite.py", line 95, in benchmark
    cell, computed = self.compute_cell(ds, classifier)
  File "./dtcontrol/dtcontrol/benchmark_suite.py", line 132, in compute_cell
    cell = self.train_and_get_cell(dataset, classifier)
  File "./dtcontrol/dtcontrol/benchmark_suite.py", line 141, in train_and_get_cell
    classifier, success, run_time = call_with_timeout(classifier, 'fit', dataset, timeout=self.timeout)
  File "./dtcontrol/dtcontrol/timeout.py", line 51, in call_with_timeout
    getattr(obj, method)(*args)
  File "./dtcontrol/dtcontrol/decision_tree/decision_tree.py", line 46, in fit
    self.root.fit(dataset)
  File "./dtcontrol/dtcontrol/decision_tree/decision_tree.py", line 133, in fit
    node.fit(subset)
  File "./dtcontrol/dtcontrol/decision_tree/decision_tree.py", line 133, in fit
    node.fit(subset)
  File "./dtcontrol/dtcontrol/decision_tree/decision_tree.py", line 133, in fit
    node.fit(subset)
  [Previous line repeated 20 more times]
  File "./dtcontrol/dtcontrol/decision_tree/decision_tree.py", line 120, in fit
    if self.check_done(dataset.x, y):
  File "./dtcontrol/dtcontrol/decision_tree/decision_tree.py", line 147, in check_done
    unique_data = np.unique(x, axis=0)
  File "<__array_function__ internals>", line 6, in unique
  File "./dtcontrol/venv/lib/python3.7/site-packages/numpy/lib/arraysetops.py", line 275, in unique
    ar = ar.reshape(orig_shape[0], -1)
ValueError: cannot reshape array of size 0 into shape (0,newaxis)

Reproducibility

First run python cli.py preset --sample > ../user-config.yml from inside the dtcontrol folder to create a user-config.yml file in the root. Then run python cli.py --input ../examples/cartpole.scs --use-preset another-config --config ../user-config.yml.