Datasets:
Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +11 -0
- WISDM-dataset-description.pdf +3 -0
- wisdm-dataset/.activity_key.txt.swp +0 -0
- wisdm-dataset/README.txt +107 -0
- wisdm-dataset/WISDM-dataset-description.pdf +3 -0
- wisdm-dataset/activity_key.txt +19 -0
- wisdm-dataset/arff_files/.DS_Store +0 -0
- wisdm-dataset/arff_files/phone/.DS_Store +0 -0
- wisdm-dataset/arff_files/phone/gyro/data_1615_gyro_phone.arff +0 -0
- wisdm-dataset/arff_files/phone/gyro/data_1628_gyro_phone.arff +0 -0
- wisdm-dataset/arffmagic-master/.DS_Store +0 -0
- wisdm-dataset/arffmagic-master/Makefile +33 -0
- wisdm-dataset/arffmagic-master/README.md +1 -0
- wisdm-dataset/arffmagic-master/bin/.DS_Store +0 -0
- wisdm-dataset/arffmagic-master/bin/arffmagic +3 -0
- wisdm-dataset/arffmagic-master/bin/arffmagic.dSYM/Contents/Info.plist +20 -0
- wisdm-dataset/arffmagic-master/bin/arffmagic.dSYM/Contents/Resources/DWARF/arffmagic +3 -0
- wisdm-dataset/arffmagic-master/bin/magic +3 -0
- wisdm-dataset/arffmagic-master/build/arff.o +3 -0
- wisdm-dataset/arffmagic-master/build/attribute.o +3 -0
- wisdm-dataset/arffmagic-master/build/chunk.o +0 -0
- wisdm-dataset/arffmagic-master/build/funcmap.o +3 -0
- wisdm-dataset/arffmagic-master/build/globals.o +0 -0
- wisdm-dataset/arffmagic-master/build/libmfcc.o +0 -0
- wisdm-dataset/arffmagic-master/build/main.o +3 -0
- wisdm-dataset/arffmagic-master/build/raw.o +0 -0
- wisdm-dataset/arffmagic-master/build/read.o +3 -0
- wisdm-dataset/arffmagic-master/build/write.o +3 -0
- wisdm-dataset/arffmagic-master/src/arff.cpp +40 -0
- wisdm-dataset/arffmagic-master/src/arff.h +25 -0
- wisdm-dataset/arffmagic-master/src/attribute.cpp +47 -0
- wisdm-dataset/arffmagic-master/src/attribute.h +67 -0
- wisdm-dataset/arffmagic-master/src/chunk.cpp +24 -0
- wisdm-dataset/arffmagic-master/src/chunk.h +8 -0
- wisdm-dataset/arffmagic-master/src/comparator.h +11 -0
- wisdm-dataset/arffmagic-master/src/except.h +41 -0
- wisdm-dataset/arffmagic-master/src/funcmap.cpp +31 -0
- wisdm-dataset/arffmagic-master/src/funcmap.h +28 -0
- wisdm-dataset/arffmagic-master/src/globals.cpp +5 -0
- wisdm-dataset/arffmagic-master/src/globals.h +27 -0
- wisdm-dataset/arffmagic-master/src/libmfcc.c +165 -0
- wisdm-dataset/arffmagic-master/src/libmfcc.h +26 -0
- wisdm-dataset/arffmagic-master/src/main.cpp +19 -0
- wisdm-dataset/arffmagic-master/src/raw.cpp +38 -0
- wisdm-dataset/arffmagic-master/src/raw.h +36 -0
- wisdm-dataset/arffmagic-master/src/read.cpp +33 -0
- wisdm-dataset/arffmagic-master/src/read.h +7 -0
- wisdm-dataset/arffmagic-master/src/try.h +14 -0
- wisdm-dataset/arffmagic-master/src/write.cpp +257 -0
- wisdm-dataset/arffmagic-master/src/write.h +31 -0
.gitattributes
CHANGED
|
@@ -58,3 +58,14 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
WISDM-dataset-description.pdf filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
wisdm-dataset/WISDM-dataset-description.pdf filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
wisdm-dataset/arffmagic-master/bin/magic filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
wisdm-dataset/arffmagic-master/bin/arffmagic filter=lfs diff=lfs merge=lfs -text
|
| 65 |
+
wisdm-dataset/arffmagic-master/bin/arffmagic.dSYM/Contents/Resources/DWARF/arffmagic filter=lfs diff=lfs merge=lfs -text
|
| 66 |
+
wisdm-dataset/arffmagic-master/build/main.o filter=lfs diff=lfs merge=lfs -text
|
| 67 |
+
wisdm-dataset/arffmagic-master/build/write.o filter=lfs diff=lfs merge=lfs -text
|
| 68 |
+
wisdm-dataset/arffmagic-master/build/funcmap.o filter=lfs diff=lfs merge=lfs -text
|
| 69 |
+
wisdm-dataset/arffmagic-master/build/arff.o filter=lfs diff=lfs merge=lfs -text
|
| 70 |
+
wisdm-dataset/arffmagic-master/build/attribute.o filter=lfs diff=lfs merge=lfs -text
|
| 71 |
+
wisdm-dataset/arffmagic-master/build/read.o filter=lfs diff=lfs merge=lfs -text
|
WISDM-dataset-description.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1d378fb33f871714cf2b1fbec65bab7eeed93e1892fc1460d80e45c022ce92ba
|
| 3 |
+
size 578662
|
wisdm-dataset/.activity_key.txt.swp
ADDED
|
Binary file (12.3 kB). View file
|
|
|
wisdm-dataset/README.txt
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
This dataset includes activity data from 51 participants from an activity
|
| 2 |
+
recognition project. Each participant performed each of the 18 activities
|
| 3 |
+
(listed in activity_key.txt) for 3 minutes and the sensor data (accelerometer
|
| 4 |
+
and gyroscope for smartphone and smartwatch) was recorded at a rate of 20 Hz.
|
| 5 |
+
The smartphones used were Nexus 5, Nexus 5X, and Galaxy S6 while the smartwatch
|
| 6 |
+
used was the LG G watch. This dataset contains the raw data as well as the
|
| 7 |
+
transformed data which was generated using arffmagic (located in
|
| 8 |
+
arffmagic-master).
|
| 9 |
+
|
| 10 |
+
A much more detailed description of the two main data sets is provided in the
|
| 11 |
+
wisdm-dataset-description.pdf document at the top level of the data directory.
|
| 12 |
+
|
| 13 |
+
################################################################################
|
| 14 |
+
################################################################################
|
| 15 |
+
|
| 16 |
+
The raw sensor data is located in the raw directory. Each user has its own data
|
| 17 |
+
file which is tagged with their subject id, the sensor, and the device. Within
|
| 18 |
+
the data file, each line is:
|
| 19 |
+
|
| 20 |
+
Subject-id, Activity Label, Timestamp, x, y, z
|
| 21 |
+
|
| 22 |
+
The features are defined as follows:
|
| 23 |
+
|
| 24 |
+
subject-id: Identfies the subject and is an integer value between 1600 and 1650.
|
| 25 |
+
|
| 26 |
+
activity-label: see activity_key.txt for a mapping from 18 characters to the
|
| 27 |
+
activity name
|
| 28 |
+
|
| 29 |
+
timestamp: time that the reading was taken (Unix Time)
|
| 30 |
+
|
| 31 |
+
x: x sensor value (real valued)
|
| 32 |
+
y: y sensor value (real valued)
|
| 33 |
+
z: z sensor value (real valued)
|
| 34 |
+
|
| 35 |
+
################################################################################
|
| 36 |
+
################################################################################
|
| 37 |
+
|
| 38 |
+
ARFF files for each user (with attributes described below) are located in the
|
| 39 |
+
arff_files directory. The ARFF files are created using the arffmagic program, which
|
| 40 |
+
aggregates the lower level raw data into examples labeled with the activity being
|
| 41 |
+
performed. The descriptions of these features are also found in the many WISDM
|
| 42 |
+
activity recognition papers.
|
| 43 |
+
|
| 44 |
+
Recognize that the sensors are samples at 20Hz and we use a 10 second window size,
|
| 45 |
+
so most of the statistics are based on the aggregation of 200 sensor readings.
|
| 46 |
+
|
| 47 |
+
Attribute information:
|
| 48 |
+
ACTIVITY[1]:
|
| 49 |
+
This field contains the code that uniquely identifies the activity
|
| 50 |
+
(activity_key.txt provides the mapping from code to actual activity)
|
| 51 |
+
|
| 52 |
+
Binned Distribution[30]:
|
| 53 |
+
The range of values is determined (maximum - minimum), 10 equal-sized
|
| 54 |
+
bins are formed, and the fraction of the 200 values within each bin
|
| 55 |
+
is recorded for each of the 3 axes. The axis bin values are provided
|
| 56 |
+
in the following order: x, y, z (10 values for each). The attributes are
|
| 57 |
+
named X0 .. X9, Y1 ... Y9, and Z0 ... Z9
|
| 58 |
+
|
| 59 |
+
Average[3]:
|
| 60 |
+
Average sensor value (for each of the 3 axes). Labeled XAVG, YAVG, ZAVG
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
Time Between Peaks[3]:
|
| 64 |
+
Time between peaks in the sinusoidal waves formed by the data
|
| 65 |
+
as determined by a simple algorithm (feel free to check the code). Done
|
| 66 |
+
for each axis). Labeled XPEAK, YPEAK, ZPEAK.
|
| 67 |
+
|
| 68 |
+
Average Absolute Difference[3]:
|
| 69 |
+
Average absolute difference between the 200 values and the mean of these
|
| 70 |
+
values (for each axis). Labeled as {X,Y,Z}ABSOLDEV
|
| 71 |
+
|
| 72 |
+
Standard Deviation[3]:
|
| 73 |
+
Standard deviation (for each axis). Labeled as {X,Y,Z}STANDDEV
|
| 74 |
+
|
| 75 |
+
Variance[3];
|
| 76 |
+
The variance of the values (for each axis). Labeled as {X,Y,Z}VAR
|
| 77 |
+
|
| 78 |
+
--------------------------------------------------------------------------------
|
| 79 |
+
THE NEXT THREE SETS OF FEATURES ARE NOT USED IN OUR PUBLISHED RESEARCH PAPERS. THEY
|
| 80 |
+
WERE ADDED TO EXPERIMENT WITH.
|
| 81 |
+
|
| 82 |
+
MFCC: Mel-frequency cepstral coefficients [39]
|
| 83 |
+
MFCCs are a representation of the short-term power spectrum of a wave, based
|
| 84 |
+
on a linear cosine transform of a log power spectrum on a nonlinear mel scale
|
| 85 |
+
of frequency. There are 13 per axis There are 13 per axis. They are labeled as
|
| 86 |
+
XMFCC{0-12}, YMFCC{0-12}, and ZMFCC{0-12}.
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
Cosine distance [3]:
|
| 90 |
+
These are the cosine distances between the sensor values for a pair of axes.
|
| 91 |
+
Three pairs are considered to cover all possible pairs. They are labeled as
|
| 92 |
+
{XY, XZ, YZ}COS.
|
| 93 |
+
|
| 94 |
+
Correlation [3]:
|
| 95 |
+
These are the correlations between the sensor values for a pair of axes.
|
| 96 |
+
Three pairs are considered to cover all possible pairs. They are labeled as
|
| 97 |
+
{XY, XZ, YZ}COR.
|
| 98 |
+
|
| 99 |
+
----------------------------------------------------------------------------------
|
| 100 |
+
|
| 101 |
+
Average Resultant Acceleration[1]:
|
| 102 |
+
For each of the sensor samples in the window, take the square root of the sum
|
| 103 |
+
of the square of the x, y, z axis values, and then average them. Labeled as
|
| 104 |
+
RESULTANT.
|
| 105 |
+
|
| 106 |
+
class: Subject-id (this name is misleading since for activity recognition the class is
|
| 107 |
+
the activity in the first position).
|
wisdm-dataset/WISDM-dataset-description.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1d378fb33f871714cf2b1fbec65bab7eeed93e1892fc1460d80e45c022ce92ba
|
| 3 |
+
size 578662
|
wisdm-dataset/activity_key.txt
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
walking = A
|
| 2 |
+
jogging = B
|
| 3 |
+
stairs = C
|
| 4 |
+
sitting = D
|
| 5 |
+
standing = E
|
| 6 |
+
typing = F
|
| 7 |
+
teeth = G
|
| 8 |
+
soup = H
|
| 9 |
+
chips = I
|
| 10 |
+
pasta = J
|
| 11 |
+
drinking = K
|
| 12 |
+
sandwich = L
|
| 13 |
+
kicking = M
|
| 14 |
+
catch = O
|
| 15 |
+
dribbling = P
|
| 16 |
+
writing = Q
|
| 17 |
+
clapping = R
|
| 18 |
+
folding = S
|
| 19 |
+
|
wisdm-dataset/arff_files/.DS_Store
ADDED
|
Binary file (8.2 kB). View file
|
|
|
wisdm-dataset/arff_files/phone/.DS_Store
ADDED
|
Binary file (10.2 kB). View file
|
|
|
wisdm-dataset/arff_files/phone/gyro/data_1615_gyro_phone.arff
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
wisdm-dataset/arff_files/phone/gyro/data_1628_gyro_phone.arff
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
wisdm-dataset/arffmagic-master/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
wisdm-dataset/arffmagic-master/Makefile
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
SHELL=/bin/sh
|
| 2 |
+
SRC=./src
|
| 3 |
+
BIN=./bin
|
| 4 |
+
BUILD=./build
|
| 5 |
+
CC=clang++
|
| 6 |
+
CFLAGS=-std=c++11 -g -O2 -Wall -Wextra
|
| 7 |
+
LDFLAGS=-lAquila -lgsl -lgslcblas -lm
|
| 8 |
+
EXE=$(BIN)/arffmagic
|
| 9 |
+
OBJS=$(BUILD)/main.o $(BUILD)/globals.o $(BUILD)/raw.o $(BUILD)/read.o $(BUILD)/chunk.o $(BUILD)/write.o $(BUILD)/arff.o $(BUILD)/funcmap.o $(BUILD)/attribute.o $(BUILD)/libmfcc.o
|
| 10 |
+
DS:=dsymutil
|
| 11 |
+
DSYM=$(BIN)/arffmagic.dSYM
|
| 12 |
+
.SUFFIXES:
|
| 13 |
+
.SUFFIXES: .c .cpp .o
|
| 14 |
+
|
| 15 |
+
dsym: $(DSYM)
|
| 16 |
+
|
| 17 |
+
all: $(EXE) $(DSYM)
|
| 18 |
+
|
| 19 |
+
$(EXE): $(OBJS)
|
| 20 |
+
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS)
|
| 21 |
+
|
| 22 |
+
$(BUILD)/%.o: $(SRC)/%.cpp
|
| 23 |
+
$(CC) $(CFLAGS) -c $< -o $@
|
| 24 |
+
|
| 25 |
+
$(BUILD)/%.o: $(SRC)/%.c
|
| 26 |
+
$(CC) $(CFLAGS) -c $< -o $@
|
| 27 |
+
|
| 28 |
+
$(DSYM): $(EXE)
|
| 29 |
+
$(DS) -o $@ $<
|
| 30 |
+
|
| 31 |
+
.PHONY: clean
|
| 32 |
+
clean:
|
| 33 |
+
rm -rf $(OBJS) $(EXE) $(DSYM)
|
wisdm-dataset/arffmagic-master/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# arffmagic
|
wisdm-dataset/arffmagic-master/bin/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
wisdm-dataset/arffmagic-master/bin/arffmagic
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d86e4bec8ba5f1921699e3c25e1e8a819359394245b7d82d9f29740b1169bf46
|
| 3 |
+
size 140780
|
wisdm-dataset/arffmagic-master/bin/arffmagic.dSYM/Contents/Info.plist
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
| 3 |
+
<plist version="1.0">
|
| 4 |
+
<dict>
|
| 5 |
+
<key>CFBundleDevelopmentRegion</key>
|
| 6 |
+
<string>English</string>
|
| 7 |
+
<key>CFBundleIdentifier</key>
|
| 8 |
+
<string>com.apple.xcode.dsym.arffmagic</string>
|
| 9 |
+
<key>CFBundleInfoDictionaryVersion</key>
|
| 10 |
+
<string>6.0</string>
|
| 11 |
+
<key>CFBundlePackageType</key>
|
| 12 |
+
<string>dSYM</string>
|
| 13 |
+
<key>CFBundleSignature</key>
|
| 14 |
+
<string>????</string>
|
| 15 |
+
<key>CFBundleShortVersionString</key>
|
| 16 |
+
<string>1.0</string>
|
| 17 |
+
<key>CFBundleVersion</key>
|
| 18 |
+
<string>1</string>
|
| 19 |
+
</dict>
|
| 20 |
+
</plist>
|
wisdm-dataset/arffmagic-master/bin/arffmagic.dSYM/Contents/Resources/DWARF/arffmagic
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:aa607d022fc8bb9f8e728f7040f17b60fbdc7213e1bfce2f1a34bfcce4d6499a
|
| 3 |
+
size 1009535
|
wisdm-dataset/arffmagic-master/bin/magic
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7be816dcfe583ef221b915067a586f6b9a9070c4e70db54624dc57d11d2c48e4
|
| 3 |
+
size 178012
|
wisdm-dataset/arffmagic-master/build/arff.o
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:78afa782cbcd22def496861ea5cf1708f4bf813dd70951d0645366723f692021
|
| 3 |
+
size 325072
|
wisdm-dataset/arffmagic-master/build/attribute.o
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:432dc51dd3b83c2d6eee0b771140980a27c2b175757b922663ae493787246487
|
| 3 |
+
size 184192
|
wisdm-dataset/arffmagic-master/build/chunk.o
ADDED
|
Binary file (75.9 kB). View file
|
|
|
wisdm-dataset/arffmagic-master/build/funcmap.o
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:40d7c59c69a7c6c6cd01253918cce6003495be7a3384c17fe13bff61f322089b
|
| 3 |
+
size 270328
|
wisdm-dataset/arffmagic-master/build/globals.o
ADDED
|
Binary file (52.8 kB). View file
|
|
|
wisdm-dataset/arffmagic-master/build/libmfcc.o
ADDED
|
Binary file (13.5 kB). View file
|
|
|
wisdm-dataset/arffmagic-master/build/main.o
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c745f17f3a095ce5cef1a26831c726f1079e5feef30958f4a0cff245682e5b1d
|
| 3 |
+
size 184100
|
wisdm-dataset/arffmagic-master/build/raw.o
ADDED
|
Binary file (42 kB). View file
|
|
|
wisdm-dataset/arffmagic-master/build/read.o
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bc608089eb9372a55e1f6e8e7cc5df012f2cf1e308e86609c41cbdc16da5c081
|
| 3 |
+
size 173244
|
wisdm-dataset/arffmagic-master/build/write.o
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:508563dda17896a97f5c433a8a0392362440e832c387448110f313640acf355d
|
| 3 |
+
size 401100
|
wisdm-dataset/arffmagic-master/src/arff.cpp
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "arff.h"
|
| 2 |
+
#include "try.h"
|
| 3 |
+
using std::endl;
|
| 4 |
+
|
| 5 |
+
arff::arff (char ** argv, void(* init)(arff&), void(* translate)(arff&)): container(new funcmap), relation("") {
|
| 6 |
+
tryOrDie([this, &argv]() { openFiles(argv); });
|
| 7 |
+
init(*this);
|
| 8 |
+
arfStream << "@relation " << relation << endl << endl;
|
| 9 |
+
translate(*this);
|
| 10 |
+
container->writeHeader(arfStream);
|
| 11 |
+
arfStream << "@data" << endl << instanceStream.str();
|
| 12 |
+
std::cout << "magic @ " << argv[2] << endl;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
arff::~arff () {
|
| 16 |
+
delete container;
|
| 17 |
+
rawStream.close();
|
| 18 |
+
arfStream.close();
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
void arff::openFiles (char ** argv) throw (OpenFileFail) {
|
| 22 |
+
rawStream.open(argv[1]);
|
| 23 |
+
if (!rawStream.is_open()) {
|
| 24 |
+
throw OpenFileFail(argv[1]);
|
| 25 |
+
} else {
|
| 26 |
+
arfStream.open(argv[2]);
|
| 27 |
+
if (!arfStream.is_open()) {
|
| 28 |
+
throw OpenFileFail(argv[2]);
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
void arff::add (int position, void(*calc)(const std::unique_ptr<attribute>&), std::string name, std::string type) {
|
| 34 |
+
container->push(position, name, type, calc);
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
void arff::compute () {
|
| 38 |
+
container->hash();
|
| 39 |
+
instanceStream << container << endl;
|
| 40 |
+
}
|
wisdm-dataset/arffmagic-master/src/arff.h
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef ARFF_H
|
| 2 |
+
#define ARFF_H
|
| 3 |
+
#include <sstream>
|
| 4 |
+
#include <fstream>
|
| 5 |
+
#include <string>
|
| 6 |
+
#include "funcmap.h"
|
| 7 |
+
#include "except.h"
|
| 8 |
+
|
| 9 |
+
class arff {
|
| 10 |
+
public:
|
| 11 |
+
arff (char **, void(*)(arff&), void(*)(arff&));
|
| 12 |
+
~arff ();
|
| 13 |
+
void add (int, void(*)(const std::unique_ptr<attribute>&), std::string, std::string = "numeric");
|
| 14 |
+
void setRelation (std::string _relation) { relation=_relation; }
|
| 15 |
+
void compute ();
|
| 16 |
+
std::ifstream rawStream;
|
| 17 |
+
private:
|
| 18 |
+
void openFiles (char **) throw (OpenFileFail);
|
| 19 |
+
funcmap * container;
|
| 20 |
+
std::string relation;
|
| 21 |
+
std::ofstream arfStream;
|
| 22 |
+
std::stringstream instanceStream;
|
| 23 |
+
};
|
| 24 |
+
|
| 25 |
+
#endif
|
wisdm-dataset/arffmagic-master/src/attribute.cpp
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "attribute.h"
|
| 2 |
+
|
| 3 |
+
bool attribute::spaceFound (string str) {
|
| 4 |
+
unsigned long i = 0; bool space = false;
|
| 5 |
+
while (!space && i<str.length()) {
|
| 6 |
+
space = isspace(str[i]);
|
| 7 |
+
i++;
|
| 8 |
+
} return space;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
string attribute::representStr (string str) {
|
| 12 |
+
string newstr = str;
|
| 13 |
+
if (spaceFound(str)) {
|
| 14 |
+
newstr = "\"";
|
| 15 |
+
newstr += (str += "\"");
|
| 16 |
+
} return newstr;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
string nominal::representType (string str) {
|
| 20 |
+
string newstr = "{ ";
|
| 21 |
+
newstr += (str += " }");
|
| 22 |
+
return newstr;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
void nominal::set (string str) {
|
| 26 |
+
val = representStr(str);
|
| 27 |
+
if (types.empty()) {
|
| 28 |
+
types.push_back(val);
|
| 29 |
+
type += val;
|
| 30 |
+
} else if ((std::find(types.begin(), types.end(), val)) == types.end()) {
|
| 31 |
+
types.push_back(val);
|
| 32 |
+
type += ", ";
|
| 33 |
+
type += val;
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
void numeric::print (std::ofstream& strm) const { strm << val; }
|
| 38 |
+
void numeric::print (std:: ostream& strm) const { strm << val; }
|
| 39 |
+
void nominal::print (std::ofstream& strm) const { strm << val; }
|
| 40 |
+
void nominal::print (std:: ostream& strm) const { strm << val; }
|
| 41 |
+
void stringy::print (std::ofstream& strm) const { strm << val; }
|
| 42 |
+
void stringy::print (std:: ostream& strm) const { strm << val; }
|
| 43 |
+
|
| 44 |
+
attribute::~attribute () {};
|
| 45 |
+
numeric::~numeric () {};
|
| 46 |
+
nominal::~nominal () {};
|
| 47 |
+
stringy::~stringy () {};
|
wisdm-dataset/arffmagic-master/src/attribute.h
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef ATTRIBUTE_H
|
| 2 |
+
#define ATTRIBUTE_H
|
| 3 |
+
#include <algorithm>
|
| 4 |
+
#include <fstream>
|
| 5 |
+
#include <vector>
|
| 6 |
+
#include <memory>
|
| 7 |
+
using std::string;
|
| 8 |
+
|
| 9 |
+
class attribute {
|
| 10 |
+
public:
|
| 11 |
+
attribute (int _position, string _name, string _type): position(_position), name(_name), type(_type), title("@attribute") {};
|
| 12 |
+
virtual ~attribute ();
|
| 13 |
+
string declare () {
|
| 14 |
+
return (this->title + " \"" + this->name + "\" " + this->representType(this->type));
|
| 15 |
+
}
|
| 16 |
+
const int position;
|
| 17 |
+
string name;
|
| 18 |
+
string type;
|
| 19 |
+
const string title;
|
| 20 |
+
bool spaceFound (string);
|
| 21 |
+
string representStr (string);
|
| 22 |
+
virtual string representType (string str) { return str; }
|
| 23 |
+
virtual void set (double) {};
|
| 24 |
+
virtual void set (string) {};
|
| 25 |
+
virtual void setType (std::vector<const char *>) {};
|
| 26 |
+
virtual void print (std::ofstream&) const=0;
|
| 27 |
+
virtual void print (std:: ostream&) const=0;
|
| 28 |
+
template <typename stream>
|
| 29 |
+
friend stream& operator << (stream& strm, const std::unique_ptr<attribute>& attr){
|
| 30 |
+
attr->print(strm);
|
| 31 |
+
return strm;
|
| 32 |
+
}
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
class numeric: public attribute {
|
| 36 |
+
public:
|
| 37 |
+
double val;
|
| 38 |
+
numeric (int _position, string _name, string _type): attribute(_position, _name, _type), val(0.0) {}
|
| 39 |
+
virtual ~numeric ();
|
| 40 |
+
void set (double x) { val = x; }
|
| 41 |
+
void print (std::ofstream&) const;
|
| 42 |
+
void print (std:: ostream&) const;
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
class nominal: public attribute {
|
| 46 |
+
public:
|
| 47 |
+
std::vector<string> types;
|
| 48 |
+
string val;
|
| 49 |
+
nominal (int _position, string _name, string _type): attribute(_position, _name, _type), val("") {};
|
| 50 |
+
virtual ~nominal ();
|
| 51 |
+
virtual string representType (string);
|
| 52 |
+
void set (string);
|
| 53 |
+
void print (std::ofstream&) const;
|
| 54 |
+
void print (std:: ostream&) const;
|
| 55 |
+
};
|
| 56 |
+
|
| 57 |
+
class stringy: public attribute {
|
| 58 |
+
public:
|
| 59 |
+
string val;
|
| 60 |
+
stringy (int _position, string _name, string _type): attribute(_position, _name, _type), val("") {};
|
| 61 |
+
virtual ~stringy ();
|
| 62 |
+
void set (string x) { val = representStr(x); }
|
| 63 |
+
void print (std::ofstream&) const;
|
| 64 |
+
void print (std:: ostream&) const;
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
#endif
|
wisdm-dataset/arffmagic-master/src/chunk.cpp
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "chunk.h"
|
| 2 |
+
#include "globals.h"
|
| 3 |
+
#include "read.h"
|
| 4 |
+
|
| 5 |
+
bool validRecord () {
|
| 6 |
+
return (record.curr != record.prev) && (record.parsed == record.expected);
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
bool belongsInChunk () {
|
| 10 |
+
return (chunk.empty()) || (!strcmp(record.toke[0], record.oldToke[0])) || (!strcmp(record.toke[1], record.oldToke[1]));
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
void addRecord () {
|
| 14 |
+
for (int i=0; i<NUM_AXIS; i++) {
|
| 15 |
+
data[i].push_back(atof(record.toke[i+3]));
|
| 16 |
+
}
|
| 17 |
+
chunk.resize(chunk.size()+1);
|
| 18 |
+
}
|
| 19 |
+
void dumpChunk () {
|
| 20 |
+
for (int i=0; i<NUM_AXIS; i++) {
|
| 21 |
+
data[i].clear();
|
| 22 |
+
}
|
| 23 |
+
chunk.resize(0);
|
| 24 |
+
}
|
wisdm-dataset/arffmagic-master/src/chunk.h
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef CHUNK_H
|
| 2 |
+
#define CHUNK_H
|
| 3 |
+
//what does it mean for records to become a chunk?
|
| 4 |
+
bool validRecord ();
|
| 5 |
+
bool belongsInChunk ();
|
| 6 |
+
void addRecord ();
|
| 7 |
+
void dumpChunk ();
|
| 8 |
+
#endif
|
wisdm-dataset/arffmagic-master/src/comparator.h
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef COMPARATOR_H
|
| 2 |
+
#define COMPARATOR_H
|
| 3 |
+
|
| 4 |
+
class comparator {
|
| 5 |
+
public:
|
| 6 |
+
bool operator () (const std::unique_ptr<attribute>& left, const std::unique_ptr<attribute>& right) const {
|
| 7 |
+
return left->position < right->position;
|
| 8 |
+
}
|
| 9 |
+
};
|
| 10 |
+
|
| 11 |
+
#endif
|
wisdm-dataset/arffmagic-master/src/except.h
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef EXCEPT_H
|
| 2 |
+
#define EXCEPT_H
|
| 3 |
+
#include <stdexcept>
|
| 4 |
+
|
| 5 |
+
class EpicFail: public std::invalid_argument {
|
| 6 |
+
public:
|
| 7 |
+
char buf[4096];
|
| 8 |
+
EpicFail (const char * msg): std::invalid_argument(msg){};
|
| 9 |
+
virtual const char * specify () {
|
| 10 |
+
return specify("error", "god knows...");
|
| 11 |
+
}
|
| 12 |
+
virtual const char * specify (const char * errorLeft, const char * errorRight) {
|
| 13 |
+
sprintf(buf, "%s: \"%s\"\n", errorLeft, errorRight);
|
| 14 |
+
return buf;
|
| 15 |
+
}
|
| 16 |
+
virtual const char * specify (const char * errorLeft, const char * errorRight, const char * errorHint) {
|
| 17 |
+
sprintf(buf, "%s: \"%s\"\n(%s)\n", errorLeft, errorRight, errorHint);
|
| 18 |
+
return buf;
|
| 19 |
+
}
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
class ArgumentFail: public EpicFail {
|
| 23 |
+
public:
|
| 24 |
+
virtual const char * specify () {
|
| 25 |
+
sprintf(buf, "%s: %-s\n%7s%-8s: %-s\n%7s%-8s: %-s\n", "USAGE", "arffmagic infile outfile", "", "infile", "raw data (.txt)", "", "outfile", "generated instances (.arff)");
|
| 26 |
+
return buf;
|
| 27 |
+
}
|
| 28 |
+
ArgumentFail(): EpicFail(specify()) {};
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
class OpenFileFail: public EpicFail {
|
| 32 |
+
public:
|
| 33 |
+
OpenFileFail(const char * file): EpicFail(specify("failed to open", file)) {};
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
class AttributeTypeFail: public EpicFail {
|
| 37 |
+
public:
|
| 38 |
+
AttributeTypeFail(const char * type): EpicFail(specify("unknown type", type, "can only magic on numeric, nominal, and string attributes")) {};
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
#endif
|
wisdm-dataset/arffmagic-master/src/funcmap.cpp
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "funcmap.h"
|
| 2 |
+
#include "try.h"
|
| 3 |
+
|
| 4 |
+
void funcmap::hash () {
|
| 5 |
+
for (auto& x: pairs) {
|
| 6 |
+
x.second(x.first);
|
| 7 |
+
}
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
void funcmap::writeHeader (std::ofstream& ofs) {
|
| 11 |
+
for (auto& x: pairs) {
|
| 12 |
+
ofs << x.first->declare() << std::endl;
|
| 13 |
+
}
|
| 14 |
+
ofs << std::endl;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
void funcmap::push (int position, string name, string type, void(*calc)(const std::unique_ptr<attribute>&)) throw (AttributeTypeFail) {
|
| 18 |
+
std::unique_ptr<attribute> curr = nullptr;
|
| 19 |
+
tryOrDie([this, &curr, &position, &name, &type, &calc]() {
|
| 20 |
+
if (type == "numeric") {
|
| 21 |
+
curr = std::unique_ptr<attribute>(new numeric(position, name, type));
|
| 22 |
+
} else if (type == "string") {
|
| 23 |
+
curr = std::unique_ptr<attribute>(new stringy(position, name, type));
|
| 24 |
+
} else if (type == "nominal") {
|
| 25 |
+
curr = std::unique_ptr<attribute>(new nominal(position, name, ""));
|
| 26 |
+
} else {
|
| 27 |
+
throw AttributeTypeFail(type.c_str());
|
| 28 |
+
}
|
| 29 |
+
pairs.insert(std::make_pair(std::move(curr), calc));
|
| 30 |
+
});
|
| 31 |
+
}
|
wisdm-dataset/arffmagic-master/src/funcmap.h
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef FUNCMAP_H
|
| 2 |
+
#define FUNCMAP_H
|
| 3 |
+
#include <fstream>
|
| 4 |
+
#include <vector>
|
| 5 |
+
#include <map>
|
| 6 |
+
#include "attribute.h"
|
| 7 |
+
#include "comparator.h"
|
| 8 |
+
#include "except.h"
|
| 9 |
+
|
| 10 |
+
class funcmap {
|
| 11 |
+
public:
|
| 12 |
+
template <typename stream>
|
| 13 |
+
friend stream& operator << (stream& strm, const funcmap * container) {
|
| 14 |
+
for (auto& x: container->pairs) {
|
| 15 |
+
strm << x.first;
|
| 16 |
+
if (x != *(container->pairs.rbegin())) {
|
| 17 |
+
strm << ",";
|
| 18 |
+
}
|
| 19 |
+
} return strm;
|
| 20 |
+
}
|
| 21 |
+
void push (int, string, string, void(*)(const std::unique_ptr<attribute>&)) throw (AttributeTypeFail);
|
| 22 |
+
void hash ();
|
| 23 |
+
void writeHeader (std::ofstream&);
|
| 24 |
+
private:
|
| 25 |
+
std::map<const std::unique_ptr<attribute>, void(*)(const std::unique_ptr<attribute>&), comparator> pairs;
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
#endif
|
wisdm-dataset/arffmagic-master/src/globals.cpp
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "globals.h"
|
| 2 |
+
|
| 3 |
+
instancer chunk(WINDOW_SIZE * SAMPLING_RATE);
|
| 4 |
+
liner record(NUM_TOKENS);
|
| 5 |
+
std::vector<double> data[NUM_AXIS];
|
wisdm-dataset/arffmagic-master/src/globals.h
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef GLOBALS_H
|
| 2 |
+
#define GLOBALS_H
|
| 3 |
+
#include "raw.h"
|
| 4 |
+
#include <vector>
|
| 5 |
+
|
| 6 |
+
const int NUM_AXIS = 3;
|
| 7 |
+
const int WINDOW_SIZE = 10;
|
| 8 |
+
const int SAMPLING_RATE = 20;
|
| 9 |
+
const int NUM_TOKENS = 3 + NUM_AXIS;
|
| 10 |
+
const int AX1 = (int) 'X';
|
| 11 |
+
const int AX2 = (int) 'Y';
|
| 12 |
+
const int AX3 = (int) 'Z';
|
| 13 |
+
const int NUM_BINS = 10;
|
| 14 |
+
const int TOTAL_BINS = NUM_AXIS * NUM_BINS;
|
| 15 |
+
const int NUM_MFCC = 13;
|
| 16 |
+
const int TOTAL_MFCC = NUM_AXIS * NUM_MFCC;
|
| 17 |
+
|
| 18 |
+
extern int BIN_START;
|
| 19 |
+
extern int XMFCC_START;
|
| 20 |
+
extern int YMFCC_START;
|
| 21 |
+
extern int ZMFCC_START;
|
| 22 |
+
extern int coefIndex;
|
| 23 |
+
extern instancer chunk;
|
| 24 |
+
extern liner record;
|
| 25 |
+
extern std::vector<double> data[];
|
| 26 |
+
|
| 27 |
+
#endif
|
wisdm-dataset/arffmagic-master/src/libmfcc.c
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* libmfcc.c - Code implementation for libMFCC
|
| 3 |
+
* Copyright (c) 2010 Jeremy Sawruk
|
| 4 |
+
*
|
| 5 |
+
* This code is released under the MIT License.
|
| 6 |
+
* For conditions of distribution and use, see the license in LICENSE
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#include <math.h>
|
| 10 |
+
#include "libmfcc.h"
|
| 11 |
+
|
| 12 |
+
/*
|
| 13 |
+
* Computes the specified (mth) MFCC
|
| 14 |
+
*
|
| 15 |
+
* spectralData - array of doubles containing the results of FFT computation. This data is already assumed to be purely real
|
| 16 |
+
* samplingRate - the rate that the original time-series data was sampled at (i.e 44100)
|
| 17 |
+
* NumFilters - the number of filters to use in the computation. Recommended value = 48
|
| 18 |
+
* binSize - the size of the spectralData array, usually a power of 2
|
| 19 |
+
* m - The mth MFCC coefficient to compute
|
| 20 |
+
*
|
| 21 |
+
*/
|
| 22 |
+
double GetCoefficient(double* spectralData, unsigned int samplingRate, unsigned int NumFilters, unsigned int binSize, unsigned int m)
|
| 23 |
+
{
|
| 24 |
+
double result = 0.0f;
|
| 25 |
+
double outerSum = 0.0f;
|
| 26 |
+
double innerSum = 0.0f;
|
| 27 |
+
unsigned int k, l;
|
| 28 |
+
|
| 29 |
+
// 0 <= m < L
|
| 30 |
+
if(m >= NumFilters)
|
| 31 |
+
{
|
| 32 |
+
// This represents an error condition - the specified coefficient is greater than or equal to the number of filters. The behavior in this case is undefined.
|
| 33 |
+
return 0.0f;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
result = NormalizationFactor(NumFilters, m);
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
for(l = 1; l <= NumFilters; l++)
|
| 40 |
+
{
|
| 41 |
+
// Compute inner sum
|
| 42 |
+
innerSum = 0.0f;
|
| 43 |
+
for(k = 0; k < binSize - 1; k++)
|
| 44 |
+
{
|
| 45 |
+
innerSum += fabs(spectralData[k] * GetFilterParameter(samplingRate, binSize, k, l));
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
if(innerSum > 0.0f)
|
| 49 |
+
{
|
| 50 |
+
innerSum = log(innerSum); // The log of 0 is undefined, so don't use it
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
innerSum = innerSum * cos(((m * PI) / NumFilters) * (l - 0.5f));
|
| 54 |
+
|
| 55 |
+
outerSum += innerSum;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
result *= outerSum;
|
| 59 |
+
|
| 60 |
+
return result;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
/*
|
| 64 |
+
* Computes the Normalization Factor (Equation 6)
|
| 65 |
+
* Used for internal computation only - not to be called directly
|
| 66 |
+
*/
|
| 67 |
+
double NormalizationFactor(int NumFilters, int m)
|
| 68 |
+
{
|
| 69 |
+
double normalizationFactor = 0.0f;
|
| 70 |
+
|
| 71 |
+
if(m == 0)
|
| 72 |
+
{
|
| 73 |
+
normalizationFactor = sqrt(1.0f / NumFilters);
|
| 74 |
+
}
|
| 75 |
+
else
|
| 76 |
+
{
|
| 77 |
+
normalizationFactor = sqrt(2.0f / NumFilters);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
return normalizationFactor;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
/*
|
| 84 |
+
* Compute the filter parameter for the specified frequency and filter bands (Eq. 2)
|
| 85 |
+
* Used for internal computation only - not the be called directly
|
| 86 |
+
*/
|
| 87 |
+
double GetFilterParameter(unsigned int samplingRate, unsigned int binSize, unsigned int frequencyBand, unsigned int filterBand)
|
| 88 |
+
{
|
| 89 |
+
double filterParameter = 0.0f;
|
| 90 |
+
|
| 91 |
+
double boundary = (frequencyBand * samplingRate) / binSize; // k * Fs / N
|
| 92 |
+
double prevCenterFrequency = GetCenterFrequency(filterBand - 1); // fc(l - 1) etc.
|
| 93 |
+
double thisCenterFrequency = GetCenterFrequency(filterBand);
|
| 94 |
+
double nextCenterFrequency = GetCenterFrequency(filterBand + 1);
|
| 95 |
+
|
| 96 |
+
if(boundary >= 0 && boundary < prevCenterFrequency)
|
| 97 |
+
{
|
| 98 |
+
filterParameter = 0.0f;
|
| 99 |
+
}
|
| 100 |
+
else if(boundary >= prevCenterFrequency && boundary < thisCenterFrequency)
|
| 101 |
+
{
|
| 102 |
+
filterParameter = (boundary - prevCenterFrequency) / (thisCenterFrequency - prevCenterFrequency);
|
| 103 |
+
filterParameter *= GetMagnitudeFactor(filterBand);
|
| 104 |
+
}
|
| 105 |
+
else if(boundary >= thisCenterFrequency && boundary < nextCenterFrequency)
|
| 106 |
+
{
|
| 107 |
+
filterParameter = (boundary - nextCenterFrequency) / (thisCenterFrequency - nextCenterFrequency);
|
| 108 |
+
filterParameter *= GetMagnitudeFactor(filterBand);
|
| 109 |
+
}
|
| 110 |
+
else if(boundary >= nextCenterFrequency && boundary < samplingRate)
|
| 111 |
+
{
|
| 112 |
+
filterParameter = 0.0f;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
return filterParameter;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
/*
|
| 119 |
+
* Compute the band-dependent magnitude factor for the given filter band (Eq. 3)
|
| 120 |
+
* Used for internal computation only - not the be called directly
|
| 121 |
+
*/
|
| 122 |
+
double GetMagnitudeFactor(unsigned int filterBand)
|
| 123 |
+
{
|
| 124 |
+
double magnitudeFactor = 0.0f;
|
| 125 |
+
|
| 126 |
+
if(filterBand >= 1 && filterBand <= 14)
|
| 127 |
+
{
|
| 128 |
+
magnitudeFactor = 0.015;
|
| 129 |
+
}
|
| 130 |
+
else if(filterBand >= 15 && filterBand <= 48)
|
| 131 |
+
{
|
| 132 |
+
magnitudeFactor = 2.0f / (GetCenterFrequency(filterBand + 1) - GetCenterFrequency(filterBand -1));
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
return magnitudeFactor;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
/*
|
| 139 |
+
* Compute the center frequency (fc) of the specified filter band (l) (Eq. 4)
|
| 140 |
+
* This where the mel-frequency scaling occurs. Filters are specified so that their
|
| 141 |
+
* center frequencies are equally spaced on the mel scale
|
| 142 |
+
* Used for internal computation only - not the be called directly
|
| 143 |
+
*/
|
| 144 |
+
double GetCenterFrequency(unsigned int filterBand)
|
| 145 |
+
{
|
| 146 |
+
double centerFrequency = 0.0f;
|
| 147 |
+
double exponent;
|
| 148 |
+
|
| 149 |
+
if(filterBand == 0)
|
| 150 |
+
{
|
| 151 |
+
centerFrequency = 0;
|
| 152 |
+
}
|
| 153 |
+
else if(filterBand >= 1 && filterBand <= 14)
|
| 154 |
+
{
|
| 155 |
+
centerFrequency = (200.0f * filterBand) / 3.0f;
|
| 156 |
+
}
|
| 157 |
+
else
|
| 158 |
+
{
|
| 159 |
+
exponent = filterBand - 14.0f;
|
| 160 |
+
centerFrequency = pow(1.0711703, exponent);
|
| 161 |
+
centerFrequency *= 1073.4;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
return centerFrequency;
|
| 165 |
+
}
|
wisdm-dataset/arffmagic-master/src/libmfcc.h
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* libmfcc.h - Header for libMFCC
|
| 3 |
+
* Copyright (c) 2010 Jeremy Sawruk
|
| 4 |
+
*
|
| 5 |
+
* This code is released under the MIT License.
|
| 6 |
+
* For conditions of distribution and use, see the license in LICENSE
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#define PI 3.14159265358979323846264338327
|
| 12 |
+
|
| 13 |
+
// Returns the specified (mth) MFCC
|
| 14 |
+
double GetCoefficient(double* spectralData, unsigned int samplingRate, unsigned int NumFilters, unsigned int binSize, unsigned int m);
|
| 15 |
+
|
| 16 |
+
// Compute the normalization factor (For internal computation only - not to be called directly)
|
| 17 |
+
double NormalizationFactor(int NumFilters, int m);
|
| 18 |
+
|
| 19 |
+
// Compute the filter parameter for the specified frequency and filter bands (For internal computation only - not the be called directly)
|
| 20 |
+
double GetFilterParameter(unsigned int samplingRate, unsigned int binSize, unsigned int frequencyBand, unsigned int filterBand);
|
| 21 |
+
|
| 22 |
+
// Compute the band-dependent magnitude factor for the given filter band (For internal computation only - not the be called directly)
|
| 23 |
+
double GetMagnitudeFactor(unsigned int filterBand);
|
| 24 |
+
|
| 25 |
+
// Compute the center frequency (fc) of the specified filter band (l) (For internal computation only - not the be called directly)
|
| 26 |
+
double GetCenterFrequency(unsigned int filterBand);
|
wisdm-dataset/arffmagic-master/src/main.cpp
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "try.h"
|
| 2 |
+
#include "except.h"
|
| 3 |
+
#include "read.h"
|
| 4 |
+
#include "write.h"
|
| 5 |
+
#include "arff.h"
|
| 6 |
+
|
| 7 |
+
void validateArgs (int argc) throw (ArgumentFail) {
|
| 8 |
+
if (argc != 3) {
|
| 9 |
+
throw ArgumentFail();
|
| 10 |
+
}
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
int main (int argc, char ** argv) {
|
| 14 |
+
tryOrDie([&]() {
|
| 15 |
+
validateArgs(argc);
|
| 16 |
+
arff magic(argv, initribute, rawdog);
|
| 17 |
+
});
|
| 18 |
+
}
|
| 19 |
+
|
wisdm-dataset/arffmagic-master/src/raw.cpp
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "raw.h"
|
| 2 |
+
|
| 3 |
+
instancer::instancer (int x): valid(0), invalid(0), MAX(x), MIN(0.9*x), count(0) {};
|
| 4 |
+
|
| 5 |
+
liner::liner (int x): expected(x), parsed(0), toke(NULL), oldToke(NULL), prev(""), curr("") {
|
| 6 |
+
size_t size = sizeof(char **) * (expected + 1);
|
| 7 |
+
toke = (char **) malloc(size);
|
| 8 |
+
oldToke = (char **) malloc(size);
|
| 9 |
+
memset(toke, '\0', size);
|
| 10 |
+
memset(oldToke, '\0', size);
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
void liner::update () {
|
| 14 |
+
prev = curr;
|
| 15 |
+
for (int i=0; i<expected; i++) {
|
| 16 |
+
if (toke[i]) {
|
| 17 |
+
free(oldToke[i]);
|
| 18 |
+
oldToke[i] = toke[i];
|
| 19 |
+
}
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
void liner::tokenize () {
|
| 24 |
+
parsed = 0;
|
| 25 |
+
const char * c_str = curr.c_str();
|
| 26 |
+
char * dup = strdup(c_str);
|
| 27 |
+
char * token = strtok(dup, ",;:");
|
| 28 |
+
while (token && parsed<expected) {
|
| 29 |
+
toke[parsed] = strdup(token);
|
| 30 |
+
parsed++;
|
| 31 |
+
token = strtok(NULL, ",;:");
|
| 32 |
+
} free(dup);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
liner::~liner () {
|
| 36 |
+
free(toke);
|
| 37 |
+
free(oldToke);
|
| 38 |
+
}
|
wisdm-dataset/arffmagic-master/src/raw.h
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef RAW_H
|
| 2 |
+
#define RAW_H
|
| 3 |
+
#include <cstdlib>
|
| 4 |
+
#include <string>
|
| 5 |
+
|
| 6 |
+
class instancer {
|
| 7 |
+
public:
|
| 8 |
+
int valid;
|
| 9 |
+
int invalid;
|
| 10 |
+
instancer (int);
|
| 11 |
+
void resize (unsigned int size) { count = size; };
|
| 12 |
+
int size () { return count; };
|
| 13 |
+
bool empty () const { return count == 0; }
|
| 14 |
+
bool min () const { return count >= MIN; };
|
| 15 |
+
bool full () const { return count == MAX; };
|
| 16 |
+
private:
|
| 17 |
+
const int MAX;
|
| 18 |
+
const int MIN;
|
| 19 |
+
int count;
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
class liner {
|
| 23 |
+
public:
|
| 24 |
+
const int expected;
|
| 25 |
+
int parsed;
|
| 26 |
+
char ** toke;
|
| 27 |
+
char ** oldToke;
|
| 28 |
+
std::string prev;
|
| 29 |
+
std::string curr;
|
| 30 |
+
void tokenize ();
|
| 31 |
+
void update ();
|
| 32 |
+
liner (int);
|
| 33 |
+
~liner ();
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
#endif
|
wisdm-dataset/arffmagic-master/src/read.cpp
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "read.h"
|
| 2 |
+
#include "globals.h"
|
| 3 |
+
#include "chunk.h"
|
| 4 |
+
#include "write.h"
|
| 5 |
+
|
| 6 |
+
void getRecord (arff& barf) {
|
| 7 |
+
getline(barf.rawStream, record.curr);
|
| 8 |
+
record.tokenize();
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
void rawdog (arff& barf) {
|
| 12 |
+
while (barf.rawStream.good()) {
|
| 13 |
+
bool instance = false; bool discard = false;
|
| 14 |
+
if (validRecord()) {
|
| 15 |
+
if (belongsInChunk()) {
|
| 16 |
+
if (!chunk.full()) {
|
| 17 |
+
addRecord();
|
| 18 |
+
} else {
|
| 19 |
+
instance = true;
|
| 20 |
+
}
|
| 21 |
+
} else if (!chunk.min()) {
|
| 22 |
+
discard = true;
|
| 23 |
+
} else {
|
| 24 |
+
instance = true;
|
| 25 |
+
}
|
| 26 |
+
} if (instance) {
|
| 27 |
+
writeInstance(barf);
|
| 28 |
+
} else if (!discard) {
|
| 29 |
+
record.update();
|
| 30 |
+
getRecord(barf);
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
}
|
wisdm-dataset/arffmagic-master/src/read.h
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef READ_H
|
| 2 |
+
#define READ_H
|
| 3 |
+
#include "arff.h"
|
| 4 |
+
//process of reading through the raw data file
|
| 5 |
+
void getRecord (arff&);
|
| 6 |
+
void rawdog (arff&);
|
| 7 |
+
#endif
|
wisdm-dataset/arffmagic-master/src/try.h
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef TRY_H
|
| 2 |
+
#define TRY_H
|
| 3 |
+
#include "except.h"
|
| 4 |
+
#include <iostream>
|
| 5 |
+
template <typename x>
|
| 6 |
+
void tryOrDie (x func) {
|
| 7 |
+
try {
|
| 8 |
+
func();
|
| 9 |
+
} catch (const EpicFail& wtf) {
|
| 10 |
+
std::cerr << wtf.what();
|
| 11 |
+
exit(1);
|
| 12 |
+
}
|
| 13 |
+
}
|
| 14 |
+
#endif
|
wisdm-dataset/arffmagic-master/src/write.cpp
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "write.h"
|
| 2 |
+
#include "read.h"
|
| 3 |
+
#include "chunk.h"
|
| 4 |
+
#include "globals.h"
|
| 5 |
+
#include "aquila/aquila.h"
|
| 6 |
+
#include "libmfcc.h"
|
| 7 |
+
#include <gsl/gsl_vector.h>
|
| 8 |
+
#include <gsl/gsl_statistics.h>
|
| 9 |
+
#include <cmath>
|
| 10 |
+
|
| 11 |
+
int binOffset = 0;
|
| 12 |
+
int mfccOffset = 0;
|
| 13 |
+
|
| 14 |
+
double avg [NUM_AXIS];
|
| 15 |
+
double sdev[NUM_AXIS];
|
| 16 |
+
int bins[NUM_AXIS][NUM_BINS];
|
| 17 |
+
vector<double> coefs[NUM_AXIS];
|
| 18 |
+
|
| 19 |
+
void initribute (arff& barf) {
|
| 20 |
+
barf.setRelation("person_activities_labeled");
|
| 21 |
+
|
| 22 |
+
/* ADDING ATTRIBUTES TO ARFFMAGIC!
|
| 23 |
+
for each attribute desired, make a call to the following arff member function
|
| 24 |
+
add(<int>, <void(*)(const std::unique_ptr<attribute>&)>, <string>, <string>)
|
| 25 |
+
with corresponding parameters
|
| 26 |
+
(1) position in instance (AKA position in arff header/attribute declaration)
|
| 27 |
+
(2) function (that you need to define) to set the attribute's value
|
| 28 |
+
(3) name (used for attribute declaration)
|
| 29 |
+
(4--optional) type (defaults to "numeric", alternatively specify "string" or "nominal")
|
| 30 |
+
Only attributes added in this function will appear in the generated arff! */
|
| 31 |
+
|
| 32 |
+
int n = 1;
|
| 33 |
+
barf.add(n++, activity, "ACTIVITY", "nominal");
|
| 34 |
+
|
| 35 |
+
binOffset = n;
|
| 36 |
+
for (int ax = AX1; ax < (NUM_AXIS + AX1); ax++) {
|
| 37 |
+
int start = NUM_BINS * (ax-AX1);
|
| 38 |
+
string str = "";
|
| 39 |
+
str += (char)ax;
|
| 40 |
+
for (n = start; n < (start + NUM_BINS); n++) {
|
| 41 |
+
barf.add(n+binOffset, bin, str+(std::to_string(n % NUM_BINS)));
|
| 42 |
+
} n += (TOTAL_BINS - n) + (ax - AX1) + binOffset;
|
| 43 |
+
barf.add(n, average, str + "AVG");
|
| 44 |
+
barf.add(n+=NUM_AXIS, peak, str + "PEAK");
|
| 45 |
+
barf.add(n+=NUM_AXIS, absoluteDev, str + "ABSOLDEV");
|
| 46 |
+
barf.add(n+=NUM_AXIS, standardDev, str + "STANDDEV");
|
| 47 |
+
barf.add(n+=NUM_AXIS, variance, str + "VAR");
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
mfccOffset = n+1;
|
| 51 |
+
for (int ax = AX1; ax < (NUM_AXIS + AX1); ax++) {
|
| 52 |
+
int start = NUM_MFCC * (ax-AX1);
|
| 53 |
+
string str = "";
|
| 54 |
+
str += (char)ax;
|
| 55 |
+
str += "MFCC";
|
| 56 |
+
for (n = start; n < (start + NUM_MFCC); n++) {
|
| 57 |
+
barf.add(n+mfccOffset, mfcc, str+(std::to_string(n % NUM_MFCC)));
|
| 58 |
+
} n += (TOTAL_MFCC - n) + (ax - AX1) + mfccOffset;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
barf.add(++n, cosineSimilarity, "XYCOS");
|
| 62 |
+
barf.add(++n, cosineSimilarity, "XZCOS");
|
| 63 |
+
barf.add(++n, cosineSimilarity, "YZCOS");
|
| 64 |
+
barf.add(++n, correlation, "XYCOR");
|
| 65 |
+
barf.add(++n, correlation, "XZCOR");
|
| 66 |
+
barf.add(++n, correlation, "YZCOR");
|
| 67 |
+
barf.add(++n, resultant, "RESULTANT");
|
| 68 |
+
barf.add(++n, userID, "class", "nominal");
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
int getAxis (const std::unique_ptr<attribute>& attr, int nameChar) {
|
| 72 |
+
int axis;
|
| 73 |
+
switch (attr->name[nameChar]) {
|
| 74 |
+
case 'X': axis = 0; break;
|
| 75 |
+
case 'Y': axis = 1; break;
|
| 76 |
+
case 'Z': axis = 2; break;
|
| 77 |
+
}
|
| 78 |
+
return axis;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
void activity (const std::unique_ptr<attribute>& attr) {
|
| 82 |
+
attr->set(record.toke[1]);
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
void bin (const std::unique_ptr<attribute>& attr) {
|
| 86 |
+
int ax = getAxis(attr, 0);
|
| 87 |
+
attr->set((bins[ax][getBindex(attr)])/((double)chunk.size()));
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
int getBindex (const std::unique_ptr<attribute>& attr) {
|
| 91 |
+
int bindex = ((attr->position)-binOffset)%NUM_BINS;
|
| 92 |
+
return bindex;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
void average (const std::unique_ptr<attribute>& attr) {
|
| 96 |
+
int ax = getAxis(attr, 0);
|
| 97 |
+
attr->set(avg[ax]);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
void peak (const std::unique_ptr<attribute>& attr) {
|
| 101 |
+
int sum = 0;
|
| 102 |
+
vector<int> dists = getDists(getPeaks(attr));
|
| 103 |
+
for (auto dist: dists) {
|
| 104 |
+
sum += dist;
|
| 105 |
+
}
|
| 106 |
+
attr->set(((double)sum/dists.size())*NUM_BINS);
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
vector<int> getPeaks (const std::unique_ptr<attribute>& attr) {
|
| 110 |
+
int ax = getAxis(attr, 0);
|
| 111 |
+
vector<int> peaks;
|
| 112 |
+
if (data[ax][0] > data[ax][1]) {
|
| 113 |
+
peaks.push_back(0);
|
| 114 |
+
} for (int i=1; i<(chunk.size()-2); i++) {
|
| 115 |
+
if ((data[ax][i] > data[ax][i-1]) && data[ax][i] > data[ax][i+1]) {
|
| 116 |
+
peaks.push_back(i);
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
if (data[ax][chunk.size()-1] > data[ax][chunk.size()-2]) {
|
| 120 |
+
peaks.push_back(chunk.size()-1);
|
| 121 |
+
}
|
| 122 |
+
return peaks;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
vector<int> getDists (vector<int> peaks) {
|
| 126 |
+
vector<int> dists;
|
| 127 |
+
for (unsigned long i=0; i<(peaks.size()-2); i++) {
|
| 128 |
+
dists.push_back(peaks[i+1] - peaks[i]);
|
| 129 |
+
}
|
| 130 |
+
return dists;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
void absoluteDev (const std::unique_ptr<attribute>& attr) {
|
| 134 |
+
double dev = 0.0;
|
| 135 |
+
int ax = getAxis(attr, 0);
|
| 136 |
+
for (auto var: data[ax]) {
|
| 137 |
+
dev += std::abs(var-(avg[ax]));
|
| 138 |
+
}
|
| 139 |
+
attr->set(dev/(double)chunk.size());
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
void standardDev (const std::unique_ptr<attribute>& attr) {
|
| 143 |
+
int ax = getAxis(attr, 0);
|
| 144 |
+
attr->set(sdev[ax]);
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
void variance (const std::unique_ptr<attribute>& attr) {
|
| 148 |
+
int ax = getAxis(attr, 0);
|
| 149 |
+
attr->set(sqrt(sdev[ax]));
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
int getCoefIndex (const std::unique_ptr<attribute>& attr) {
|
| 153 |
+
int coefIndex = ((attr->position)-mfccOffset)%NUM_MFCC;
|
| 154 |
+
return coefIndex;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
void mfcc (const std::unique_ptr<attribute>& attr) {
|
| 158 |
+
int ax = getAxis(attr, 0);
|
| 159 |
+
attr->set(coefs[ax][getCoefIndex(attr)]);
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
void cosineSimilarity (const std::unique_ptr<attribute>& attr) {
|
| 163 |
+
vector<double> * left = &data[getAxis(attr, 0)];
|
| 164 |
+
vector<double> * right = &data[getAxis(attr, 1)];
|
| 165 |
+
double top = 0.0;
|
| 166 |
+
double bottomLeft = 0.0;
|
| 167 |
+
double bottomRight = 0.0;
|
| 168 |
+
for (size_t i=0; i<(*left).size(); i++) {
|
| 169 |
+
top += (((*left)[i])*((*right)[i]));
|
| 170 |
+
bottomLeft += pow((* left)[i], 2);
|
| 171 |
+
bottomRight += pow((*right)[i], 2);
|
| 172 |
+
}
|
| 173 |
+
attr->set(top/((sqrt(bottomLeft))*(sqrt(bottomRight))));
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
void correlation (const std::unique_ptr<attribute>& attr) {
|
| 177 |
+
vector<double> * left = &data[getAxis(attr, 0)];
|
| 178 |
+
vector<double> * right = &data[getAxis(attr, 1)];
|
| 179 |
+
gsl_vector_const_view gslLeft = gsl_vector_const_view_array((*left).data(), (*left).size());
|
| 180 |
+
gsl_vector_const_view gslRight = gsl_vector_const_view_array((*right).data(), (*right).size());
|
| 181 |
+
attr->set(gsl_stats_correlation(gslLeft.vector.data, 1, gslRight.vector.data, 1, (*left).size()));
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
// template <typename x>
|
| 185 |
+
// void iterateChunk (x func) {
|
| 186 |
+
// for (int j=0; j<chunk.size(); j++) {
|
| 187 |
+
// func(j);
|
| 188 |
+
// }
|
| 189 |
+
// }
|
| 190 |
+
|
| 191 |
+
void resultant (const std::unique_ptr<attribute>& attr) {
|
| 192 |
+
double sum = 0.0;
|
| 193 |
+
for (int i=0; i<chunk.size(); i++) {
|
| 194 |
+
double squared = 0.0;
|
| 195 |
+
for (int j=0; j<NUM_AXIS; j++) {
|
| 196 |
+
squared += pow(data[j][i], 2);
|
| 197 |
+
}
|
| 198 |
+
sum += sqrt(squared);
|
| 199 |
+
}
|
| 200 |
+
attr->set(sum/((double)chunk.size()));
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
void userID (const std::unique_ptr<attribute>& attr) {
|
| 205 |
+
attr->set(record.toke[0]);
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
int binDrop (double var) {
|
| 209 |
+
int bindex = 0;
|
| 210 |
+
var = (double) var/2.5;
|
| 211 |
+
if (var >= -1 && var <= 7) {
|
| 212 |
+
bindex = (floor(var))+2;
|
| 213 |
+
} else if (var > 7) {
|
| 214 |
+
bindex = 9;
|
| 215 |
+
}
|
| 216 |
+
return bindex;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
vector<double> getFFT (vector<double> data) {
|
| 220 |
+
size_t before = data.size();
|
| 221 |
+
while ((data.size() & (data.size()-1)) != 0) {
|
| 222 |
+
data.push_back(0.0);
|
| 223 |
+
}
|
| 224 |
+
Aquila::SignalSource source(data, SAMPLING_RATE);
|
| 225 |
+
Aquila::AquilaFft fft(source.getSamplesCount());
|
| 226 |
+
auto spectrum = fft.fft(source.toArray());
|
| 227 |
+
std::vector<double> realFFT;
|
| 228 |
+
for (auto complex: spectrum) {
|
| 229 |
+
realFFT.push_back(std::abs(complex));
|
| 230 |
+
}
|
| 231 |
+
chunk.resize(before);
|
| 232 |
+
return realFFT;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
void writeInstance (arff& barf) {
|
| 236 |
+
for (int i=0; i<NUM_AXIS; i++) {
|
| 237 |
+
avg[i] = sdev[i] = 0.0;
|
| 238 |
+
coefs[i].clear();
|
| 239 |
+
memset(bins[i], 0, sizeof(int) * NUM_BINS);
|
| 240 |
+
for (auto val: data[i]) {
|
| 241 |
+
bins[i][binDrop(val)]++;
|
| 242 |
+
avg[i] += val;
|
| 243 |
+
}
|
| 244 |
+
avg[i] /= chunk.size();
|
| 245 |
+
for (auto val: data[i]) {
|
| 246 |
+
sdev[i] += pow((val-avg[i]), 2);
|
| 247 |
+
}
|
| 248 |
+
sdev[i] = (sqrt(sdev[i]))/((double)chunk.size());
|
| 249 |
+
vector<double> FFT = getFFT(data[i]);
|
| 250 |
+
for (int j=0; j<NUM_MFCC; j++) {
|
| 251 |
+
coefs[i].push_back(GetCoefficient(FFT.data(), SAMPLING_RATE, 48, FFT.size(), j));
|
| 252 |
+
}
|
| 253 |
+
}
|
| 254 |
+
barf.compute();
|
| 255 |
+
dumpChunk();
|
| 256 |
+
chunk.valid++;
|
| 257 |
+
}
|
wisdm-dataset/arffmagic-master/src/write.h
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef WRITE_H
|
| 2 |
+
#define WRITE_H
|
| 3 |
+
#include "attribute.h"
|
| 4 |
+
#include "arff.h"
|
| 5 |
+
#include <vector>
|
| 6 |
+
using std::vector;
|
| 7 |
+
// process writing to the arff file
|
| 8 |
+
|
| 9 |
+
void initribute (arff&);
|
| 10 |
+
//axis *
|
| 11 |
+
int getAxis (const std::unique_ptr<attribute>&, int);
|
| 12 |
+
void activity (const std::unique_ptr<attribute>&);
|
| 13 |
+
void bin (const std::unique_ptr<attribute>&);
|
| 14 |
+
int getBindex (const std::unique_ptr<attribute>&);
|
| 15 |
+
void average (const std::unique_ptr<attribute>&);
|
| 16 |
+
void peak (const std::unique_ptr<attribute>&);
|
| 17 |
+
vector<int> getPeaks (const std::unique_ptr<attribute>&);
|
| 18 |
+
vector<int> getDists (vector<int>);
|
| 19 |
+
void absoluteDev (const std::unique_ptr<attribute>&);
|
| 20 |
+
void standardDev (const std::unique_ptr<attribute>&);
|
| 21 |
+
void variance (const std::unique_ptr<attribute>&);
|
| 22 |
+
void mfcc (const std::unique_ptr<attribute>&);
|
| 23 |
+
void cosineSimilarity (const std::unique_ptr<attribute>&);
|
| 24 |
+
void correlation (const std::unique_ptr<attribute>&);
|
| 25 |
+
void resultant (const std::unique_ptr<attribute>&);
|
| 26 |
+
double square (double);
|
| 27 |
+
void userID (const std::unique_ptr<attribute>&);
|
| 28 |
+
void writeInstance (arff&);
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
#endif
|