NormWear
Collection
A Foundation Model for Multivariate Wearable Sensing of Physiological Signals. • 4 items • Updated
data listlengths 6 6 |
|---|
[[-1.9756044149398804,-1.9735095500946045,-1.971415400505066,-1.9693272113800049,-1.9672497510910034(...TRUNCATED) |
[[-1.5406455993652344,-1.546750545501709,-1.5599920749664307,-1.5743052959442139,-1.5826082229614258(...TRUNCATED) |
[[-1.8044497966766357,-1.7974263429641724,-1.7903839349746704,-1.7833473682403564,-1.776341676712036(...TRUNCATED) |
[[1.9955214262008667,2.004786729812622,2.011600971221924,2.016298294067383,2.019174575805664,2.02049(...TRUNCATED) |
[[-1.0775837898254395,-1.0588799715042114,-1.039595365524292,-1.0196987390518188,-0.9991582036018372(...TRUNCATED) |
[[1.6932704448699951,1.6909736394882202,1.6885160207748413,1.6857587099075317,1.6825703382492065,1.6(...TRUNCATED) |
[[1.2676451206207275,1.25425386428833,1.2407963275909424,1.2273237705230713,1.213877558708191,1.2004(...TRUNCATED) |
[[1.2913559675216675,1.3029745817184448,1.3138412237167358,1.3238849639892578,1.3330364227294922,1.3(...TRUNCATED) |
[[-1.396154761314392,-1.3864741325378418,-1.3761361837387085,-1.3652410507202148,-1.3539096117019653(...TRUNCATED) |
[[-2.024733781814575,-2.01704478263855,-2.009326219558716,-2.001673936843872,-1.9941612482070923,-1.(...TRUNCATED) |
import numpy as np
from torch.utils.data import Dataset
from datasets import load_dataset
class PretrainDataset(Dataset):
def __init__(self, window_size=4096, nvar=11):
self.window_size = window_size
self.nvar = nvar
# init dataset
self.ds = load_dataset("mosaic-laboratory/dynamic_systems_pretrain")
def __len__(self):
return sum([len(self.ds[k]) for k in self.ds.keys()])
def __getitem__(self, idx):
# sample from the correct systen set ['chaos', 'signals', 'series'] based on idx
if idx < self.ds['chaos']:
ds_k = 'chaos'
ds_idx = idx
elif idx < self.ds['chaos'] + self.ds['signals']:
ds_k = 'signals'
ds_idx = idx - self.ds['chaos']
else:
ds_k = 'series'
ds_idx = idx - self.ds['chaos'] - self.ds['signals']
traj = np.array(self.ds[ds_k][ds_idx]['data']) # nvar, L
# append dummy
if traj.shape[0] < self.nvar: # if less, duplicate
dummy_traj = np.random.choice(np.arange(traj.shape[0]), self.nvar-traj.shape[0], replace=True)
traj = np.concatenate((traj, traj[dummy_traj]), axis=0)
elif traj.shape[0] > self.nvar: # if more, random sample
traj = traj[np.random.choice(np.arange(traj.shape[0]), self.nvar, replace=False)]
# shuffle channels
var_idx = np.random.permutation(traj.shape[0])
traj = np.take(traj, var_idx, axis=0)
# in-sample normalization
traj = np.nan_to_num(traj, nan=0.0, posinf=0.0, neginf=0.0)
traj_std = traj.std(axis=1, keepdims=True)
traj_std[traj_std == 0] = 1.0
traj = (traj - traj.mean(axis=1, keepdims=True)) / (traj_std + 1e-8)
# clip
if traj.shape[1] > self.window_size:
start_idx = np.random.choice(np.arange(traj.shape[1]-self.window_size))
traj = traj[:, start_idx:start_idx+self.window_size]
# packing
curr_pack = {
'sample': torch.from_numpy(traj).float() # nvar, L
}
# packing
return curr_pack