def plot_surface(gr, ax, keys, imshow=False):
    # from https://github.com/russelljjarvis/neuronunit/blob/dev/neuronunit/unit_test/progress_report_4thJuly.ipynb
    # Not rendered https://github.com/russelljjarvis/neuronunit/blob/dev/neuronunit/unit_test/progress_report_.ipynb
    gr = [g for g in gr if type(g.dtc) is not type(None)]
    gr = [g for g in gr if type(g.dtc.scores) is not type(None)]
    ax.cla()
    gr_ = []
    index = 0
    for i, g in enumerate(gr):
        if type(g.dtc) is not type(None):
            gr_.append(g)
        else:
            index = i

    xx = np.array([p.dtc.attrs[str(keys[0])] for p in gr])
    yy = np.array([p.dtc.attrs[str(keys[1])] for p in gr])
    zz = np.array([np.sum(list(p.dtc.scores.values())) for p in gr])
    dim = len(xx)
    N = int(np.sqrt(len(xx)))
    X = xx.reshape((N, N))
    Y = yy.reshape((N, N))
    Z = zz.reshape((N, N))
    if imshow == False:
        ax.pcolormesh(X, Y, Z, edgecolors='black')
    else:
        import seaborn as sns
        sns.set()
        ax = sns.heatmap(Z)

    ax.set_title(' {0} vs {1} '.format(keys[0], keys[1]))
    return ax
def plot_scatter(hof, ax, keys):
    z = np.array([np.sum(list(p.dtc.scores.values())) for p in hof])
    x = np.array([p.dtc.attrs[str(keys[0])] for p in hof])
    if len(keys) != 1:
        y = np.array([p.dtc.attrs[str(keys[1])] for p in hof])
        ax.cla()
        ax.set_title(' {0} vs {1} '.format(keys[0], keys[1]))
        ax.scatter(x, y, c=y, s=125)  #, cmap='gray')
    return ax
def plot_line(gr, ax, key):
    ax.cla()
    ax.set_title(' {0} vs  score'.format(key[0]))
    z = np.array([np.sum(list(p.dtc.scores.values())) for p in gr])
    x = np.array([p.dtc.attrs[key[0]] for p in gr])

    ax.plot(x, z)
    ax.set_xlim(np.min(x), np.max(x))
    ax.set_ylim(np.min(z), np.max(z))
    return ax
Exemple #4
0
def plot_scatter(history, ax, keys, constant):
    pop = [v for v in history.genealogy_history.values()]
    z = np.array([p.dtc.get_ss() for p in pop])
    x = np.array([p.dtc.attrs[str(keys[0])] for p in pop])
    y = np.array([p.dtc.attrs[str(keys[1])] for p in pop])
    ax.cla()
    ax.set_title('held constant: ' + str(constant))
    ax.scatter(x, y, c=y, s=125)  #, cmap='gray')
    ax.set_xlabel('free: ' + str(keys[0]))
    ax.set_ylabel('free: ' + str(keys[1]))
    return ax
def plot_surface(gr, ax, keys, imshow=False):
    # from
    # https://github.com/russelljjarvis/neuronunit/blob/dev/neuronunit/unit_test/progress_report_4thJuly.ipynb
    # Not rendered
    # https://github.com/russelljjarvis/neuronunit/blob/dev/neuronunit/unit_test/progress_report_.ipynb
    gr = [g for g in gr if type(g.dtc) is not type(None)]

    gr = [g for g in gr if type(g.dtc.scores) is not type(None)]
    ax.cla()
    #gr = [ g
    gr_ = []
    index = 0
    for i, g in enumerate(gr):
        if type(g.dtc) is not type(None):
            gr_.append(g)
        else:
            index = i

    z = [np.sum(list(p.dtc.scores.values())) for p in gr]
    x = [p.dtc.attrs[str(keys[0])] for p in gr]
    y = [p.dtc.attrs[str(keys[1])] for p in gr]

    # impute missings
    if len(x) != 100:
        delta = 100 - len(x)
        for i in range(0, delta):
            x.append(np.mean(x))
            y.append(np.mean(y))
            z.append(np.mean(z))

    xx = np.array(x)
    yy = np.array(y)
    zz = np.array(z)

    dim = len(xx)

    N = int(np.sqrt(len(xx)))
    X = xx.reshape((N, N))
    Y = yy.reshape((N, N))
    Z = zz.reshape((N, N))
    if imshow == False:
        ax.pcolormesh(X, Y, Z, edgecolors='black')
    else:
        import seaborn as sns
        sns.set()
        ax = sns.heatmap(Z)

        #ax.imshow(Z)
    #ax.pcolormesh(xi, yi, zi, edgecolors='black')
    ax.set_title(' {0} vs {1} '.format(keys[0], keys[1]))
    return ax
