| 663 | return all_df, labels_df |
| 664 | |
| 665 | def load_single(self, filepath): |
| 666 | df, labels = load_from_tsfile_to_dataframe(filepath, return_separate_X_and_y=True, |
| 667 | replace_missing_vals_with='NaN') |
| 668 | labels = pd.Series(labels, dtype="category") |
| 669 | self.class_names = labels.cat.categories |
| 670 | labels_df = pd.DataFrame(labels.cat.codes, |
| 671 | dtype=np.int8) # int8-32 gives an error when using nn.CrossEntropyLoss |
| 672 | |
| 673 | lengths = df.applymap( |
| 674 | lambda x: len(x)).values # (num_samples, num_dimensions) array containing the length of each series |
| 675 | |
| 676 | horiz_diffs = np.abs(lengths - np.expand_dims(lengths[:, 0], -1)) |
| 677 | |
| 678 | if np.sum(horiz_diffs) > 0: # if any row (sample) has varying length across dimensions |
| 679 | df = df.applymap(subsample) |
| 680 | |
| 681 | lengths = df.applymap(lambda x: len(x)).values |
| 682 | vert_diffs = np.abs(lengths - np.expand_dims(lengths[0, :], 0)) |
| 683 | if np.sum(vert_diffs) > 0: # if any column (dimension) has varying length across samples |
| 684 | self.max_seq_len = int(np.max(lengths[:, 0])) |
| 685 | else: |
| 686 | self.max_seq_len = lengths[0, 0] |
| 687 | |
| 688 | # First create a (seq_len, feat_dim) dataframe for each sample, indexed by a single integer ("ID" of the sample) |
| 689 | # Then concatenate into a (num_samples * seq_len, feat_dim) dataframe, with multiple rows corresponding to the |
| 690 | # sample index (i.e. the same scheme as all datasets in this project) |
| 691 | |
| 692 | df = pd.concat((pd.DataFrame({col: df.loc[row, col] for col in df.columns}).reset_index(drop=True).set_index( |
| 693 | pd.Series(lengths[row, 0] * [row])) for row in range(df.shape[0])), axis=0) |
| 694 | |
| 695 | # Replace NaN values |
| 696 | grp = df.groupby(by=df.index) |
| 697 | df = grp.transform(interpolate_missing) |
| 698 | |
| 699 | return df, labels_df |
| 700 | |
| 701 | def instance_norm(self, case): |
| 702 | if self.root_path.count('EthanolConcentration') > 0: # special process for numerical stability |