예제 #1
0
def test_radon(
        # add_data, add_box,
        add_condition_slope,
        add_group_slope,
        # do_mean_over_trials,
        do_make_change):
    window = BayesRegression(df=df_radon,
                             y='radon',
                             treatment='floor',
                             condition=['county'])
    # window.plot(x='county').facet(row='floor').display()
    window.fit(
        add_condition_slope=
        add_condition_slope,  # do_mean_over_trials=do_mean_over_trials,
        add_group_slope=add_group_slope,
        do_make_change=do_make_change,
        n_draws=100,
        num_chains=1,
        num_warmup=100)
    # window.plot().display()
    window.plot(
        x=':O',  # add_data=add_data,
    ).display()
    window.plot()
    window.chart_posterior_kde.display()
    # window.chart_data_boxplot.display() # Fold change won't work, bc uneven number of entries
    assert len(window.charts) > 3  # Should include kde
예제 #2
0
def test_fit():
    window = BayesRegression(df=df,
                             y='isi',
                             treatment='stim',
                             condition='neuron',
                             group='mouse')
    window.fit(model=models.model_hierarchical)
예제 #3
0
def test_plot_slopes_2levelslope():
    window = BayesRegression(df=df,
                             y='isi',
                             treatment='stim',
                             condition='neuron_x_mouse',
                             group='mouse',
                             add_data=True)
    window.fit(model=models.model_hierarchical, add_group_slope=True)
    window.plot().display()
예제 #4
0
def test_estimate_posteriors_data_overlay_slope():
    window = BayesRegression(df=df,
                             y='isi',
                             treatment='stim',
                             condition='neuron',
                             group='mouse')
    window.fit(model=models.model_hierarchical)
    chart = window.plot(x='neuron', independent_axes=False)
    chart.display()
    window.chart.facet(row='mouse').display()
예제 #5
0
def test_facet():
    # Slopes:
    window = BayesRegression(df=df,
                             y='isi',
                             treatment='stim',
                             condition='neuron',
                             group='mouse')
    window.fit(model=models.model_hierarchical)
    window.plot(row='neuron', width=40)
    window.plot(x='neuron').facet(column='mouse')
예제 #6
0
def test_plot_slopes():
    window = BayesRegression(df=df,
                             y='isi',
                             treatment='stim',
                             condition='neuron',
                             group='mouse',
                             add_data=True)
    window.fit(model=models.model_hierarchical)
    window.plot()
    window.plot_BEST()
예제 #7
0
def test_single_condition_nodata():
    window = BayesRegression(df=dfl,
                             y='Log power',
                             treatment='stim',
                             group='mouse')
    window.fit(model=models.model_hierarchical,
               do_make_change='divide',
               dist_y='normal')
    alt.layer(*plot_posterior(
        df=window.data_and_posterior,
        y_title='Log power',
    )).display()
    window.plot(independent_axes=True).display()
예제 #8
0
def test_estimate_posteriors_slope(add_condition_slope):
    window = BayesRegression(df=df,
                             y='isi',
                             treatment='stim',
                             condition=['neuron', 'mouse'],
                             group='mouse',
                             add_data=True)
    window.fit(models.model_hierarchical,
               add_condition_slope=add_condition_slope)

    chart = window.plot(x='neuron', column='neuron', row='mouse')
    chart.display()
    chart = window.plot(x='neuron', column='neuron', row='mouse')
    chart.display()
예제 #9
0
def test_slopes(do_make_change, detail):
    window = BayesRegression(df=df,
                             y='isi',
                             treatment='stim',
                             condition='neuron',
                             group='mouse',
                             detail=detail)
    # try:
    window.fit(
        model=models.model_hierarchical,
        do_make_change=do_make_change,
    )
    # fold_change_index_cols=('stim', 'mouse', 'neuron_x_mouse'))
    window.chart.display()
    window.window.chart_data_box_detail.display()
예제 #10
0
def test_gpu():
    window = BayesRegression(df=df,
                             y='isi',
                             treatment='stim',
                             condition=['neuron', 'mouse'],
                             group='mouse',
                             detail='i_trial')
    window.fit(model=models.model_hierarchical,
               do_make_change='subtract',
               add_condition_slope=True,
               add_group_slope=True,
               use_gpu=True)
    assert window.data_and_posterior.dropna(
        subset=['mu_intercept_per_group center interval'
                ])['mouse'].unique().size == 4
