{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "78608b4f-b347-494a-bcaf-1822a16e3361",
   "metadata": {},
   "source": [
    "# Land Value\n",
    "\n",
    "<h1 style=\"color:red\">VERY WIP -- not ready yet!</h1>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "13a2b053-59e7-4d55-9389-c6258adfc0e6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import init_notebooks\n",
    "init_notebooks.setup_environment()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "58f716e1-03ef-48c0-b8f9-eb05af3410dc",
   "metadata": {},
   "outputs": [],
   "source": [
    "from openavmkit.synthetic.generate import (\n",
    "    trial_simple_plane,\n",
    "    trial_simple_plane_w_buildings,\n",
    "    simple_plane,\n",
    "    simple_plane_w_buildings,\n",
    "    run_trials,\n",
    "    add_simple_land_value\n",
    ")\n",
    "from openavmkit.benchmark import (\n",
    "    run_one_model\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6e1355a7-e779-430e-be27-29fd2743d8a4",
   "metadata": {},
   "source": [
    "# Trial 1: Simple plane\n",
    "\n",
    "- Uniform grid of equally sized parcels\n",
    "- No buildings\n",
    "- Only meaningful characteristic is distance from center"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b207fbfd-21b8-4c34-b773-2769699dc15c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define variations and parameters\n",
    "\n",
    "variations = [\n",
    "    {\n",
    "        \"id\": \"inverse_square_dist_only\",\n",
    "        \"land_value_curve\": \"inverse_square\",\n",
    "        \"ind_vars\": [\"dist_to_centroid\"]\n",
    "    },\n",
    "    {\n",
    "        \"id\": \"inverse_square_lat_long\",\n",
    "        \"land_value_curve\": \"inverse_square\",\n",
    "        \"ind_vars\": [\"dist_to_centroid\", \"latitude_norm\", \"longitude_norm\"],\n",
    "    },\n",
    "    {\n",
    "        \"id\": \"inverse_square_polar_coords\",\n",
    "        \"land_value_curve\": \"inverse_square\",\n",
    "        \"ind_vars\": [\"dist_to_centroid\", \"polar_radius\", \"polar_angle\"],\n",
    "    },\n",
    "    {\n",
    "        \"id\": \"inverse_square_all_coords\",\n",
    "        \"land_value_curve\": \"inverse_square\",\n",
    "        \"ind_vars\": [\"dist_to_centroid\", \"latitude_norm\", \"longitude_norm\", \"polar_radius\", \"polar_angle\"],\n",
    "    }\n",
    "]\n",
    "\n",
    "params = {\n",
    "    \"latitude\": 29.759172,\n",
    "    \"longitude\": -95.363158,\n",
    "    \"block_size_y\": 100,\n",
    "    \"block_size_x\": 100,\n",
    "    \"blocks_y\": 100,\n",
    "    \"blocks_x\": 100,\n",
    "    \"units\": \"ft\",\n",
    "    \"land_value_base\": 10,\n",
    "    \"land_value_curve\": \"inverse_square\",\n",
    "    \"land_value_size_field\": \"land_area_sqft\",\n",
    "    \"perc_sales\": 0.05,\n",
    "    \"perc_sales_error\": 0.15,\n",
    "    \"train_frac\": 0.8,\n",
    "    \"cat_vars\": [],\n",
    "    \"outpath\": \"land_value/out/trial_1\",\n",
    "    \"models\": [\"ground_truth\", \"mra\", \"gwr\", \"kernel\", \"lightgbm\", \"xgboost\", \"catboost\"],\n",
    "    \"ind_vars\": [\"dist_to_centroid\", \"latitude_norm\", \"longitude_norm\"],\n",
    "    \"locations\": [\"loc_32\", \"loc_16\", \"loc_8\", \"loc_4\", \"loc_2\"],\n",
    "    \"dep_var_test\": \"true_market_value\",\n",
    "    \"verbose\": False\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6dcfc84d-952d-4f66-8425-c4487056a30d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Run trial\n",
    "\n",
    "run_trials(trial_simple_plane, params, variations)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "289853aa-04eb-4e86-9bb9-db596576e0b9",
   "metadata": {},
   "source": [
    "# Trial 2: Land and Simple buildings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "67596dcb-9be5-4526-b205-471de9d9b6f3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define variations and parameters\n",
    "\n",
    "variations = [\n",
    "    {\n",
    "        \"id\": \"inverse_square_no_vacant\",\n",
    "        \"land_value_curve\": \"inverse_square\",\n",
    "        \"perc_vacant\": 0.0,\n",
    "    },\n",
    "    {\n",
    "        \"id\": \"inverse_square_10_vacant\",\n",
    "        \"land_value_curve\": \"inverse_square\",\n",
    "        \"perc_vacant\": 0.1,\n",
    "    }\n",
    "]\n",
    "\n",
    "params = {\n",
    "    \"latitude\": 29.759172,\n",
    "    \"longitude\": -95.363158,\n",
    "    \"block_size_y\": 100,\n",
    "    \"block_size_x\": 100,\n",
    "    \"blocks_y\": 100,\n",
    "    \"blocks_x\": 100,\n",
    "    \"units\": \"ft\",\n",
    "    \"bldg_value_base\": 50,\n",
    "    \"land_value_base\": 10,\n",
    "    \"land_value_curve\": \"linear\",\n",
    "    \"land_value_size_field\": \"land_area_sqft\",\n",
    "    \"perc_sales\": 0.05,\n",
    "    \"perc_sales_error\": 0.15,\n",
    "    \"train_frac\": 0.8,\n",
    "    \"cat_vars\": [],\n",
    "    \"outpath\": \"land_value/out/trial_2\",\n",
    "    \"perc_vacant\": 0.1,\n",
    "    \"models\": [\"ground_truth\", \"spatial_lag\", \"mra\", \"gwr\", \"kernel\", \"lightgbm\", \"xgboost\", \"catboost\", \"local_sqft\"],\n",
    "    \"ind_vars\": [\"dist_to_centroid\", \"bldg_area_finished_sqft\", \"latitude_norm\", \"longitude_norm\"],\n",
    "    \"locations\": [\"loc_polar_32\", \"loc_polar_16\", \"loc_polar_8\", \"loc_polar_4\", \"loc_polar_ 2\"],\n",
    "    \"dep_var_test\": \"true_market_value\",\n",
    "    \"dep_var_test_hedonic\": \"true_land_value\",\n",
    "    \"use_saved_results\": True,\n",
    "    \"verbose\": True,\n",
    "    \"hedonic\": True\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0091ffec-cfd2-4148-a0e6-4478415ef6c6",
   "metadata": {},
   "outputs": [],
   "source": [
    "run_trials(trial_simple_plane_w_buildings, params, variations)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f2b5a341-b6c4-4c1a-b6b7-10c183756033",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "96755140-415c-4ce5-8189-b1deb11c7773",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python (my_library_env)",
   "language": "python",
   "name": "my_library_env"
  },
  "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.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
