diff --git a/examples/simplecell/config/extract_config/simplecell_config.json b/examples/simplecell/config/extract_config/simplecell_config.json index 13cd27ee..795bb360 100644 --- a/examples/simplecell/config/extract_config/simplecell_config.json +++ b/examples/simplecell/config/extract_config/simplecell_config.json @@ -367,7 +367,7 @@ { "efeature": "Spikecount", "protocol": "IDrest", - "amplitude": 0.256, + "amplitude": 0.2, "tolerance": 0.1, "efeature_name": null, "weight": 1.0, @@ -378,7 +378,7 @@ { "efeature": "mean_frequency", "protocol": "IDrest", - "amplitude": 0.256, + "amplitude": 0.2, "tolerance": 0.1, "efeature_name": null, "weight": 1.0, @@ -389,7 +389,7 @@ { "efeature": "voltage_base", "protocol": "IDrest", - "amplitude": 0.256, + "amplitude": 0.2, "tolerance": 0.1, "efeature_name": null, "weight": 1.0, @@ -433,7 +433,7 @@ { "efeature": "voltage_base", "protocol": "IV", - "amplitude": -0.147, + "amplitude": -0.1, "tolerance": 0.1, "efeature_name": null, "weight": 1.0, @@ -444,7 +444,7 @@ { "efeature": "ohmic_input_resistance_vb_ssse", "protocol": "IV", - "amplitude": -0.147, + "amplitude": -0.1, "tolerance": 0.1, "efeature_name": null, "weight": 1.0, diff --git a/examples/simplecell/config/features/simplecell.json b/examples/simplecell/config/features/simplecell.json index 56e394b8..cac8962a 100644 --- a/examples/simplecell/config/features/simplecell.json +++ b/examples/simplecell/config/features/simplecell.json @@ -2,53 +2,53 @@ "efeatures": [ { "efel_feature_name": "Spikecount", - "protocol_name": "IDrest_0.256", + "protocol_name": "IDrest_0.2", "recording_name": "soma.v", "threshold_efeature_std": null, "default_std_value": 0.001, - "mean": 6.6, - "original_std": 4.5431266766402185, - "sample_size": 5, + "mean": 5.0, + "original_std": 3.605551275463989, + "sample_size": 4, "efeature_name": "Spikecount", "weight": 1.0, "efel_settings": { "interp_step": 0.025, "strict_stiminterval": true, - "Threshold": -50.11250305175781 + "Threshold": -48.99374771118164 } }, { "efel_feature_name": "mean_frequency", - "protocol_name": "IDrest_0.256", + "protocol_name": "IDrest_0.2", "recording_name": "soma.v", "threshold_efeature_std": null, "default_std_value": 0.001, - "mean": 4.6549665308108965, - "original_std": 1.7066939148229534, - "sample_size": 4, + "mean": 3.9105121810617045, + "original_std": 1.2910808300604681, + "sample_size": 3, "efeature_name": "mean_frequency", "weight": 1.0, "efel_settings": { "interp_step": 0.025, "strict_stiminterval": true, - "Threshold": -50.11250305175781 + "Threshold": -48.99374771118164 } }, { "efel_feature_name": "voltage_base", - "protocol_name": "IDrest_0.256", + "protocol_name": "IDrest_0.2", "recording_name": "soma.v", "threshold_efeature_std": null, "default_std_value": 0.001, - "mean": -84.9396882128033, - "original_std": 0.3331013733422112, - "sample_size": 5, + "mean": -84.83373198951986, + "original_std": 0.28733612701960526, + "sample_size": 4, "efeature_name": "voltage_base", "weight": 1.0, "efel_settings": { "interp_step": 0.025, "strict_stiminterval": true, - "Threshold": -50.11250305175781 + "Threshold": -48.99374771118164 } }, { @@ -104,56 +104,56 @@ }, { "efel_feature_name": "voltage_base", - "protocol_name": "IV_-0.147", + "protocol_name": "IV_-0.1", "recording_name": "soma.v", "threshold_efeature_std": null, "default_std_value": 0.001, - "mean": -84.5937809414334, - "original_std": 0.25958992541480197, - "sample_size": 5, + "mean": -84.4690685507692, + "original_std": 0.08042238367019017, + "sample_size": 4, "efeature_name": "voltage_base", "weight": 1.0, "efel_settings": { "interp_step": 0.025, "strict_stiminterval": true, - "Threshold": -64.5374984741211 + "Threshold": -64.51874923706055 } }, { "efel_feature_name": "ohmic_input_resistance_vb_ssse", - "protocol_name": "IV_-0.147", + "protocol_name": "IV_-0.1", "recording_name": "soma.v", "threshold_efeature_std": null, "default_std_value": 0.001, - "mean": 47.95114886552402, - "original_std": 1.5928203273461563, - "sample_size": 5, + "mean": 48.64694052877976, + "original_std": 0.8664384286999164, + "sample_size": 4, "efeature_name": "ohmic_input_resistance_vb_ssse", "weight": 1.0, "efel_settings": { "interp_step": 0.025, "strict_stiminterval": true, - "Threshold": -64.5374984741211 + "Threshold": -64.51874923706055 } } ], "protocols": [ { - "name": "IDrest_0.256", + "name": "IDrest_0.2", "stimuli": [ { "delay": 700.0000000000001, - "amp": 0.2579375009983778, + "amp": 0.23945312993600965, "thresh_perc": null, "duration": 2000.0, "totduration": 3000.0, - "holding_current": -0.0266875009983778 + "holding_current": -0.026718751061707735 } ], "recordings_from_config": [ { "type": "CompRecording", - "name": "IDrest_0.256.soma.v", + "name": "IDrest_0.2.soma.v", "location": "soma", "variable": "v" } @@ -187,21 +187,21 @@ "stochasticity": false }, { - "name": "IV_-0.147", + "name": "IV_-0.1", "stimuli": [ { "delay": 20.0, - "amp": -0.1440624985843897, + "amp": -0.1265624992083758, "thresh_perc": null, "duration": 1000.0, "totduration": 1320.0, - "holding_current": -0.02878124974668026 + "holding_current": -0.02816406195051968 } ], "recordings_from_config": [ { "type": "CompRecording", - "name": "IV_-0.147.soma.v", + "name": "IV_-0.1.soma.v", "location": "soma", "variable": "v" } diff --git a/examples/simplecell/final.json b/examples/simplecell/final.json index 435bb37b..71b8b30f 100644 --- a/examples/simplecell/final.json +++ b/examples/simplecell/final.json @@ -9,34 +9,42 @@ "iteration": null, "synapse_class": null, "allen_notation": null, - "score": 1257.8671455915864, + "score": 510.2861723258447, "parameters": { - "gnabar_hh.somatic": 0.10623315844384061, - "gkbar_hh.somatic": 0.026127548830000066 + "gnabar_hh.somatic": 0.05000000003749999, + "gkbar_hh.somatic": 0.07499999996750001 }, "fitness": { - "IDrest_0.256.soma.v.Spikecount": 0.1320676359488435, - "IDrest_0.256.soma.v.mean_frequency": 250.0, - "IDrest_0.256.soma.v.voltage_base": 6.755673681284991, - "IV_-0.147.soma.v.voltage_base": 0.979404274352486, - "IV_-0.147.soma.v.ohmic_input_resistance_vb_ssse": 250.0, + "IDrest_0.2.soma.v.Spikecount": 1.1094003924504583, + "IDrest_0.2.soma.v.mean_frequency": 250.0, + "IDrest_0.2.soma.v.voltage_base": 6.86265875272435, + "IV_-0.1.soma.v.voltage_base": 2.3141131806698945, + "IV_-0.1.soma.v.ohmic_input_resistance_vb_ssse": 250.0 + }, + "features": { + "IDrest_0.2.soma.v.Spikecount": 1.0, + "IDrest_0.2.soma.v.mean_frequency": 1739.1304358817733, + "IDrest_0.2.soma.v.voltage_base": -82.86184220245485, + "IDrest_0.4.soma.v.Spikecount": 1.0, + "IDrest_0.4.soma.v.mean_frequency": 2105.263159505021, + "IDrest_0.4.soma.v.voltage_base": -82.71053576131624, + "IV_-0.1.soma.v.voltage_base": -84.28296205269712, + "IV_-0.1.soma.v.ohmic_input_resistance_vb_ssse": 1060.243113329033 + }, + "validation_fitness": { "IDrest_0.4.soma.v.Spikecount": 250.0, "IDrest_0.4.soma.v.mean_frequency": 250.0, "IDrest_0.4.soma.v.voltage_base": 250.0 }, - "features": { - "IDrest_0.256.soma.v.Spikecount": 6.0, - "IDrest_0.256.soma.v.mean_frequency": 1105.990783485126, - "IDrest_0.256.soma.v.voltage_base": -82.68936403171544, - "IDrest_0.4.soma.v.Spikecount": 4.0, - "IDrest_0.4.soma.v.mean_frequency": 1333.3333334958297, - "IDrest_0.4.soma.v.voltage_base": -82.5609583626679, - "IV_-0.147.soma.v.voltage_base": -84.8480244239635, - "IV_-0.147.soma.v.ohmic_input_resistance_vb_ssse": 1060.9623644880035 - }, - "validation_fitness": {}, "validated": false, "seed": 1, - "pdfs": [] + "pdfs": [ + "/gpfs/bbp.cscs.ch/home/ikilic/workspace/BluePyEModel/examples/simplecell/figures/simplecell/optimisation/emodel=simplecell__etype=cADpyr__species=rat__brain_region=SSCX__seed=1__optimisation.pdf", + "/gpfs/bbp.cscs.ch/home/ikilic/workspace/BluePyEModel/examples/simplecell/figures/simplecell/traces/all/emodel=simplecell__etype=cADpyr__species=rat__brain_region=SSCX__seed=1__traces.pdf", + "/gpfs/bbp.cscs.ch/home/ikilic/workspace/BluePyEModel/examples/simplecell/figures/simplecell/scores/all/emodel=simplecell__etype=cADpyr__species=rat__brain_region=SSCX__seed=1__scores.pdf", + "/gpfs/bbp.cscs.ch/home/ikilic/workspace/BluePyEModel/examples/simplecell/figures/simplecell/thumbnail/all/emodel=simplecell__etype=cADpyr__species=rat__brain_region=SSCX__seed=1__thumbnail.png", + "/gpfs/bbp.cscs.ch/home/ikilic/workspace/BluePyEModel/examples/simplecell/figures/simplecell/distributions/all/emodel=simplecell__etype=cADpyr__species=rat__brain_region=SSCX__parameters_distribution.pdf", + "/gpfs/bbp.cscs.ch/home/ikilic/workspace/BluePyEModel/examples/simplecell/figures/simplecell/parameter_evolution/emodel=simplecell__etype=cADpyr__species=rat__brain_region=SSCX__seed=1__evo_parameter_density.pdf" + ] } } \ No newline at end of file diff --git a/examples/simplecell/simplecell.ipynb b/examples/simplecell/simplecell.ipynb index 97727763..89c43167 100644 --- a/examples/simplecell/simplecell.ipynb +++ b/examples/simplecell/simplecell.ipynb @@ -6,11 +6,13 @@ "source": [ "# Building an E-Model for a single-compartment cell\n", "\n", - "This notebook provides a simple example on how to run the pipeline to create an e-model of a single-compartment cell with two free parameters. In this instance, we will use \"rheobase independant\" optimisation. \n", + "This notebook provides a simple example on how to run the pipeline to create an e-model of a single-compartment cell with two free parameters. In this instance, we will use \"rheobase independent\" optimisation. \n", "\n", "When the optimisation is \"rheobase dependent,\" it means that we need to calculate the rheobase value (the minimum current required to trigger a neuron) to normalise the trace values. In this case, the normalisation is done by expressing the trace values as a percentage of the rheobase. This approach ensures that the traces are scaled relative to the neuron’s threshold current, providing a consistent basis for comparison. \n", "\n", - "For rheobase dependant\" optimisation or additional details, please refer to the [L5PC](./../L5PC/) example." + "However, here we will present the rheobase independent approach which means that we use specific amplitude values like `IDRest_1.0` (indicating a fixed current of 1.0 nA) instead of `IDRest_100` (which represents 100% of the rheobase).\n", + "\n", + "For \"rheobase dependant\" optimisation or additional details, please refer to the [L5PC](./../L5PC/) example." ] }, { @@ -27,7 +29,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -46,7 +48,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The pipeline setup involves six key steps: extraction of e-features from electrophysiological recordings; optimisation of a NEURON cell model based on these e-features; storing the optimised model parameters; validating the models against specified protocols; and plotting the results, including traces, e-feature scores, and parameter distributions." + "The pipeline setup involves six key steps: **extraction** of e-features from electrophysiological recordings; **optimisation** of a NEURON cell model based on these e-features; storing the optimised model parameters; **validating** the models against specified protocols; and **plotting** the results, including traces, e-feature scores, and parameter distributions." ] }, { @@ -55,16 +57,16 @@ "source": [ "The [recipes.json](./config/recipes.json) file (displayed below) contains the key settings for the various stages of the e-model building pipeline.\n", "\n", - "* ``morph_path``: Directory path for morphologies\n", - "* ``morphology``: Contains a list with the morphology's arbitrary name and file name, located in morph_path.\n", - "* ``params``: Specifies mechanisms, locations, distributions, and parameters.\n", - "* ``features``: Path to the file with extraction outputs.\n", + "* **``morph_path``**: Directory path for morphologies\n", + "* **``morphology``**: Contains a list with the morphology's arbitrary name and file name, located in `morph_path`.\n", + "* **``params``**: Specifies mechanisms, locations, distributions, and parameters.\n", + "* **``features``**: Path to the file with extraction outputs.\n", "- **`pipeline_settings`**: Sets up the pipeline with several configuration options, including: \n", " - `extract_absolute_amplitudes`: Set to `true` for performing optimisation independently of rheobase (threshold current). \n", " - `optimiser`: Specifies the optimisation algorithm, set to `\"SO-CMA\"` (a single-objective Covariance Matrix Adaptation algorithm). \n", " - `max_ngen`: Defines the maximum number of generations for the optimisation process, set to `5`. \n", " - `optimisation_params`: Additional optimisation parameters, such as `offspring_size` set to `20`, indicating the number of solutions generated per generation. \n", - " - `validation_protocols`: Lists protocols used for validation, e.g., `[\"IDrest\"]`. \n", + " - `validation_protocols`: Lists protocols used for validation, e.g., `[\"IDrest_0.4\"]`. \n", " - `morph_modifiers`: Set to an empty list `[]`, meaning no specific modifications to morphologies are applied by default." ] }, @@ -130,7 +132,7 @@ "\n", "- **`morphology`**: Filename of the morphology file located in the `./morphologies` folder, with a spherical shape characterized by a diameter and length of 10 micrometers.\n", "\n", - "- **`morphology_format`**: Specifies the format of the morphology file, \"swc\", with support for SWC, ASC, and H5 formats." + "- **`morphology_format`**: Specifies the format of the morphology file, \"swc\", with support for SWC, ASC formats." ] }, { @@ -144,15 +146,8 @@ "species = \"rat\"\n", "brain_region = \"SSCX\"\n", "morphology = \"simple\"\n", - "morphology_format = \"swc\"" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ + "morphology_format = \"swc\"\n", + "\n", "pipeline = EModel_pipeline(\n", " emodel=emodel,\n", " etype=etype,\n", @@ -174,7 +169,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We need to download the required data using the script [download_ephys_data.sh](./download_ephys_data.sh). This dataset features continuous adapting pyramidal cells (cADpyr) e-type models from the rat somatosensory cortex. The data can be obtained from this [repository]()." + "We need to download the required data using the script `./download_ephys_data.sh`. This dataset features continuous adapting pyramidal cells (cADpyr) e-type models from the rat somatosensory cortex. The data can be obtained from this [repository]()." ] }, { @@ -188,7 +183,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -215,22 +210,22 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We can now define the targets which contains the protocols (ecodes) and the features. We define two protocols, IDrest and IV protocols.\n", + "We can now define the targets which contains the protocols (ecodes) and the features. We define two protocols, `IDrest` and `IV` protocols.\n", "\n", - "For the IDrest protocol with an amplitude of 0.256 nA, we select the Spikecount, mean_frequency, and voltage_base capture the neuron's spiking activity and resting potential. In the IV protocol, at an amplitude of -0.147 nA, voltage_base and ohmic_input_resistance_vb_ssse assess the neuron's baseline potential and input resistance. \n", + "For the `IDrest` protocol with an amplitude of 0.2 nA (and 0.4 nA for validation), we select the `Spikecount`, `mean_frequency`, and `voltage_base` capture the neuron's spiking activity and resting potential. In the `IV` protocol, at an amplitude of -0.1 nA, `voltage_base` and `ohmic_input_resistance_vb_ssse` assess the neuron's baseline potential and input resistance. \n", "\n", - "The tolerance of 0.1 specifies the allowable deviation from the target amplitudes when extracting e-features from traces, meaning values within ±0.1 of the specified amplitudes are considered acceptable." + "The `tolerance` of 0.1 allows for a range of ±0.1 around each target amplitude for extracting e-features. For example, if the target amplitude is 0.4, the acceptable range would be from 0.3 to 0.5 Values, excluding 0.3 and 0.5." ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "targets = {\n", " \"IDrest\": {\n", - " \"amplitudes\": [0.256, 0.4],\n", + " \"amplitudes\": [0.2, 0.4],\n", " \"efeatures\": [\n", " \"Spikecount\",\n", " \"mean_frequency\",\n", @@ -238,7 +233,7 @@ " ],\n", " },\n", " \"IV\": {\n", - " \"amplitudes\": [-0.147],\n", + " \"amplitudes\": [-0.1],\n", " \"efeatures\": [\n", " \"voltage_base\",\n", " \"ohmic_input_resistance_vb_ssse\",\n", @@ -258,7 +253,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -278,7 +273,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -342,12 +337,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The results of the feature extraction is stored in [simplecell.json](./config/features/simplecell.json). Let's take a look at the extracted features" + "The results of the feature extraction is stored in `./config/features/simplecell.json`. Let's take a look at the extracted features" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -358,53 +353,53 @@ " \"efeatures\": [\n", " {\n", " \"efel_feature_name\": \"Spikecount\",\n", - " \"protocol_name\": \"IDrest_0.256\",\n", + " \"protocol_name\": \"IDrest_0.2\",\n", " \"recording_name\": \"soma.v\",\n", " \"threshold_efeature_std\": null,\n", " \"default_std_value\": 0.001,\n", - " \"mean\": 6.6,\n", - " \"original_std\": 4.5431266766402185,\n", - " \"sample_size\": 5,\n", + " \"mean\": 5.0,\n", + " \"original_std\": 3.605551275463989,\n", + " \"sample_size\": 4,\n", " \"efeature_name\": \"Spikecount\",\n", " \"weight\": 1.0,\n", " \"efel_settings\": {\n", " \"interp_step\": 0.025,\n", " \"strict_stiminterval\": true,\n", - " \"Threshold\": -50.11250305175781\n", + " \"Threshold\": -48.99374771118164\n", " }\n", " },\n", " {\n", " \"efel_feature_name\": \"mean_frequency\",\n", - " \"protocol_name\": \"IDrest_0.256\",\n", + " \"protocol_name\": \"IDrest_0.2\",\n", " \"recording_name\": \"soma.v\",\n", " \"threshold_efeature_std\": null,\n", " \"default_std_value\": 0.001,\n", - " \"mean\": 4.6549665308108965,\n", - " \"original_std\": 1.7066939148229534,\n", - " \"sample_size\": 4,\n", + " \"mean\": 3.9105121810617045,\n", + " \"original_std\": 1.2910808300604681,\n", + " \"sample_size\": 3,\n", " \"efeature_name\": \"mean_frequency\",\n", " \"weight\": 1.0,\n", " \"efel_settings\": {\n", " \"interp_step\": 0.025,\n", " \"strict_stiminterval\": true,\n", - " \"Threshold\": -50.11250305175781\n", + " \"Threshold\": -48.99374771118164\n", " }\n", " },\n", " {\n", " \"efel_feature_name\": \"voltage_base\",\n", - " \"protocol_name\": \"IDrest_0.256\",\n", + " \"protocol_name\": \"IDrest_0.2\",\n", " \"recording_name\": \"soma.v\",\n", " \"threshold_efeature_std\": null,\n", " \"default_std_value\": 0.001,\n", - " \"mean\": -84.9396882128033,\n", - " \"original_std\": 0.3331013733422112,\n", - " \"sample_size\": 5,\n", + " \"mean\": -84.83373198951986,\n", + " \"original_std\": 0.28733612701960526,\n", + " \"sample_size\": 4,\n", " \"efeature_name\": \"voltage_base\",\n", " \"weight\": 1.0,\n", " \"efel_settings\": {\n", " \"interp_step\": 0.025,\n", " \"strict_stiminterval\": true,\n", - " \"Threshold\": -50.11250305175781\n", + " \"Threshold\": -48.99374771118164\n", " }\n", " },\n", " {\n", @@ -460,56 +455,56 @@ " },\n", " {\n", " \"efel_feature_name\": \"voltage_base\",\n", - " \"protocol_name\": \"IV_-0.147\",\n", + " \"protocol_name\": \"IV_-0.1\",\n", " \"recording_name\": \"soma.v\",\n", " \"threshold_efeature_std\": null,\n", " \"default_std_value\": 0.001,\n", - " \"mean\": -84.5937809414334,\n", - " \"original_std\": 0.25958992541480197,\n", - " \"sample_size\": 5,\n", + " \"mean\": -84.4690685507692,\n", + " \"original_std\": 0.08042238367019017,\n", + " \"sample_size\": 4,\n", " \"efeature_name\": \"voltage_base\",\n", " \"weight\": 1.0,\n", " \"efel_settings\": {\n", " \"interp_step\": 0.025,\n", " \"strict_stiminterval\": true,\n", - " \"Threshold\": -64.5374984741211\n", + " \"Threshold\": -64.51874923706055\n", " }\n", " },\n", " {\n", " \"efel_feature_name\": \"ohmic_input_resistance_vb_ssse\",\n", - " \"protocol_name\": \"IV_-0.147\",\n", + " \"protocol_name\": \"IV_-0.1\",\n", " \"recording_name\": \"soma.v\",\n", " \"threshold_efeature_std\": null,\n", " \"default_std_value\": 0.001,\n", - " \"mean\": 47.95114886552402,\n", - " \"original_std\": 1.5928203273461563,\n", - " \"sample_size\": 5,\n", + " \"mean\": 48.64694052877976,\n", + " \"original_std\": 0.8664384286999164,\n", + " \"sample_size\": 4,\n", " \"efeature_name\": \"ohmic_input_resistance_vb_ssse\",\n", " \"weight\": 1.0,\n", " \"efel_settings\": {\n", " \"interp_step\": 0.025,\n", " \"strict_stiminterval\": true,\n", - " \"Threshold\": -64.5374984741211\n", + " \"Threshold\": -64.51874923706055\n", " }\n", " }\n", " ],\n", " \"protocols\": [\n", " {\n", - " \"name\": \"IDrest_0.256\",\n", + " \"name\": \"IDrest_0.2\",\n", " \"stimuli\": [\n", " {\n", " \"delay\": 700.0000000000001,\n", - " \"amp\": 0.2579375009983778,\n", + " \"amp\": 0.23945312993600965,\n", " \"thresh_perc\": null,\n", " \"duration\": 2000.0,\n", " \"totduration\": 3000.0,\n", - " \"holding_current\": -0.0266875009983778\n", + " \"holding_current\": -0.026718751061707735\n", " }\n", " ],\n", " \"recordings_from_config\": [\n", " {\n", " \"type\": \"CompRecording\",\n", - " \"name\": \"IDrest_0.256.soma.v\",\n", + " \"name\": \"IDrest_0.2.soma.v\",\n", " \"location\": \"soma\",\n", " \"variable\": \"v\"\n", " }\n", @@ -543,21 +538,21 @@ " \"stochasticity\": false\n", " },\n", " {\n", - " \"name\": \"IV_-0.147\",\n", + " \"name\": \"IV_-0.1\",\n", " \"stimuli\": [\n", " {\n", " \"delay\": 20.0,\n", - " \"amp\": -0.1440624985843897,\n", + " \"amp\": -0.1265624992083758,\n", " \"thresh_perc\": null,\n", " \"duration\": 1000.0,\n", " \"totduration\": 1320.0,\n", - " \"holding_current\": -0.02878124974668026\n", + " \"holding_current\": -0.02816406195051968\n", " }\n", " ],\n", " \"recordings_from_config\": [\n", " {\n", " \"type\": \"CompRecording\",\n", - " \"name\": \"IV_-0.147.soma.v\",\n", + " \"name\": \"IV_-0.1.soma.v\",\n", " \"location\": \"soma\",\n", " \"variable\": \"v\"\n", " }\n", @@ -579,6 +574,13 @@ "print(json.dumps(fcc, indent=4))" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The \"validation\": true field indicates the IDrest_0.4 protocol will only be used for validation" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -590,12 +592,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The parameters for the optimisation are defined in [simple.json](./config/simple.json). In this case, we are optimising two parameters: ``gnabar_hh`` and ``gkbar_hh``. These parameters determine the maximum conductances for sodium and potassium ion channels in a Hodgkin-Huxley neuron model, with optimisation ranges of 0.05–0.125 (S/cm2) and 0.01–0.075 (S/cm2), respectively." + "The parameters for the optimisation are defined in `./config/simple.json`. In this case, we are optimising two parameters: ``gnabar_hh`` and ``gkbar_hh``. These parameters determine the maximum conductances for sodium and potassium ion channels in a Hodgkin-Huxley neuron model, with optimisation ranges of 0.05–0.125 (S/cm2) and 0.01–0.075 (S/cm2), respectively." ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -661,7 +663,6 @@ } ], "source": [ - "# EMC\n", "emc_path = \"./config/params/simple.json\"\n", "with open(emc_path, 'r') as file:\n", " emc = json.load(file)\n", @@ -680,7 +681,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We can now run the optimisation using the `EModel_pipeline` class. The optimisation will run for 5 generations, with a population size of 20." + "We can now run the optimisation process using the `EModel_pipeline` class. The seed parameter is used to set the random number generator for reproducibility. The optimisation runs for 5 generations with a population size of 20. After each optimisation round is completed, the results are saved in a pickle file for each seed within the `./checkpoints` directory" ] }, { @@ -689,14 +690,21 @@ "metadata": {}, "outputs": [], "source": [ - "pipeline.optimise()" + "pipeline.optimise(seed=1)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Validating the model" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Once the model has been fitted, we can store the results in the [final.json](./final.json) file." + "This validation step is optional but essential for verifying that the optimised model reliably represents biological behavior. It involves executing the protocols defined under the `validation_protocols` key in `recipes.json` to ensure the model's e-feature scores are within acceptable limits." ] }, { @@ -705,30 +713,102 @@ "metadata": {}, "outputs": [], "source": [ - "pipeline.store_optimisation_results()" + "pipeline.store_optimisation_results()\n", + "pipeline.validation()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Validating the model" + "The `./final.json` contains the best model across all seeds. Since we're only running a single seed here, the result will simply be that model. Now, let's check the final results" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": 15, "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"simplecell__1\": {\n", + " \"emodel\": \"simplecell\",\n", + " \"etype\": \"cADpyr\",\n", + " \"ttype\": null,\n", + " \"mtype\": null,\n", + " \"species\": \"rat\",\n", + " \"brain_region\": \"SSCX\",\n", + " \"iteration\": null,\n", + " \"synapse_class\": null,\n", + " \"allen_notation\": null,\n", + " \"score\": 510.2861723258447,\n", + " \"parameters\": {\n", + " \"gnabar_hh.somatic\": 0.05000000003749999,\n", + " \"gkbar_hh.somatic\": 0.07499999996750001\n", + " },\n", + " \"fitness\": {\n", + " \"IDrest_0.2.soma.v.Spikecount\": 1.1094003924504583,\n", + " \"IDrest_0.2.soma.v.mean_frequency\": 250.0,\n", + " \"IDrest_0.2.soma.v.voltage_base\": 6.86265875272435,\n", + " \"IV_-0.1.soma.v.voltage_base\": 2.3141131806698945,\n", + " \"IV_-0.1.soma.v.ohmic_input_resistance_vb_ssse\": 250.0\n", + " },\n", + " \"features\": {\n", + " \"IDrest_0.2.soma.v.Spikecount\": 1.0,\n", + " \"IDrest_0.2.soma.v.mean_frequency\": 1739.1304358817733,\n", + " \"IDrest_0.2.soma.v.voltage_base\": -82.86184220245485,\n", + " \"IDrest_0.4.soma.v.Spikecount\": 1.0,\n", + " \"IDrest_0.4.soma.v.mean_frequency\": 2105.263159505021,\n", + " \"IDrest_0.4.soma.v.voltage_base\": -82.71053576131624,\n", + " \"IV_-0.1.soma.v.voltage_base\": -84.28296205269712,\n", + " \"IV_-0.1.soma.v.ohmic_input_resistance_vb_ssse\": 1060.243113329033\n", + " },\n", + " \"validation_fitness\": {\n", + " \"IDrest_0.4.soma.v.Spikecount\": 250.0,\n", + " \"IDrest_0.4.soma.v.mean_frequency\": 250.0,\n", + " \"IDrest_0.4.soma.v.voltage_base\": 250.0\n", + " },\n", + " \"validated\": false,\n", + " \"seed\": 1,\n", + " \"pdfs\": [\n", + " \"/gpfs/bbp.cscs.ch/home/ikilic/workspace/BluePyEModel/examples/simplecell/figures/simplecell/optimisation/emodel=simplecell__etype=cADpyr__species=rat__brain_region=SSCX__seed=1__optimisation.pdf\",\n", + " \"/gpfs/bbp.cscs.ch/home/ikilic/workspace/BluePyEModel/examples/simplecell/figures/simplecell/traces/all/emodel=simplecell__etype=cADpyr__species=rat__brain_region=SSCX__seed=1__traces.pdf\",\n", + " \"/gpfs/bbp.cscs.ch/home/ikilic/workspace/BluePyEModel/examples/simplecell/figures/simplecell/scores/all/emodel=simplecell__etype=cADpyr__species=rat__brain_region=SSCX__seed=1__scores.pdf\",\n", + " \"/gpfs/bbp.cscs.ch/home/ikilic/workspace/BluePyEModel/examples/simplecell/figures/simplecell/thumbnail/all/emodel=simplecell__etype=cADpyr__species=rat__brain_region=SSCX__seed=1__thumbnail.png\",\n", + " \"/gpfs/bbp.cscs.ch/home/ikilic/workspace/BluePyEModel/examples/simplecell/figures/simplecell/distributions/all/emodel=simplecell__etype=cADpyr__species=rat__brain_region=SSCX__parameters_distribution.pdf\",\n", + " \"/gpfs/bbp.cscs.ch/home/ikilic/workspace/BluePyEModel/examples/simplecell/figures/simplecell/parameter_evolution/emodel=simplecell__etype=cADpyr__species=rat__brain_region=SSCX__seed=1__evo_parameter_density.pdf\"\n", + " ]\n", + " }\n", + "}\n" + ] + } + ], "source": [ - "We can also run the validation of the e-model, executing the protocols defined under the `validation_protocols` key in recipes.json" + "final_path = \"./final.json\"\n", + "with open(final_path, 'r') as file:\n", + " final = json.load(file)\n", + "\n", + "print(json.dumps(final, indent=4))" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "pipeline.validation()" + "- **`score`**: The global z-score for the optimized model, summing z-scores of all e-features used in optimisation (e.g., `507.86`).\n", + "\n", + "- **`parameters`**: Best hall of fame parameters of the optimised e-model\n", + "\n", + "- **`fitness`**: Z-scores for each optimized e-feature, indicating how closely the model matches experimental data. High scores (e.g., `250.0`) suggest a poor fit.\n", + "\n", + "- **`features`**: The actual numerical values of each e-feature produced by the model.\n", + "\n", + "- **`validation_fitness`**: Z-scores for validation e-features; empty (`{}`) here, indicating no validation recorded.\n", + "\n", + "- **`validated`**: Shows validation status. Here, `false` means the model didn't pass, as fitness scores must be below 5 to pass.\n" ] }, { @@ -742,16 +822,48 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The plots are stored in the `./figures/` directory, organised into subfolders: efeatures_extraction for e-feature figures by protocol, distributions for parameter distributions, optimisation for optimisation curves and progress, parameter_evolution for parameter changes over generations, scores for z-scores of optimised e-features, traces for optimised e-model traces, and currentscape for Currentscape plots." + "The plots are stored in the `./figures/` directory, organised into subfolders: `efeatures_extraction` for e-feature figures by protocol, distributions for parameter distributions, `optimisation` for optimisation curves and progress, `parameter_evolution` for parameter changes over generations, `scores` for z-scores of optimised e-features, `traces` for optimised e-model traces, and `currentscape` for Currentscape plots." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/gpfs/bbp.cscs.ch/home/ikilic/workspace/BluePyEModel/bluepyemodel/emodel_pipeline/plotting.py:802: UserWarning: Tight layout not applied. The bottom and top margins cannot be made large enough to accommodate all axes decorations.\n", + " plt.tight_layout()\n", + "Could not find any step protocol in recording. Will take the first one.\n", + "Could not plot currentscape for emodel=simplecell__etype=cADpyr__species=rat__brain_region=SSCX__seed=1__currentscape.IDrest_0.2.soma: voltage or currents is empty.\n", + "Could not plot currentscape for emodel=simplecell__etype=cADpyr__species=rat__brain_region=SSCX__seed=1__currentscape.IDrest_0.4.soma: voltage or currents is empty.\n", + "Could not plot currentscape for emodel=simplecell__etype=cADpyr__species=rat__brain_region=SSCX__seed=1__currentscape.IV_-0.1.soma: voltage or currents is empty.\n" + ] + }, + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "text/plain": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ - "pipeline.plot(only_validated=False)" + "pipeline.plot()" ] } ],