예제 #11
0
def test_two_groups():
    df = generate_spikes_stim_types(
        mouse_response_slope=3,
        n_trials=2,
        n_neurons=3,
        n_mice=4,
        dur=2,
    )

    window = BayesRegression(df=df,
                             y='isi',
                             treatment='stim',
                             condition=['stim_strength', 'neuron_x_mouse'],
                             group='mouse',
                             group2='neuron')
    window.fit(model=models.model_hierarchical, add_group2_slope=True)
예제 #12
0
def test_data_replacement1():
    window = BayesRegression(df=df,
                             y='isi',
                             treatment='stim',
                             condition='neuron_x_mouse',
                             group='mouse',
                             detail='i_trial',
                             add_data=True)
    window.fit(
        model=models.model_hierarchical,
        do_make_change='subtract',
        add_condition_slope=True,
        # add_group_slope=True
    )
    posterior_no_nan = window.data_and_posterior.dropna(
        subset=['mu_intercept_per_group center interval'])
    assert posterior_no_nan['mouse'].unique().size == 4
예제 #13
0
def test_estimate_posteriors_data_overlay_indep_axes_slope(
        add_data, add_data_plot, add_group_slope):
    window = BayesRegression(df=df,
                             add_data=add_data,
                             y='isi',
                             treatment='stim',
                             condition='neuron',
                             group='mouse')
    window.fit(model=models.model_hierarchical,
               add_group_slope=add_group_slope)
    chart = window.plot(independent_axes=True, add_data=add_data_plot)
    chart.display()
    if add_group_slope and add_data_plot:
        chart = window.facet(column='neuron', row='mouse')
    else:
        chart = window.facet(column='neuron')
    chart.display()
예제 #14
0
def test_chirp_data1(plot_from_data_and_posterior):
    dfdata = pd.read_csv(Path('tests') / 'test_data' / 'chirp_power.csv')
    window = BayesRegression(df=dfdata,
                             y='Log power',
                             treatment='stim_on',
                             condition=['Stim phase', 'Inversion'],
                             group='Subject')
    window.fit(model=models.model_hierarchical,
               num_chains=1,
               n_draws=100,
               num_warmup=100)
    chart = window.plot(
        x='Stim phase',  # color='Fid',
        add_data=plot_from_data_and_posterior,
        independent_axes=True)
    chart.display()
    chart_data = pd.DataFrame.from_records(
        list(json.loads(chart.to_json())['datasets'].values())[0])
    assert (chart_data['Stim phase'].unique().astype(float) ==
            dfdata['Stim phase'].unique()).all()
예제 #15
0
def test_plot_slopes_intercepts(do_make_change):
    window = BayesRegression(df=dfl,
                             y='Power',
                             treatment='stim',
                             group='mouse',
                             add_data=True)
    # Fit:
    window.fit(model=models.model_hierarchical,
               add_group_intercept=True,
               zscore_y=False,
               add_group_slope=False,
               robust_slopes=False,
               do_make_change=do_make_change,
               dist_y='gamma',
               num_chains=1,
               n_draws=100,
               num_warmup=100)

    window.plot_intercepts(x='mouse').display()
    chart_intercepts = window.chart_posterior_intercept
    chart_intercepts.display()
예제 #16
0
def random_tests():
    # TODO make a notebook for this
    window = BayesRegression(df=df,
                             y='isi',
                             treatment='stim',
                             condition='neuron',
                             group='mouse')
    window.fit(model=models.model_hierarchical, num_chains=1)
    window.plot(x='neuron',
                color='mouse',
                independent_axes=True,
                finalize=True)

    window.plot(independent_axes=False, x='neuron:O', color='mouse')

    window.plot(add_box=False,
                independent_axes=True,
                x='neuron:O',
                color='mouse')

    window.plot(independent_axes=False, x='neuron:O', color='mouse')

    chart = window.plot(independent_axes=True, x='neuron:O', color='mouse')

    chart.display()

    chart.resolve_scale(y='independent')

    window.facet(column='neuron')

    window = BayesRegression(df=df,
                             y='isi',
                             treatment='stim',
                             condition='neuron',
                             group='mouse')
    window.fit(model=models.model_hierarchical, num_chains=1)
    window.plot(x='neuron', color='i_trial')

    window.plot()  # x='Stim phase', color='Fid')#,independent_axes=True)
    window.facet(column='neuron', row='mouse')