Exemple #6
0
def plot_line_ss(gr, ax, free, hof, constant):
    ax.cla()

    ax.set_title(' {0} vs  score'.format(free))
    z = np.array([p.dtc.get_ss() for p in gr])
    print(str(free))
    print(free)
    x = np.array([p.dtc.attrs[str(free)] for p in gr])

    y = hof[0].dtc.attrs[free]
    i = hof[0].dtc.get_ss()
    #ax.hold(True)
    ax.scatter(x, z)
    ax.scatter(y, i)
    ax.plot(x, z)

    ax.set_xlabel(str(key[0]))
    ax.set_ylabel(str('Sum of Errors'))
    return ax
Exemple #7
0
def plot_surface(gr, ax, keys, constant, imshow=True):
    # from https://github.com/russelljjarvis/neuronunit/blob/dev/neuronunit/unit_test/progress_report_4thJuly.ipynb
    # Not rendered https://github.com/russelljjarvis/neuronunit/blob/dev/neuronunit/unit_test/progress_report_.ipynb
    gr = [g for g in gr if type(g.dtc) is not type(None)]
    gr = [g for g in gr if type(g.dtc.scores) is not type(None)]
    ax.cla()
    gr_ = []
    index = 0
    for i, g in enumerate(gr):
        if type(g.dtc) is not type(None):
            gr_.append(g)
        else:
            index = i

    xx = np.array([p.dtc.attrs[str(keys[0])] for p in gr])
    yy = np.array([p.dtc.attrs[str(keys[1])] for p in gr])
    zz = np.array([p.dtc.get_ss() for p in gr])
    dim = len(xx)
    N = int(np.sqrt(len(xx)))
    X = xx.reshape((N, N))
    Y = yy.reshape((N, N))
    Z = zz.reshape((N, N))
    if imshow == True:
        img = ax.pcolormesh(X, Y, Z, edgecolors='black')
        #ax.colorbar()

    else:

        import seaborn as sns
        sns.set()

        current_palette = sns.color_palette()
        sns.palplot(current_palette)

        #df = pd.DataFrame(Z, columns=xx)

        img = sns.heatmap(Z)  #,cm=current_palette)
        #ax.colorbar()

    ax.set_title(' {0} vs {1} '.format(keys[0], keys[1]))
    return ax, img
