lynn-miller commited on
Commit
c1362c7
·
verified ·
1 Parent(s): cbb75e2

Upload 3 files

Browse files
Files changed (3) hide show
  1. WISDM.py +181 -0
  2. WISDM_X.npy +3 -0
  3. WISDM_y.npy +3 -0
WISDM.py ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # TODO: Address all TODOs and remove all explanatory comments
15
+ """TODO: Add a description here."""
16
+
17
+
18
+ import numpy as np
19
+ #import json
20
+ import os
21
+
22
+ import datasets
23
+
24
+
25
+ # TODO: Add BibTeX citation
26
+ # Find for instance the citation on arxiv or on the dataset repo/website
27
+ _CITATION = """\
28
+ @InProceedings{huggingface:dataset,
29
+ title = {A great new dataset},
30
+ author={huggingface, Inc.
31
+ },
32
+ year={2020}
33
+ }
34
+ """
35
+
36
+ # TODO: Add description of the dataset here
37
+ # You can copy an official description
38
+ _DATASET = "WISDM"
39
+ _DESCRIPTION = """\
40
+ This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
41
+ """
42
+
43
+ # TODO: Add a link to an official homepage for the dataset here
44
+ _HOMEPAGE = ""
45
+
46
+ # TODO: Add the licence for the dataset here if you can find it
47
+ _LICENSE = ""
48
+
49
+ # TODO: Add link to the official dataset URLs here
50
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
51
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
52
+ _URL = [f"https://huggingface.co/datasets/lynn-miller/{_DATASET}"]
53
+
54
+
55
+ # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
56
+ class Monster(datasets.GeneratorBasedBuilder):
57
+ """TODO: Short description of my dataset."""
58
+
59
+ VERSION = datasets.Version("1.1.0")
60
+
61
+ # This is an example of a dataset with multiple configurations.
62
+ # If you don't want/need to define several sub-sets in your dataset,
63
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
64
+
65
+ # If you need to make complex sub-parts in the datasets with configurable options
66
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
67
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
68
+
69
+ # You will be able to load one or the other configurations in the following list with
70
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
71
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
72
+ BUILDER_CONFIGS = [
73
+ datasets.BuilderConfig(name="full", version=VERSION, description="All data"),
74
+ datasets.BuilderConfig(name="fold_0", version=VERSION, description="Cross-validation fold 0"),
75
+ datasets.BuilderConfig(name="fold_1", version=VERSION, description="Cross-validation fold 1"),
76
+ datasets.BuilderConfig(name="fold_2", version=VERSION, description="Cross-validation fold 2"),
77
+ datasets.BuilderConfig(name="fold_3", version=VERSION, description="Cross-validation fold 3"),
78
+ datasets.BuilderConfig(name="fold_4", version=VERSION, description="Cross-validation fold 4"),
79
+ ]
80
+
81
+ DEFAULT_CONFIG_NAME = "full" # It's not mandatory to have a default configuration. Just use one if it make sense.
82
+
83
+ def _info(self):
84
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
85
+ data_dir = f"G:\My Drive\Postdoc\Other papers\Time Series Archive\{_DATASET}"
86
+ metadata_file = os.path.join(data_dir, "metadata", f"{_DATASET}_metadata.txt")
87
+ try:
88
+ metadata = np.loadtxt(metadata_file, delimiter=',', dtype=str)
89
+ shape = (int(metadata[1,1]), int(metadata[2,1]))
90
+ print(shape)
91
+ except:
92
+ print("Error reading metadata")
93
+ shape = (3, 100)
94
+ features = datasets.Features(
95
+ {
96
+ "X": datasets.Array2D(shape, "float32"),
97
+ "y": datasets.Value("int64")
98
+ # These are the features of your dataset like images, labels ...
99
+ }
100
+ )
101
+ return datasets.DatasetInfo(
102
+ # This is the description that will appear on the datasets page.
103
+ description=_DESCRIPTION,
104
+ # This defines the different columns of the dataset and their types
105
+ features=features, # Here we define them above because they are different between the two configurations
106
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
107
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
108
+ # supervised_keys=("sentence", "label"),
109
+ # Homepage of the dataset for documentation
110
+ homepage=_HOMEPAGE,
111
+ # License for the dataset if available
112
+ license=_LICENSE,
113
+ # Citation for the dataset
114
+ citation=_CITATION,
115
+ )
116
+
117
+ def _split_generators(self, dl_manager):
118
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
119
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
120
+
121
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
122
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
123
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
124
+ # urls = _URLS[self.config.name]
125
+ # data_dir = f"G:\My Drive\Postdoc\Other papers\Time Series Archive\{_DATASET}"
126
+ data_dir = dl_manager.download_and_extract(_URL)
127
+ if self.config.name == "full":
128
+ return [
129
+ datasets.SplitGenerator(
130
+ name=datasets.Split.TRAIN,
131
+ # These kwargs will be passed to _generate_examples
132
+ gen_kwargs={
133
+ "filepath": data_dir,
134
+ "fold": self.config.name,
135
+ "split": "train",
136
+ },
137
+ ),
138
+ ]
139
+ else:
140
+ return [
141
+ datasets.SplitGenerator(
142
+ name=datasets.Split.TRAIN,
143
+ # These kwargs will be passed to _generate_examples
144
+ gen_kwargs={
145
+ "filepath": data_dir,
146
+ "fold": self.config.name,
147
+ "split": "train",
148
+ },
149
+ ),
150
+ datasets.SplitGenerator(
151
+ name=datasets.Split.TEST,
152
+ # These kwargs will be passed to _generate_examples
153
+ gen_kwargs={
154
+ "filepath": data_dir,
155
+ "fold": self.config.name,
156
+ "split": "test"
157
+ },
158
+ ),
159
+ ]
160
+
161
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
162
+ def _generate_examples(self, filepath, fold, split):
163
+ # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
164
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
165
+ X_file = os.path.join(filepath, f'{_DATASET}_X.npy')
166
+ y_file = os.path.join(filepath, f'{_DATASET}_y.npy')
167
+ X = np.load(X_file) #, 'r')
168
+ y = np.load(y_file) #, 'r')
169
+ if self.config.name == "full":
170
+ for row in range(y.shape[0]):
171
+ yield(row, {"X": X[row], "y": y[row]})
172
+ else:
173
+ indices_file = os.path.join(filepath, f"test_indices_{fold}.txt")
174
+ test_indices = np.loadtxt(indices_file, dtype='int')
175
+ if split == "test":
176
+ for row in test_indices:
177
+ yield(int(row), {"X": X[row], "y": y[row]})
178
+ elif split == "train":
179
+ train_indices = np.delete(np.arange(y.shape[0]), test_indices)
180
+ for row in train_indices:
181
+ yield(int(row), {"X": X[row], "y": y[row]})
WISDM_X.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:108172943dfa0eff97861023a674a9809fabf945ec24bd6898d9abdba60e2867
3
+ size 20599328
WISDM_y.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dd54a11c42b598106d8d8a9469bdd6d1bc22692e0bcffd06c30cfed93d9ca9b9
3
+ size 137456