예제 #17
0
def test_chirp_data2():
    dfdata = pd.read_csv(Path('tests') / 'test_data' / 'chirp_power.csv')
    window = BayesRegression(
        df=dfdata,
        y='Log power',
        treatment='stim_on',
        # condition=['Condition code'],
        group='Subject',
        add_data=True)
    window.fit(
        model=models.model_hierarchical,
        fold_change_index_cols=[  # 'Condition code',
            'Brain region', 'Stim phase', 'stim_on', 'Fid', 'Subject',
            'Inversion'
        ],
        do_mean_over_trials=True,
        num_chains=1,
        n_draws=100,
        num_warmup=100)
    window.plot(x='Stim phase',
                color='Fid',
                add_data=True,
                independent_axes=True).display()
예제 #18
0
def test_chirp_data(force_correct_fold_change_index_cols):
    dfdata = pd.read_csv(Path('tests') / 'test_data' / 'chirp_power.csv')
    window = BayesRegression(
        df=dfdata,
        y='Log power',
        treatment='stim_on',
        condition=['Stim phase', 'Inversion', 'Brain region'],
        group='Subject')
    if force_correct_fold_change_index_cols:
        window.fit(model=models.model_hierarchical,
                   fold_change_index_cols=[
                       'Brain region', 'Stim phase', 'stim_on', 'Fid',
                       'Subject', 'Inversion'
                   ],
                   num_chains=1,
                   n_draws=100,
                   num_warmup=100)
    else:
        window.fit(model=models.model_hierarchical,
                   num_chains=1,
                   n_draws=100,
                   num_warmup=100)
    window.plot(x='Stim phase', color='Fid', independent_axes=True).display()
예제 #19
0
def test_estimate_posteriors_two_conditions():
    df = generate_spikes_stim_types(
        mouse_response_slope=3,
        n_trials=2,
        n_neurons=3,
        n_mice=4,
        dur=2,
    )

    regression = BayesRegression(
        BayesWindow(df=df,
                    y='isi',
                    treatment='stim',
                    condition=['neuron', 'stim_strength'],
                    group='mouse',
                    add_data=True))
    regression.fit(model=models.model_hierarchical,
                   fold_change_index_cols=None,
                   do_mean_over_trials=False)
    for condition_name in regression.window.condition:
        assert condition_name in regression.data_and_posterior.columns, f'{condition_name} not in window.condition'
    chart = regression.plot(x='neuron', column='neuron', row='mouse')
    chart.display()
예제 #20
0
def test_estimate_posteriors_slope_uneven_n_data_per_condition():
    # Trying to reproduce Uneven number of entries in conditions! Try setting do_take_mean=True
    df, df_monster, index_cols, firing_rates = generate_fake_spikes(
        n_trials=10,
        n_neurons=3,
        n_mice=4,
        dur=2,
    )
    df = df.drop(df[(df['i_trial'] == 0) &
                    # (df['neuron_x_mouse'] == '0m0bayes') &
                    (df['stim'] == 0)].index)
    window = BayesRegression(df=df,
                             y='isi',
                             treatment='stim',
                             condition='neuron',
                             group='mouse',
                             add_data=True)
    window.fit(models.model_hierarchical, do_make_change='divide')

    chart = window.plot(x='neuron', column='neuron', row='mouse')
    chart.display()
    chart = window.plot(x='neuron', column='neuron', row='mouse')
    chart.display()
예제 #21
0
    assert window.data_and_posterior.dropna(
        subset=['mu_intercept_per_group center interval'
                ])['mouse'].unique().size == 4


# def test_stim_strength():
#     df = []
#     for slope in np.linspace(4, 400, 4):
#         df1 = generate_fake_lfp(mouse_response_slope=slope)[0]
#         df1['stim_strength'] = slope
#         df.append(df1)
#     df = pd.concat(df)

#     BayesRegression(df=df, 'Power', treatment='stim_strength', group='mouse', detail='i_trial').data_box_detail()
#     window = BayesRegression(df=df, 'Power', treatment='stim_strength', condition='mouse', detail='i_trial')
#     window.fit(add_condition_slope=True, center_intercept=True, dist_y='normal', num_chains=1, n_draws=100, num_warmup=100)
#     window.chart

window = BayesRegression(df=df, y='isi', treatment='stim', group='mouse')
window.fit(model=models.model_hierarchical)


def test_extra_plots():
    window.plot_intercepts().display()
    window.plot_detail_minus_intercepts().display()


# def test_explore_models():
#     window.explore_models(parallel=False)
#     window.explore_model_kinds(parallel=False)