Exemple #8
0
def pre_run(tests, opt_keys):
    # algorithmically find the the edges of parameter ranges, via a course grained
    # sampling of extreme parameter values
    # to find solvable instances of Izhi-model, (models with a rheobase value).
    nparams = len(opt_keys)
    from neuronunit.models.NeuroML2 import model_parameters as modelp
    mp = copy.copy(modelp.model_params)
    mp['b'] = [-0.5, 500.0]
    mp['vr'] = [-100.0, 10.0]
    mp['a'] = [-10, 5]
    cnt = 0
    fc = {}  # final container

    for key in opt_keys:
        cnt = 0
        print(key, mp)
        gr = run_grid(3, tests, provided_keys=key, mp_in=mp)
        line = [g.dtc.get_ss() for g in gr]
        nr = {key: None}
        _, range_adj, new, index = check_line(line, gr, nr, key)
        while range_adj == True:
            # while the sampled line is not concave (when minimas are at the edges)
            # sample a point to a greater extreme
            gr_ = update_deap_pop(new, tests, key)
            param_line = [g.dtc.attrs[key] for g in gr]

            temp = list(mp[key])
            inter = None

            if index == 0:
                p0 = (gr_.dtc.attrs[key], gr_.dtc.get_ss())
                p1 = (gr[0].dtc.attrs[key], gr[0].dtc.get_ss())
                inter = interpolate(p0, p1)
                print(inter)

                gr.insert(index, gr_)
                temp.insert(index, new)
            elif index == -1:
                p0 = (gr_.dtc.attrs[key], gr_.dtc.get_ss())

                p1 = (gr[-1].dtc.attrs[key], gr[-1].dtc.get_ss())
                inter = interpolate(p0, p1)
                print(inter)

                gr.append(gr_)
                temp.append(gr_)

            mp[key] = np.array(temp)
            line = [g.dtc.get_ss() for g in gr]

            _, range_adj, new, index = check_line(line, gr, mp, key)
            cnt += 1
            with open('temp_range.p', 'wb') as f:
                pickle.dump(mp, f)
            if type(inter) is not type(None):
                with open('temp_inter.p', 'wb') as f:
                    pickle.dump([mp, inter], f)

        param_line = [g.dtc.attrs[key] for g in gr]
        line = [g.dtc.get_ss() for g in gr]
        plt.clf()
        plt.plot(param_line, line)
        plt.savefig('check_' + str(key) + '.png')

        fc[key] = {}
        fc[key]['line'] = line
        fc[key]['range'] = mp
        fc[key]['cnt'] = cnt
    return fc, mp
Exemple #9
0
def get_justas_plot(history):

    # try:
    import plotly.plotly as py
    from plotly.offline import download_plotlyjs, init_notebook_mode, plot  #, iplot
    import plotly.graph_objs as go
    import cufflinks as cf
    cf.go_offline()
    gr = [v for v in history.genealogy_history.values()]
    gr = [g for g in gr if type(g.dtc) is not type(None)]
    gr = [g for g in gr if type(g.dtc.scores) is not type(None)]
    keys = list(gr[0].dtc.attrs.keys())
    xx = np.array([p.dtc.attrs[str(keys[0])] for p in gr])
    yy = np.array([p.dtc.attrs[str(keys[1])] for p in gr])
    zz = np.array([p.dtc.attrs[str(keys[2])] for p in gr])
    ee = np.array([np.sum(list(p.dtc.scores.values())) for p in gr])
    #pdb.set_trace()
    # z_data = np.array((xx,yy,zz,ee))
    list_of_dicts = []
    for x, y, z, e in zip(list(xx), list(yy), list(zz), list(ee)):
        list_of_dicts.append({
            keys[0]: x,
            keys[1]: y,
            keys[2]: z,
            str('error'): e
        })

    z_data = pd.DataFrame(list_of_dicts)
    data = [go.Surface(z=z_data.as_matrix())]

    layout = go.Layout(
        width=1000,
        height=1000,
        autosize=False,
        title='Sciunit Errors',
        scene=dict(
            xaxis=dict(
                title=str(keys[0]),

                #gridcolor='rgb(255, 255, 255)',
                #zerolinecolor='rgb(255, 255, 255)',
                #showbackground=True,
                #backgroundcolor='rgb(230, 230,230)'
            ),
            yaxis=dict(
                title=str(keys[1]),

                #gridcolor='rgb(255, 255, 255)',
                #zerolinecolor='rgb(255, 255, 255)',
                #showbackground=True,
                #backgroundcolor='rgb(230, 230,230)'
            ),
            zaxis=dict(
                title=str(keys[2]),

                #gridcolor='rgb(255, 255, 255)',
                #zerolinecolor='rgb(255, 255, 255)',
                #showbackground=True,
                #backgroundcolor='rgb(230, 230,230)'
            ),
            aspectratio=dict(x=1, y=1, z=0.7),
            aspectmode='manual'),
        margin=dict(l=65, r=50, b=65, t=90))

    fig = go.Figure(
        data=data, layout=layout
    )  #,xTitle=str(keys[0]),yTitle=str(keys[1]),title='SciUnitOptimization')
    plot(fig, filename='sciunit-score-3d-surface.html')