Exemplo n.º 1
0
## Load LFPs
ids, labels = read_ids_parameters(os.path.join(DATA_DIR, 'id_parameters.txt'))
lfps = np.zeros((len(ids), 6, 2851), dtype=np.float32)
for j, i in enumerate(ids):
    with h5py.File(
            os.path.join(DATA_DIR, 'nest_output', i,
                         'LFP_firing_rate.h5')) as f:
        lfp = f['data'][:, 150:]
    lfps[j] = lfp

lfps = np.array(lfps)
labels = np.array(labels)

## Get PSDs
fs, psds = calc_psds(lfps)
del lfps

## Remove cases of simulations where no neurons spiked
psds, labels = remove_zero_lfps(psds, labels)

test_psds = psds[:10000]
test_labels = labels[:10000]
training_psds = psds[10000:]
training_labels = labels[10000:]

## Hyperparams
batch_size = 100
epochs = 400
lr = 1e-3
Exemplo n.º 2
0
ids = ids[:10000]
labels_large = labels_large[:10000]

lfps = np.zeros((len(ids), 6, 2851), dtype=np.float32)
for j, i in enumerate(ids[:10000]):
    with h5py.File(
            os.path.join(DATA_DIR_LARGE, 'nest_output', i,
                         'LFP_firing_rate.h5')) as f:
        lfp = f['data'][:, 150:]
    lfps[j] = lfp

lfps = np.array(lfps)
labels_large = np.array(labels_large)

## Get PSDs
fs, psds_large = calc_psds(lfps)
del lfps

## Remove cases of simulations where no neurons spiked
psds_large, labels_large = remove_zero_lfps(psds_large, labels_large)

psds_large = np.swapaxes(psds_large, 1, 2)

#### Load small parameterspace LFPs
ids, labels_small = read_ids_parameters(
    os.path.join(DATA_DIR_SMALL, 'id_parameters.txt'))

## Test sims
ids = ids[:10000]
labels_small = labels_small[:10000]
SAVE_DIR = os.path.join('./save/')

### GRID SAMPLED DATA
# Load LFPs
print('loading grid sampled data')
ids, grid_labels = read_ids_parameters(os.path.join(DATA_DIR_GRID, 'id_parameters.txt'))
lfps = np.zeros((len(ids), 6, 2851), dtype=np.float32)
for j, i in enumerate(ids):
    with h5py.File(os.path.join(DATA_DIR_GRID, 'nest_output', i, 'LFP_firing_rate.h5')) as f:
        lfp = f['data'][:,150:]
    lfps[j] = lfp

grid_labels = np.array(grid_labels)

## Get PSDs
fs, grid_psds = calc_psds(lfps)
del lfps

## Remove cases of simulations where no neurons spiked
psds, labels = remove_zero_lfps(grid_psds, grid_labels)


### RANDOMLY SAMPLED DATA
# Load LFPs
print('loading randomly sampled data')
ids, random_labels = read_ids_parameters(os.path.join(DATA_DIR_RANDOM, 'id_parameters.txt'))
lfps = np.zeros((len(ids), 6, 2851), dtype=np.float32)
for j, i in enumerate(ids):
    print('%d'%j, end='\r')
    with h5py.File(os.path.join(DATA_DIR_RANDOM, 'nest_output', i, 'LFP_firing_rate.h5')) as f:
        lfp = f['data'][:,150:]
ids = ids[:10000]
labels_large = labels_large[:10000]

lfps = np.zeros((len(ids), 6, 2851), dtype=np.float32)
for j, i in enumerate(ids[:10000]):
    with h5py.File(
            os.path.join(DATA_DIR_LARGE, 'nest_output', i,
                         'LFP_firing_rate.h5')) as f:
        lfp = f['data'][:, 150:]
    lfps[j] = lfp

lfps = np.array(lfps)
labels_large = np.array(labels_large)

## Get PSDs
fs, psds_large = calc_psds(lfps)
del lfps

## Remove cases of simulations where no neurons spiked
psds_large, labels_large = remove_zero_lfps(psds_large, labels_large)

psds_large = np.swapaxes(psds_large, 1, 2)

## Rescale labels
labels_large_rescaled = labels_large - np.array([[0.8, 3.5, 0.05]])
labels_large_rescaled /= np.array([[3.2, 4.5, 0.35]])


## CNN model
def set_up_model(x_train, lr, n_dense=128, output=3):
    keras.backend.clear_session()
gaussian_taumem_path = os.path.join('../simulation_code/lfp_simulations_gaussian_taumem')
gaussian_theta_path = os.path.join('../simulation_code/lfp_simulations_gaussian_theta')
gaussian_t_ref_path = os.path.join('../simulation_code/lfp_simulations_gaussian_t_ref')

def fetch_lfps(path, nest_output='nest_output'):
    ids, labels = read_ids_parameters(os.path.join(path, 'id_parameters.txt'))
    lfps = []
    for i in ids:
        fpath = os.path.join(path, nest_output, i, 'LFP_firing_rate.h5')
        with h5py.File(fpath) as f:
            lfps.append(f['data'][:,150:])
    return np.array(labels), np.array(lfps)

## Get LFPs and PSDs
gt_labels, gt_lfps = fetch_lfps(gaussian_taumem_path)
fs, gt_psds = calc_psds(gt_lfps)
del gt_lfps

gd_labels, gd_lfps = fetch_lfps(gaussian_delay_path)
fs, gd_psds = calc_psds(gd_lfps)
del gd_lfps

gth_labels, gth_lfps = fetch_lfps(gaussian_theta_path)
fs, gth_psds = calc_psds(gth_lfps)
del gth_lfps

gtr_labels, gtr_lfps = fetch_lfps(gaussian_t_ref_path)
fs, gtr_psds = calc_psds(gtr_lfps)
del gtr_lfps

vd_labels, vd_lfps = fetch_lfps(varying_delay_path)