{ "cells": [ { "cell_type": "markdown", "id": "0ec85e00", "metadata": {}, "source": [ "# Build your own Scikit-NeuroMSI model" ] }, { "cell_type": "markdown", "id": "dd00e482", "metadata": {}, "source": [ "You can implement your own model by importing the `SKNMSIMethodABC` method from the `core` module and creating a class calling such method. \n", "\n", "Such class must have four attributes to define the model's identity and input/output modalities: \n", "- `_model_name`: Name of the model.\n", "- `_model_type`: Classification of the model (e.g. MLE, Bayesian, Neural, etc).\n", "- `_run_input`: Modality specific parameters computed by the model. \n", "- `_run_output`: Modality specific results delivered by the model.\n", "\n", "Furthermore, the class must have six managed attributes (properties) defined in the `init` method:\n", "- `mode0`: Name of sensory modality 0.\n", "- `mode1`: Name of sensory modality 1.\n", "- `position_range`: Range of positions encoded by the model.\n", "- `position_res`: Resolution of positional encoding.\n", "- `time_range`: Range of times encoded by the model.\n", "- `time_res`: Resolution of time encoding.\n", "\n", "> The model may include more than two sensory modalities, as long as they are properly defined in the class.\n", "\n", "Finally, the class must have two methods to specify the model execution:\n", "- `set_random`: Sets random seed (if required).\n", "- `run`: Executes the model\n", "\n", "Here a template of a Scikit-NeuroMSI model class:" ] }, { "cell_type": "code", "execution_count": 1, "id": "51150d48", "metadata": {}, "outputs": [], "source": [ "from skneuromsi.core import SKNMSIMethodABC\n", "\n", "\n", "class MyBayesianModel(SKNMSIMethodABC):\n", " _model_name = \"MyBayesianModel\"\n", " _model_type = \"Bayesian\"\n", " _output_mode = \"multi\"\n", "\n", " _run_input = [\n", " {\"target\": \"auditory_position\", \"template\": \"${mode0}_position\"},\n", " {\"target\": \"visual_position\", \"template\": \"${mode1}_position\"},\n", " ]\n", "\n", " _run_output = [\n", " {\"target\": \"auditory\", \"template\": \"${mode0}\"},\n", " {\"target\": \"visual\", \"template\": \"${mode1}\"},\n", " ]\n", "\n", " def __init__(\n", " self,\n", " *,\n", " mode0=\"auditory\",\n", " mode1=\"visual\",\n", " position_range=(0, 29),\n", " position_res=1,\n", " time_range=(1, 2),\n", " time_res=1,\n", " ):\n", " self._mode0 = mode0\n", " self._mode1 = mode1\n", " self._position_range = position_range\n", " self._position_res = float(position_res)\n", " self._time_range = time_range\n", " self._time_res = float(time_res)\n", "\n", " # PROPERTY ================================================================\n", "\n", " @property\n", " def mode0(self):\n", " return self._mode0\n", "\n", " @property\n", " def mode1(self):\n", " return self._mode1\n", "\n", " @property\n", " def time_range(self):\n", " return self._time_range\n", "\n", " @property\n", " def time_res(self):\n", " return self._time_res\n", "\n", " @property\n", " def position_range(self):\n", " return self._position_range\n", "\n", " @property\n", " def position_res(self):\n", " return self._position_res\n", "\n", " # MODEL RUN ================================================================\n", "\n", " def set_random():\n", " pass\n", "\n", " def run(auditory_position, visual_position): ..." ] }, { "cell_type": "markdown", "id": "1147fe6e", "metadata": {}, "source": [ "For more details about model building, please refer to the [API documentation](https://scikit-neuromsi.readthedocs.io/en/latest/api/core/modelabc.html). " ] } ], "metadata": { "kernelspec": { "display_name": "neuromsi", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.18" } }, "nbformat": 4, "nbformat_minor": 5 }