@Override
    public List<Double> untransform(List<Double> in) {
        if (in.size() != template.getNumCols()) {
            throw new MLException(String.format(
                    "Unexpected in-vector size. Expected %d, Got: %d", template.getNumCols(), in.size()));
        }
        List<Double> out = new ArrayList<Double>();
        int inStart = 0;
        for (int i = 0; i < values.size(); i++) {
            if  (values.get(i) == 1) {
                out.add(in.get(inStart++));
            } else {
                int startPos = inStart;
                int maxIndex = 0;
                for (int j = 1; j < values.get(i); j++) {
                    if (in.get(inStart) > in.get(startPos + maxIndex)) {
                        maxIndex = inStart - startPos;
                    }
                    inStart++;
                }
                out.add((double) maxIndex);
            }
        }
        return out;
    }