Skip to content

Commit

Permalink
Mobility model alpha parameter regression from data (#15)
Browse files Browse the repository at this point in the history
* Fixed PR changes for params_regression

* Fixed Unittest for param_regression according to PR change

* Fixed the mobility notebook and radp_library file(PR changes done)

* Resolved test_param_regression unittest cases

* Updated Param Regression and radp library as instructed in the PR review

* Changed the scipy dependency to solve dependency error

* Changed how seed value works especially made it user friendly

* Refactored functions and changed the imports

* Resolved test_param_regression imports
  • Loading branch information
tanzim10 authored Oct 11, 2024
1 parent 4b5cd5a commit 188a31b
Show file tree
Hide file tree
Showing 6 changed files with 963 additions and 53 deletions.
2 changes: 1 addition & 1 deletion notebooks/coo_with_radp_digital_twin.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
"version": "3.11.5"
},
"varInspector": {
"cols": {
Expand Down
362 changes: 362 additions & 0 deletions notebooks/mobility_model.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,362 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "ec7ab4ae",
"metadata": {},
"source": [
"# Alpha Optimization in a Gauss-Markov Mobility Model\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "754a70e3",
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"from pathlib import Path\n",
"sys.path.append(f\"{Path().absolute().parent}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b3d3ca1a",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import scipy\n",
"import numpy as np\n",
"from radp_library import *\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib.cm as cm\n",
"from radp.digital_twin.mobility.param_regression import get_predicted_alpha,preprocess_ue_data"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "309ead1f",
"metadata": {},
"outputs": [],
"source": [
"params = {\n",
" \"ue_tracks_generation\": {\n",
" \"params\": {\n",
" \"simulation_duration\": 3600,\n",
" \"simulation_time_interval_seconds\": 0.01,\n",
" \"num_ticks\": 50,\n",
" \"num_batches\": 1,\n",
" \"ue_class_distribution\": {\n",
" \"stationary\": {\n",
" \"count\": 10,\n",
" \"velocity\": 0,\n",
" \"velocity_variance\": 1\n",
" },\n",
" \"pedestrian\": {\n",
" \"count\": 5,\n",
" \"velocity\": 2,\n",
" \"velocity_variance\": 1\n",
" },\n",
" \"cyclist\": {\n",
" \"count\": 5,\n",
" \"velocity\": 5,\n",
" \"velocity_variance\": 1\n",
" },\n",
" \"car\": {\n",
" \"count\": 12,\n",
" \"velocity\": 20,\n",
" \"velocity_variance\": 1\n",
" }\n",
" },\n",
" \"lat_lon_boundaries\": {\n",
" \"min_lat\": -90,\n",
" \"max_lat\": 90,\n",
" \"min_lon\": -180,\n",
" \"max_lon\": 180\n",
" },\n",
" \"gauss_markov_params\": {\n",
" \"alpha\": 0.5,\n",
" \"variance\": 0.8,\n",
" \"rng_seed\": 42,\n",
" \"lon_x_dims\": 100,\n",
" \"lon_y_dims\": 100,\n",
" \"// TODO\": \"Account for supporting the user choosing the anchor_loc and cov_around_anchor.\",\n",
" \"// Current implementation\": \"the UE Tracks generator will not be using these values.\",\n",
" \"// anchor_loc\": {},\n",
" \"// cov_around_anchor\": {}\n",
" }\n",
" }\n",
" }\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "d5d3f4fb",
"metadata": {},
"source": [
"## Generate Data Set 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bf32a451",
"metadata": {},
"outputs": [],
"source": [
"data1 = get_ue_data(params)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0217fb7d",
"metadata": {},
"outputs": [],
"source": [
"data1.head(10)"
]
},
{
"cell_type": "markdown",
"id": "0f112187",
"metadata": {},
"source": [
"## Plot Dataset 1 "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "57d3c99b",
"metadata": {},
"outputs": [],
"source": [
"plot_ue_tracks(data1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "507f5c0b",
"metadata": {},
"outputs": [],
"source": [
"velocity = preprocess_ue_data(data1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "60b0bc3b",
"metadata": {},
"outputs": [],
"source": [
"velocity"
]
},
{
"cell_type": "markdown",
"id": "3e4713fc",
"metadata": {},
"source": [
"## Alpha Initialization"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ee3e00c1",
"metadata": {},
"outputs": [],
"source": [
"alpha0 = np.random.choice(np.arange(0, 1.1, 0.1))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "119f1534",
"metadata": {},
"outputs": [],
"source": [
"print(\"Alpha0:\",alpha0)"
]
},
{
"cell_type": "markdown",
"id": "97a8c1ec",
"metadata": {},
"source": [
"## Regress to Find Alpha 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "12fdaf4b",
"metadata": {},
"outputs": [],
"source": [
"alpha1 = get_predicted_alpha(data1,alpha0,seed=42) # Adding seed for reproducibility"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "39eed46d",
"metadata": {},
"outputs": [],
"source": [
"alpha1"
]
},
{
"cell_type": "markdown",
"id": "1dc52c9d",
"metadata": {},
"source": [
"## Generating new data using alpha 1\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "46d7e685",
"metadata": {},
"outputs": [],
"source": [
"#Changing alpha value to alpha1 in the params dictionary\n",
"params['ue_tracks_generation']['params']['gauss_markov_params']['alpha'] = alpha1"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ab4eb7cd",
"metadata": {},
"outputs": [],
"source": [
"print(params['ue_tracks_generation']['params']['gauss_markov_params']['alpha'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3c700855",
"metadata": {},
"outputs": [],
"source": [
"data2 = get_ue_data(params)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "18a2b294",
"metadata": {},
"outputs": [],
"source": [
"data2"
]
},
{
"cell_type": "markdown",
"id": "07a4c3aa",
"metadata": {},
"source": [
"## Plot Dataset 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "df4b1b11",
"metadata": {},
"outputs": [],
"source": [
"plot_ue_tracks(data2)"
]
},
{
"cell_type": "markdown",
"id": "b727758e",
"metadata": {},
"source": [
"## Regress to Find Alpha 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5a268312",
"metadata": {},
"outputs": [],
"source": [
"alpha2 = get_predicted_alpha(data1,alpha1,seed=42) # Adding seed for reproducibility"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "02575be1",
"metadata": {},
"outputs": [],
"source": [
"alpha2"
]
},
{
"cell_type": "markdown",
"id": "da3b378b",
"metadata": {},
"source": [
"## Comparison Plot of Dataset 1 and Dataset2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0798532d",
"metadata": {},
"outputs": [],
"source": [
"plot_ue_tracks_side_by_side(data1, data2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4c61c293",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 188a31b

Please sign in to comment.