Download data/utils/load_data.py from introvoyz041/FAS-Simulator: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/datasets/introvoyz041/FAS-Simulator/resolve/main/data/utils/load_data.py
- Command line
-
hf download hf://datasets/introvoyz041/FAS-Simulator/data/utils/load_data.py
-
curl -L -o load_data.py https://huggingface.co/datasets/introvoyz041/FAS-Simulator/resolve/main/data/utils/load_data.py
1.37 kB
| #!/usr/bin/python | |
| import scipy.io as sio | |
| import matplotlib | |
| matplotlib.use('Agg') | |
| import pylab | |
| import numpy as np | |
| import random | |
| import json | |
| import itertools | |
| lastIndex = 0 | |
| symbolIndices = dict() | |
| def get_symbol_index(symbolName): | |
| global lastIndex | |
| global symbolIndices | |
| if (not symbolIndices.has_key(symbolName)): | |
| symbolIndices[symbolName] = lastIndex | |
| lastIndex = lastIndex + 1 | |
| return symbolIndices[symbolName] | |
| def one_hot(index, size): | |
| vector = [0 for i in range(size)] | |
| vector[index] = 1 | |
| return vector | |
| def load_json_data(fileName): | |
| global lastIndex | |
| input = [] | |
| lastTime = 0 | |
| with open(fileName, 'r') as inputData: | |
| jsonData = json.loads(inputData.read()) | |
| for item in jsonData: | |
| symbolIndex = get_symbol_index(item['type']) | |
| numberOfSymbols = lastIndex | |
| with open(fileName, 'r') as inputData: | |
| print("Number of symbols: ", numberOfSymbols) | |
| jsonData = json.loads(inputData.read()) | |
| for item in jsonData: | |
| timestamp = item['timestamp'] | |
| symbolIndex = get_symbol_index(item['type']) | |
| deltaTime = (timestamp - lastTime) / 1000 | |
| lastTime = timestamp | |
| inputVector = one_hot(symbolIndex, numberOfSymbols) + [ deltaTime ] | |
| input.append(inputVector) | |
| return (np.asfarray(input), lastIndex) | |