SimplifiedTimeSeriesLoader { @SuppressWarnings("unchecked") public static Pair<TimeSeriesDataset2, ClassMapper> loadArffs(final File... arffFiles) throws TimeSeriesLoadingException { if (arffFiles == null) { throw new IllegalArgumentException("Parameter 'arffFiles' must not be null!"); } final List<double[][]> matrices = new ArrayList<>(); int[] target = null; List<String> classNames = null; for (final File arffFile : arffFiles) { Object[] tsTargetClassNames = loadTimeSeriesWithTargetFromArffFile(arffFile); if (classNames == null && tsTargetClassNames[2] != null) { classNames = (List<String>) tsTargetClassNames[2]; } else { List<String> furtherClassNames = (List<String>) tsTargetClassNames[2]; if ((classNames != null && furtherClassNames == null) || (furtherClassNames != null && !furtherClassNames.equals(classNames))) { throw new TimeSeriesLoadingException("Could not load multivariate time series with different targets. Target values have to be stored in each " + "time series arff file and must be equal!"); } } if (target == null) { target = (int[]) tsTargetClassNames[1]; } else { int[] furtherTarget = (int[]) tsTargetClassNames[1]; if (furtherTarget == null || target.length != furtherTarget.length || !Arrays.equals(target, furtherTarget)) { throw new TimeSeriesLoadingException("Could not load multivariate time series with different targets. Target values have to be stored in each " + "time series arff file and must be equal!"); } } if (!matrices.isEmpty() && ((double[][]) tsTargetClassNames[0]).length != matrices.get(0).length) { throw new TimeSeriesLoadingException("All time series must have the same first dimensionality (number of instances)."); } matrices.add((double[][]) tsTargetClassNames[0]); } ClassMapper cm = null; if (classNames != null) { cm = new ClassMapper(classNames); } return new Pair<>(new TimeSeriesDataset2(matrices, new ArrayList<>(), target), cm); } private  SimplifiedTimeSeriesLoader(); @SuppressWarnings("unchecked") static Pair<TimeSeriesDataset2, ClassMapper> loadArff(final File arffFile); @SuppressWarnings("unchecked") static Pair<TimeSeriesDataset2, ClassMapper> loadArffs(final File... arffFiles); static int countFileLines(final File file); static final String DEFAULT_CHARSET; }
@Test public void testMultivariateArffFileLoading() throws TimeSeriesLoadingException { File datasetFile0 = new File(TSC_DATASET_PATH_PREFIX + "multivariate" + File.separator + "Libras" + File.separator + "LibrasDimension1_TRAIN.arff"); File datasetFile1 = new File(TSC_DATASET_PATH_PREFIX + "multivariate" + File.separator + "Libras" + File.separator + "LibrasDimension2_TRAIN.arff"); final Pair<TimeSeriesDataset2, ClassMapper> pairResult = SimplifiedTimeSeriesLoader.loadArffs(datasetFile0, datasetFile1); TimeSeriesDataset2 result = pairResult.getX(); final int expectedNumInstances = 180; final int expectedNumSteps = 45; final int expectedNumVariables = 2; final int expectedNumTargets = 180; assertEquals(expectedNumInstances, result.getNumberOfInstances()); assertEquals(expectedNumSteps, result.getValues(0)[0].length); assertEquals(expectedNumVariables, result.getNumberOfVariables()); assertEquals(expectedNumTargets, result.getTargets().length); }
@Test public void testMultivariateArffFileLoadingStringClass() throws TimeSeriesLoadingException { File datasetFile0 = new File(TSC_DATASET_PATH_PREFIX + "multivariate" + File.separator + "FingerMovements" + File.separator + "FingerMovementsDimension1_TRAIN.arff"); File datasetFile1 = new File(TSC_DATASET_PATH_PREFIX + "multivariate" + File.separator + "FingerMovements" + File.separator + "FingerMovementsDimension2_TRAIN.arff"); final Pair<TimeSeriesDataset2, ClassMapper> pairResult = SimplifiedTimeSeriesLoader.loadArffs(datasetFile0, datasetFile1); TimeSeriesDataset2 result = pairResult.getX(); final int expectedNumInstances = 316; final int expectedNumSteps = 50; final int expectedNumVariables = 2; final int expectedNumTargets = 316; final List<String> expectedClassDomain = Arrays.asList("left", "right"); assertEquals(expectedNumInstances, result.getNumberOfInstances()); assertEquals(expectedNumSteps, result.getValues(0)[0].length); assertEquals(expectedNumVariables, result.getNumberOfVariables()); assertEquals(expectedNumTargets, result.getTargets().length); assertEquals(expectedClassDomain, pairResult.getY().getClassValues()); }