|
1723 | 1723 | }, |
1724 | 1724 | { |
1725 | 1725 | "cell_type": "code", |
1726 | | - "execution_count": 2, |
| 1726 | + "execution_count": null, |
| 1727 | + "metadata": {}, |
| 1728 | + "outputs": [], |
| 1729 | + "source": [ |
| 1730 | + "from spotPython.utils.init import fun_control_init\n", |
| 1731 | + "from spotPython.hyperparameters.values import get_control_key_value\n", |
| 1732 | + "from spotPython.light.regression.netlightregression import NetLightRegression\n", |
| 1733 | + "from spotPython.hyperdict.light_hyper_dict import LightHyperDict\n", |
| 1734 | + "from spotPython.hyperparameters.values import add_core_model_to_fun_control\n", |
| 1735 | + "from spotPython.hyperparameters.values import set_control_hyperparameter_value\n", |
| 1736 | + "\n", |
| 1737 | + "fun_control = fun_control_init()\n", |
| 1738 | + "add_core_model_to_fun_control(core_model=NetLightRegression,\n", |
| 1739 | + " fun_control=fun_control,\n", |
| 1740 | + " hyper_dict=LightHyperDict)\n", |
| 1741 | + "set_control_hyperparameter_value(control_dict=fun_control, hyperparameter=\"l1\", value=[1,7])\n", |
| 1742 | + "set_control_hyperparameter_value(control_dict=fun_control, hyperparameter=\"initialization\", value=[\"xavier2\", \"kaiming2\"])\n", |
| 1743 | + "print(fun_control)\n" |
| 1744 | + ] |
| 1745 | + }, |
| 1746 | + { |
| 1747 | + "cell_type": "code", |
| 1748 | + "execution_count": null, |
| 1749 | + "metadata": {}, |
| 1750 | + "outputs": [], |
| 1751 | + "source": [] |
| 1752 | + }, |
| 1753 | + { |
| 1754 | + "cell_type": "markdown", |
| 1755 | + "metadata": {}, |
| 1756 | + "source": [ |
| 1757 | + "## get names" |
| 1758 | + ] |
| 1759 | + }, |
| 1760 | + { |
| 1761 | + "cell_type": "code", |
| 1762 | + "execution_count": null, |
| 1763 | + "metadata": {}, |
| 1764 | + "outputs": [], |
| 1765 | + "source": [ |
| 1766 | + "def get_entry(dictionary, key, i):\n", |
| 1767 | + " if key in dictionary:\n", |
| 1768 | + " if 'levels' in dictionary[key]:\n", |
| 1769 | + " if i < len(dictionary[key]['levels']):\n", |
| 1770 | + " return dictionary[key]['levels'][i]\n", |
| 1771 | + " return None" |
| 1772 | + ] |
| 1773 | + }, |
| 1774 | + { |
| 1775 | + "cell_type": "code", |
| 1776 | + "execution_count": null, |
| 1777 | + "metadata": {}, |
| 1778 | + "outputs": [], |
| 1779 | + "source": [ |
| 1780 | + "import torch\n", |
| 1781 | + "from spotPython.data.pkldataset_intern import PKLDataset\n", |
| 1782 | + "from spotPython.utils.device import getDevice\n", |
| 1783 | + "from spotPython.utils.init import fun_control_init\n", |
| 1784 | + "from spotPython.utils.file import get_experiment_name, get_spot_tensorboard_path\n", |
| 1785 | + "import numpy as np\n", |
| 1786 | + "from spotPython.hyperparameters.values import set_control_key_value\n", |
| 1787 | + "from spotPython.data.diabetes import Diabetes\n", |
| 1788 | + "from spotPython.light.regression.netlightregression import NetLightRegression\n", |
| 1789 | + "from spotPython.hyperdict.light_hyper_dict import LightHyperDict\n", |
| 1790 | + "from spotPython.hyperparameters.values import add_core_model_to_fun_control\n", |
| 1791 | + "from spotPython.utils.eda import gen_design_table\n", |
| 1792 | + "from math import inf\n", |
| 1793 | + "\n", |
| 1794 | + "MAX_TIME = 60\n", |
| 1795 | + "FUN_EVALS = inf\n", |
| 1796 | + "INIT_SIZE = 25\n", |
| 1797 | + "WORKERS = 0\n", |
| 1798 | + "PREFIX=\"031\"\n", |
| 1799 | + "DEVICE = getDevice()\n", |
| 1800 | + "\n", |
| 1801 | + "\n", |
| 1802 | + "experiment_name = get_experiment_name(prefix=PREFIX)\n", |
| 1803 | + "fun_control = fun_control_init(\n", |
| 1804 | + " spot_tensorboard_path=get_spot_tensorboard_path(experiment_name),\n", |
| 1805 | + " _L_in=10,\n", |
| 1806 | + " _L_out=1,\n", |
| 1807 | + " TENSORBOARD_CLEAN=True,\n", |
| 1808 | + " device=DEVICE,\n", |
| 1809 | + " enable_progress_bar=False,\n", |
| 1810 | + " fun_evals=FUN_EVALS,\n", |
| 1811 | + " log_level=10,\n", |
| 1812 | + " max_time=MAX_TIME,\n", |
| 1813 | + " num_workers=WORKERS,\n", |
| 1814 | + " show_progress=True,\n", |
| 1815 | + " tolerance_x=np.sqrt(np.spacing(1)),\n", |
| 1816 | + " )\n", |
| 1817 | + "\n", |
| 1818 | + "dataset = Diabetes()\n", |
| 1819 | + "dataset = PKLDataset(directory=\"/Users/bartz/workspace/spotPython/notebooks/data/spotPython/\", filename=\"data_sensitive.pkl\", target_column='N', feature_type=torch.float32, target_type=torch.float32, rmNA=True, rmMF=True)\n", |
| 1820 | + "set_control_key_value(control_dict=fun_control,\n", |
| 1821 | + " key=\"data_set\",\n", |
| 1822 | + " value=dataset,\n", |
| 1823 | + " replace=True)\n", |
| 1824 | + "\n", |
| 1825 | + "set_control_key_value(control_dict=fun_control,\n", |
| 1826 | + " key=\"_L_in\",\n", |
| 1827 | + " value=133,\n", |
| 1828 | + " replace=True)\n", |
| 1829 | + "\n", |
| 1830 | + "\n", |
| 1831 | + "add_core_model_to_fun_control(core_model=NetLightRegression,\n", |
| 1832 | + " fun_control=fun_control,\n", |
| 1833 | + " hyper_dict=LightHyperDict)\n", |
| 1834 | + "# from spotPython.hyperparameters.values import modify_hyper_parameter_bounds\n", |
| 1835 | + "\n", |
| 1836 | + "from spotPython.hyperparameters.values import set_control_hyperparameter_value\n", |
| 1837 | + "set_control_hyperparameter_value(fun_control, \"l1\", [3,8])\n", |
| 1838 | + "set_control_hyperparameter_value(fun_control, \"epochs\", [4,9])\n", |
| 1839 | + "set_control_hyperparameter_value(fun_control, \"batch_size\", [1, 4])\n", |
| 1840 | + "set_control_hyperparameter_value(fun_control, \"optimizer\", [\"Adam\", \"AdamW\", \"Adamax\", \"NAdam\"])" |
| 1841 | + ] |
| 1842 | + }, |
| 1843 | + { |
| 1844 | + "cell_type": "code", |
| 1845 | + "execution_count": null, |
| 1846 | + "metadata": {}, |
| 1847 | + "outputs": [], |
| 1848 | + "source": [ |
| 1849 | + "fun_control" |
| 1850 | + ] |
| 1851 | + }, |
| 1852 | + { |
| 1853 | + "cell_type": "code", |
| 1854 | + "execution_count": null, |
| 1855 | + "metadata": {}, |
| 1856 | + "outputs": [], |
| 1857 | + "source": [ |
| 1858 | + "def get_entry(dictionary, key, i):\n", |
| 1859 | + " if 'core_model_hyper_dict' in dictionary:\n", |
| 1860 | + " if key in dictionary['core_model_hyper_dict']:\n", |
| 1861 | + " if 'levels' in dictionary['core_model_hyper_dict'][key]:\n", |
| 1862 | + " if i < len(dictionary['core_model_hyper_dict'][key]['levels']):\n", |
| 1863 | + " return dictionary['core_model_hyper_dict'][key]['levels'][i]\n", |
| 1864 | + " return None\n", |
| 1865 | + "print(get_entry(fun_control, \"optimizer\", 0)) " |
| 1866 | + ] |
| 1867 | + }, |
| 1868 | + { |
| 1869 | + "cell_type": "code", |
| 1870 | + "execution_count": 3, |
1727 | 1871 | "metadata": {}, |
1728 | 1872 | "outputs": [ |
1729 | 1873 | { |
|
1732 | 1876 | "text": [ |
1733 | 1877 | "Seed set to 1234\n" |
1734 | 1878 | ] |
1735 | | - }, |
1736 | | - { |
1737 | | - "name": "stdout", |
1738 | | - "output_type": "stream", |
1739 | | - "text": [ |
1740 | | - "{'CHECKPOINT_PATH': 'runs/saved_models/', 'DATASET_PATH': 'data/', 'RESULTS_PATH': 'results/', 'TENSORBOARD_PATH': 'runs/', '_L_in': None, '_L_out': None, 'data': None, 'data_dir': './data', 'data_module': None, 'data_set': None, 'device': None, 'enable_progress_bar': False, 'eval': None, 'fun_evals': 15, 'k_folds': 3, 'log_level': 10, 'loss_function': None, 'max_time': 1, 'metric_river': None, 'metric_sklearn': None, 'metric_torch': None, 'metric_params': {}, 'model_dict': {}, 'n_samples': None, 'num_workers': 0, 'optimizer': None, 'path': None, 'prep_model': None, 'save_model': False, 'seed': 1234, 'show_batch_interval': 1000000, 'show_progress': False, 'shuffle': None, 'sigma': 0.0, 'target_column': None, 'tolerance_x': 0, 'train': None, 'test': None, 'task': 'classification', 'spot_tensorboard_path': None, 'var_name': ['l1', 'epochs', 'batch_size', 'act_fn', 'optimizer', 'dropout_prob', 'lr_mult', 'patience', 'initialization'], 'var_type': ['int', 'int', 'int', 'factor', 'factor', 'float', 'float', 'int', 'factor'], 'weights': 1.0, 'spot_writer': None, 'core_model': <class 'spotPython.light.regression.netlightregression.NetLightRegression'>, 'core_model_hyper_dict': {'l1': {'type': 'int', 'default': 3, 'transform': 'transform_power_2_int', 'lower': 1, 'upper': 7}, 'epochs': {'type': 'int', 'default': 4, 'transform': 'transform_power_2_int', 'lower': 4, 'upper': 9}, 'batch_size': {'type': 'int', 'default': 4, 'transform': 'transform_power_2_int', 'lower': 1, 'upper': 4}, 'act_fn': {'levels': ['Sigmoid', 'Tanh', 'ReLU', 'LeakyReLU', 'ELU', 'Swish'], 'type': 'factor', 'default': 'ReLU', 'transform': 'None', 'class_name': 'spotPython.torch.activation', 'core_model_parameter_type': 'instance()', 'lower': 0, 'upper': 5}, 'optimizer': {'levels': ['Adadelta', 'Adagrad', 'Adam', 'AdamW', 'SparseAdam', 'Adamax', 'ASGD', 'NAdam', 'RAdam', 'RMSprop', 'Rprop', 'SGD'], 'type': 'factor', 'default': 'SGD', 'transform': 'None', 'class_name': 'torch.optim', 'core_model_parameter_type': 'str', 'lower': 0, 'upper': 11}, 'dropout_prob': {'type': 'float', 'default': 0.01, 'transform': 'None', 'lower': 0.0, 'upper': 0.25}, 'lr_mult': {'type': 'float', 'default': 1.0, 'transform': 'None', 'lower': 0.1, 'upper': 10.0}, 'patience': {'type': 'int', 'default': 2, 'transform': 'transform_power_2_int', 'lower': 2, 'upper': 6}, 'initialization': {'levels': ['xavier2', 'kaiming2'], 'type': 'factor', 'default': 'Default', 'transform': 'None', 'core_model_parameter_type': 'str', 'lower': 0, 'upper': 1}}}\n" |
1741 | | - ] |
1742 | 1879 | } |
1743 | 1880 | ], |
1744 | 1881 | "source": [ |
| 1882 | + "from spotPython.utils.device import getDevice\n", |
1745 | 1883 | "from spotPython.utils.init import fun_control_init\n", |
1746 | | - "from spotPython.hyperparameters.values import get_control_key_value\n", |
| 1884 | + "from spotPython.utils.file import get_experiment_name, get_spot_tensorboard_path\n", |
| 1885 | + "import numpy as np\n", |
| 1886 | + "from spotPython.data.diabetes import Diabetes\n", |
1747 | 1887 | "from spotPython.light.regression.netlightregression import NetLightRegression\n", |
1748 | 1888 | "from spotPython.hyperdict.light_hyper_dict import LightHyperDict\n", |
1749 | 1889 | "from spotPython.hyperparameters.values import add_core_model_to_fun_control\n", |
| 1890 | + "from spotPython.hyperparameters.values import get_ith_hyperparameter_name_from_fun_control\n", |
| 1891 | + "from spotPython.hyperparameters.values import set_control_key_value\n", |
1750 | 1892 | "from spotPython.hyperparameters.values import set_control_hyperparameter_value\n", |
1751 | | - "\n", |
1752 | | - "fun_control = fun_control_init()\n", |
| 1893 | + "experiment_name = get_experiment_name(prefix=\"000\")\n", |
| 1894 | + "fun_control = fun_control_init(\n", |
| 1895 | + " spot_tensorboard_path=get_spot_tensorboard_path(experiment_name),\n", |
| 1896 | + " _L_in=10,\n", |
| 1897 | + " _L_out=1,\n", |
| 1898 | + " TENSORBOARD_CLEAN=True,\n", |
| 1899 | + " device=getDevice(),\n", |
| 1900 | + " enable_progress_bar=False,\n", |
| 1901 | + " fun_evals=15,\n", |
| 1902 | + " log_level=10,\n", |
| 1903 | + " max_time=1,\n", |
| 1904 | + " num_workers=0,\n", |
| 1905 | + " show_progress=True,\n", |
| 1906 | + " tolerance_x=np.sqrt(np.spacing(1)),\n", |
| 1907 | + " )\n", |
| 1908 | + "dataset = Diabetes()\n", |
| 1909 | + "set_control_key_value(control_dict=fun_control,\n", |
| 1910 | + " key=\"data_set\",\n", |
| 1911 | + " value=dataset,\n", |
| 1912 | + " replace=True)\n", |
1753 | 1913 | "add_core_model_to_fun_control(core_model=NetLightRegression,\n", |
1754 | | - " fun_control=fun_control,\n", |
1755 | | - " hyper_dict=LightHyperDict)\n", |
1756 | | - "set_control_hyperparameter_value(control_dict=fun_control, hyperparameter=\"l1\", value=[1,7])\n", |
1757 | | - "set_control_hyperparameter_value(control_dict=fun_control, hyperparameter=\"initialization\", value=[\"xavier2\", \"kaiming2\"])\n", |
1758 | | - "print(fun_control)\n" |
| 1914 | + " fun_control=fun_control,\n", |
| 1915 | + " hyper_dict=LightHyperDict)\n", |
| 1916 | + "\n", |
| 1917 | + "set_control_hyperparameter_value(fun_control, \"l1\", [3,8])\n", |
| 1918 | + "set_control_hyperparameter_value(fun_control, \"optimizer\", [\"Adam\", \"AdamW\", \"Adamax\", \"NAdam\"])\n", |
| 1919 | + "assert get_ith_hyperparameter_name_from_fun_control(fun_control, key=\"optimizer\", i=0) == \"Adam\"" |
1759 | 1920 | ] |
1760 | 1921 | }, |
1761 | 1922 | { |
|
0 commit comments