Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bz committed Nov 9, 2023
1 parent 94b7824 commit e881cb1
Show file tree
Hide file tree
Showing 9 changed files with 617 additions and 246 deletions.
198 changes: 0 additions & 198 deletions examples/IrisTraining.ipynb

This file was deleted.

Empty file removed examples/__init__.py
Empty file.
131 changes: 131 additions & 0 deletions examples/custom_model.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "235c92cd-cc05-42b8-a516-1185eeac5f0c",
"metadata": {},
"source": [
"# Creating a Custom LUME-model\n",
"Custom models that are compatible with LUME tools can be created by inhereting from the `LUMEBaseModel`."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "56725817-2b21-4bea-98b0-151dea959f77",
"metadata": {},
"outputs": [],
"source": [
"from lume_model.base import LUMEBaseModel\n",
"from lume_model.variables import ScalarInputVariable, ScalarOutputVariable"
]
},
{
"cell_type": "markdown",
"id": "79c62b18-7dc1-44ca-b578-4dea5cc4a4b4",
"metadata": {},
"source": [
"## Model Definition\n",
"The minimum requirement for creating a custom LUME-model is to implement the abstract `evaluate` method inherited from `LUMEBaseModel`. Here, we simply return the squared input."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "f96d9863-269c-49d8-9671-cc73a783bcbc",
"metadata": {},
"outputs": [],
"source": [
"class ExampleModel(LUMEBaseModel):\n",
" def evaluate(self, input_dict):\n",
" output_dict = {\n",
" \"output1\": input_dict[self.input_variables[0].name] ** 2,\n",
" \"output2\": input_dict[self.input_variables[1].name] ** 2,\n",
" }\n",
" return output_dict"
]
},
{
"cell_type": "markdown",
"id": "868fff4d-1f46-48e2-8bd0-c9d831df79e6",
"metadata": {},
"source": [
"## Model Instantiation and Execution\n",
"Instantiation requires specification of the input and output variables of the model."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "97946e64-062d-47d4-8d0c-d7e02a335a56",
"metadata": {},
"outputs": [],
"source": [
"input_variables = [\n",
" ScalarInputVariable(name=\"input1\", default=0.1, value_range=[0.0, 1.0]),\n",
" ScalarInputVariable(name=\"input2\", default=0.2, value_range=[0.0, 1.0]),\n",
"]\n",
"output_variables = [\n",
" ScalarOutputVariable(name=\"output1\"),\n",
" ScalarOutputVariable(name=\"output2\"),\n",
"]\n",
"\n",
"m = ExampleModel(input_variables=input_variables, output_variables=output_variables)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "50aae4be-0d6e-456f-83e8-3a84d6d78f84",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'output1': 0.09, 'output2': 0.36}"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"input_dict = {\n",
" \"input1\": 0.3,\n",
" \"input2\": 0.6,\n",
"}\n",
"m.evaluate(input_dict)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6a547f3c-1706-4b32-bab6-9687627f6a78",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:lume-model-dev]",
"language": "python",
"name": "conda-env-lume-model-dev-py"
},
"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.9.18"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Binary file removed examples/files/example_input_image.npy
Binary file not shown.
39 changes: 0 additions & 39 deletions examples/files/iris_config.yml

This file was deleted.

Binary file removed examples/files/iris_model.h5
Binary file not shown.
9 changes: 0 additions & 9 deletions examples/iris_model.py

This file was deleted.

Loading

0 comments on commit e881cb1

Please sign in to comment.