Exemple #1
0
            active_set.pop(c + 1)
            len_active_set -= 1
            # update solution back to lag tau
            v, w, f, l = active_set[c]
            solution[max(f, f + l - tau - 1):f + l] = max(v, 0) / \
                w * g**np.arange(max(0, l - tau - 1), l)

    return solution


# correlation with ground truth spike train for OASIS with L1

tauls = [0, 1, 2, 5, 10, np.inf]
plt.figure(figsize=(7, 5))
for j, sn in enumerate([.1, .2, .3]):
    Y, trueC, trueSpikes = gen_data(sn=sn)
    N = len(Y)
    C = np.asarray([
        [
            deconvolveAR1(
                y, .95, tau=tau,
                lam=(.2 + .25 * np.exp(-tau / 2.)
                     ))  # lam=(.12 / (1 - (.8 if sn == .3 else .7)**(tau + 1))
            for tau in tauls
        ] for y in Y
    ])
    S = np.zeros_like(C)
    S[:, :, 1:] = C[:, :, 1:] - .95 * C[:, :, :-1]
    S[S < 0] = 0

    corr = np.array([[np.corrcoef(ss, s[-1])[0, 1] for ss in s] for s in S])
Exemple #2
0
"""Script illustrating the autoregressive calcium fluorescence model
for OASIS, an active set method for sparse nonnegative deconvolution
@author: Johannes Friedrich
"""

from matplotlib import pyplot as plt
from functions import init_fig, simpleaxis, gen_data

init_fig()
# colors for colorblind from  http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/
col = ['#0072B2', '#009E73', '#D55E00']


Y, trueC, trueSpikes = gen_data([1.58, -.6], .5, T=455,
                                framerate=30, firerate=2., seed=0)
plt.figure(figsize=(15, 2.5))
for i, t in enumerate(trueSpikes[0, 20:-1]):
    if t:
        plt.plot([i, i], [0, 1], c=col[2])
plt.plot([trueSpikes[0, -1], trueSpikes[0, -1]], [0, 1], c=col[2], label=r'$s$')
plt.plot(trueC[0, 20:] / 3., c=col[0], label=r'$c$', zorder=-11)
plt.scatter(range(435), Y[0, 20:] / 3., c=col[1], clip_on=False, label=r'$y$')
plt.legend(loc=(.38, .75), ncol=3)
plt.yticks([0, 1, 2], [0, 1, 2])
plt.xticks(*[[0, 150, 300]] * 2)
plt.xlim(0, 435)
plt.ylim(0, 2.9)
plt.ylabel('Fluorescence', y=.45)
plt.xlabel('Time', labelpad=-15)
simpleaxis(plt.gca())
plt.tight_layout(.01)
Exemple #3
0
from net import Net
from functions import preprocessing, gen_data, odeintI, get_params

from matplotlib import pyplot as plt
from matplotlib import gridspec

net = Net()
net.load_state_dict(torch.load("model"))
net.eval()

#VALEURS
params = get_params()
arange, brange, pop, n, T = params

#TEST SET
test_data, test_labels = gen_data(arange, brange, pop, n, T, 50)
p_test_data, p_test_labels = preprocessing(test_data, test_labels, params)
inputs, targets = torch.tensor(p_test_data).float(), torch.tensor(
    p_test_labels).float()

fig = plt.figure(figsize=(15, 10))
gs = gridspec.GridSpec(1, 3, width_ratios=[1, 1, 2])
ax1 = plt.subplot(gs[0])
ax2 = plt.subplot(gs[1])
ax3 = plt.subplot(gs[2])

#A, B PREDICTION/LABEL GRAPHS
predictions = net(inputs).detach().numpy().reshape(len(targets), 2)

x1, y1 = [l[0] for l in targets], [l[1] for l in targets]
x2, y2 = [l[0] for l in predictions], [l[1] for l in predictions]
Exemple #4
0
    plt.gca().set_xticklabels([])
    simpleaxis(plt.gca())
    plt.yticks([0, .5, 1], [0, 0.5, 1.0])
    plt.xticks(range(0, 500, 150), [0, 5, 10, ''])
    plt.ylim(-.2, 1.1)
    plt.xlim(0, 452)
    plt.ylabel(r'$s_{\min}$')
    plt.xlabel('Time [s]', labelpad=-10)
    plt.show()


# AR(1)

g = .95
sn = .3
Y, trueC, trueSpikes = gen_data()
y = Y[0]
N, T = Y.shape

c, s = constrained_foopsi(y, [g], sn)[:2]
c_t, s_t = oasisAR1(y, g, s_min=.55)
res = [np.where(oasisAR1(y, g, s_min=s0)[1] > 1e-2)[0]
       for s0 in np.arange(0, 1.1, .1)]
plotTrace(True)


# AR(2)

g = [1.7, -.712]
sn = 1.
Y, trueC, trueSpikes = gen_data(g, sn, seed=3)
Exemple #5
0
from matplotlib import pyplot as plt

net = Net()
print("Net ready, creating training set")

epochs = 5000
train_size = 5000
val_size = 50

#VALEURS
params = get_params()
arange, brange, pop, n, T = params

#TRAINING SET
train_data, train_labels = gen_data(
    arange, brange, pop, n, T,
    train_size)  #data,labels = infected curve(array), (a,b)
p_train_data, p_train_labels = preprocessing(
    train_data, train_labels, params
)  #p_data, p_labels = preprocesed data/labels : (max,max position,max delta,average) and normalized a and b
train_inputs, train_targets = torch.tensor(p_train_data).float(), torch.tensor(
    p_train_labels).float(
    )  #inputs, labels = pytroch tensors for p_data and p_labels
print("Train set ready")

#VALIDATION SET
val_data, val_labels = gen_data(arange, brange, pop, n, T, val_size)
p_val_data, p_val_labels = preprocessing(val_data, val_labels, params)
val_inputs, val_targets = torch.tensor(p_val_data).float(), torch.tensor(
    p_val_labels).float()
print("Validation set ready.")