<jupyter_start><jupyter_text>An example of using BluePyOpt/NeuronUnit OptimizationUsing:* Allen Brain Experimental data (`specimen_id=325479788`, sweep number `64`) to derive features from.* EFEL feature extraction* BluePyOpt Optimization.* Numba JIT simple cell models (Izhikevich, Adaptive Exponential).* Neuronunit model scoring<jupyter_code>import matplotlib.pyplot as plt
import seaborn as sns
sns.set(context="paper", font="monospace")
%matplotlib inline
SILENT = True
import warnings
if SILENT:
    warnings.filterwarnings("ignore")

from neuronunit.plotting.plot_utils import check_bin_vm_soma
from neuronunit.allenapi.allen_data_driven import opt_setup
from nb_utils import optimize_job
from sciunit.scores import RelativeDifferenceScore
import pandas as pd
import pickle
import quantities as pq
specimen_id = 325479788

def test_opt_relative_diff(specimen_id,model_type = "ADEXP",efel_filter_iterable=None):    
    _,scores,obs_preds,opt,target = optimize_job(specimen_id,
                                                 model_type,
                                                 score_type=RelativeDifferenceScore,
                                                 efel_filter_iterable=efel_filter_iterable)
    return obs_preds,opt,target<jupyter_output><empty_output><jupyter_text>Below is a plot of vm trace for fitting the simple model to with neuron unit.* It is from Allen Specimen id `325479788`, sweep number `64`.* sweep number<jupyter_code>with open('325479788later_allen_NU_tests.p', "rb") as f:
    suite = pickle.load(f)
    
plt.plot(suite.traces["vm_soma"].times,suite.traces["vm_soma"])
plt.xlabel(pq.s)
plt.ylabel(suite.traces["vm_soma"].dimensionality)
plt.title("$V_{M}$ Allen Specimen id 325479788, sweep number 64")
plt.show()<jupyter_output><empty_output><jupyter_text>Example 1* Izhikevich model * Allen specimen 325479788<jupyter_code>efel_filter_iterable = [
    "ISI_log_slope",
    "mean_frequency",
    "adaptation_index2",
    "first_isi",
    "ISI_CV",
    "median_isi",
    "Spikecount",
    "all_ISI_values",
    "ISI_values",
    "time_to_first_spike",
    "time_to_last_spike",
    "time_to_second_spike",
    ]
obs_preds,opt,target = test_opt_relative_diff(specimen_id = 325479788,model_type="IZHI",efel_filter_iterable=efel_filter_iterable)
#"voltage_after_stim"


check_bin_vm_soma(target,opt)
opt.attrs_to_params()
params = pd.DataFrame([opt.params])
params
df = pd.DataFrame(obs_preds)
df.rename(columns={0:'EFEL_feature_NU_test_Name',1:'prediction',2:'observation',3:'neuronunit_score'},inplace=True)
df<jupyter_output><empty_output><jupyter_text>Example 2* Now fit Adaptive Exponential model to a single sweep from Allen specimen 325479788 sweep number 64<jupyter_code>efel_filter_iterable = [
    "ISI_log_slope",
    "mean_frequency",
    "adaptation_index2",
    "first_isi",
    "ISI_CV",
    "median_isi",
    "Spikecount",
    "all_ISI_values",
    "ISI_values",
    "time_to_first_spike",
    "time_to_last_spike",
    "time_to_second_spike",
    "peak_voltage",
    "AHP_depth",
    "AHP_depth_abs",
    "base_voltage",
    "sag_amplitude",
    "voltage_after_stim",
    "spike_half_width"
    ]
obs_preds,opt,target = test_opt_relative_diff(specimen_id = 325479788,efel_filter_iterable=efel_filter_iterable)

df = pd.DataFrame(obs_preds)
df.rename(columns={0:'EFEL_feature_NU_test_Name',1:'prediction',2:'observation',3:'neuronunit_score'},inplace=True)
df
check_bin_vm_soma(target,opt)

opt.attrs_to_params()
params = pd.DataFrame([opt.params])
params<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10434292160180485, 'fraction_numerical': 0.028482797518330515, 'mean_word_length': 5.104991394148021, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '111289', 'license': 'MIT', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1247, 'n_words': 214, 'path': 'neuronunit/ReducedModelOptimizationMulitSpiking-Copy3.ipynb', 'repo_name': 'russelljjarvis/ReducedModelOptimization', 'size': '3546'}