|
6709 | 6709 | }, |
6710 | 6710 | { |
6711 | 6711 | "cell_type": "code", |
6712 | | - "execution_count": 2, |
| 6712 | + "execution_count": null, |
6713 | 6713 | "metadata": {}, |
6714 | | - "outputs": [ |
6715 | | - { |
6716 | | - "name": "stderr", |
6717 | | - "output_type": "stream", |
6718 | | - "text": [ |
6719 | | - "Seed set to 123\n", |
6720 | | - "Seed set to 123\n" |
6721 | | - ] |
6722 | | - }, |
6723 | | - { |
6724 | | - "name": "stdout", |
6725 | | - "output_type": "stream", |
6726 | | - "text": [ |
6727 | | - "In update_writer().\n", |
6728 | | - "No spot_writer available.\n", |
6729 | | - "spotpython tuning: 0.0 [########--] 80.00% \n", |
6730 | | - "In update_writer().\n", |
6731 | | - "No spot_writer available.\n", |
6732 | | - "spotpython tuning: 0.0 [#########-] 86.67% \n", |
6733 | | - "In update_writer().\n", |
6734 | | - "No spot_writer available.\n", |
6735 | | - "spotpython tuning: 0.0 [#########-] 93.33% \n", |
6736 | | - "In update_writer().\n", |
6737 | | - "No spot_writer available.\n", |
6738 | | - "spotpython tuning: 0.0 [##########] 100.00% Done...\n", |
6739 | | - "\n", |
6740 | | - "S.X: [[ 0.00000000e+00 0.00000000e+00]\n", |
6741 | | - " [ 0.00000000e+00 1.00000000e+00]\n", |
6742 | | - " [ 1.00000000e+00 0.00000000e+00]\n", |
6743 | | - " [ 1.00000000e+00 1.00000000e+00]\n", |
6744 | | - " [-9.09243389e-01 -1.58234577e-01]\n", |
6745 | | - " [-2.05817107e-01 -4.81249089e-01]\n", |
6746 | | - " [ 9.49741171e-01 -9.46312716e-01]\n", |
6747 | | - " [-1.20955714e-01 6.38358863e-02]\n", |
6748 | | - " [-6.62787018e-01 1.74316373e-01]\n", |
6749 | | - " [ 2.82008441e-01 9.30010114e-01]\n", |
6750 | | - " [ 4.78788115e-01 6.53210582e-01]\n", |
6751 | | - " [ 2.80654143e-04 4.06814022e-03]\n", |
6752 | | - " [-2.09901507e-04 4.88466998e-03]\n", |
6753 | | - " [-4.56773307e-04 5.27725863e-03]\n", |
6754 | | - " [ 1.93158942e-03 1.63023818e-02]]\n", |
6755 | | - "S.y: [0.00000000e+00 1.00000000e+00 1.00000000e+00 2.00000000e+00\n", |
6756 | | - " 8.51761723e-01 2.73961367e-01 1.79751605e+00 1.87053051e-02\n", |
6757 | | - " 4.69672829e-01 9.44447573e-01 6.55922124e-01 1.66285316e-05\n", |
6758 | | - " 2.39040594e-05 2.80581006e-05 2.69498690e-04]\n" |
6759 | | - ] |
6760 | | - } |
6761 | | - ], |
| 6714 | + "outputs": [], |
6762 | 6715 | "source": [ |
6763 | 6716 | "import numpy as np\n", |
6764 | 6717 | "from spotpython.fun.objectivefunctions import Analytical\n", |
|
6843 | 6796 | }, |
6844 | 6797 | { |
6845 | 6798 | "cell_type": "code", |
6846 | | - "execution_count": 1, |
| 6799 | + "execution_count": null, |
6847 | 6800 | "metadata": {}, |
6848 | | - "outputs": [ |
6849 | | - { |
6850 | | - "name": "stderr", |
6851 | | - "output_type": "stream", |
6852 | | - "text": [ |
6853 | | - "/Users/bartz/miniforge3/envs/spot312/lib/python3.12/site-packages/lightning/pytorch/utilities/parsing.py:208: Attribute 'act_fn' is an instance of `nn.Module` and is already saved during checkpointing. It is recommended to ignore them using `self.save_hyperparameters(ignore=['act_fn'])`.\n", |
6854 | | - "GPU available: True (mps), used: True\n", |
6855 | | - "TPU available: False, using: 0 TPU cores\n", |
6856 | | - "HPU available: False, using: 0 HPUs\n", |
6857 | | - "/Users/bartz/miniforge3/envs/spot312/lib/python3.12/site-packages/lightning/pytorch/trainer/configuration_validator.py:70: You defined a `validation_step` but have no `val_dataloader`. Skipping val loop.\n", |
6858 | | - "\n", |
6859 | | - " | Name | Type | Params | Mode | In sizes | Out sizes\n", |
6860 | | - "---------------------------------------------------------------------\n", |
6861 | | - "0 | layers | Sequential | 20.2 K | train | [64, 10] | [64, 1] \n", |
6862 | | - "---------------------------------------------------------------------\n", |
6863 | | - "20.2 K Trainable params\n", |
6864 | | - "0 Non-trainable params\n", |
6865 | | - "20.2 K Total params\n", |
6866 | | - "0.081 Total estimated model params size (MB)\n", |
6867 | | - "33 Modules in train mode\n", |
6868 | | - "0 Modules in eval mode\n" |
6869 | | - ] |
6870 | | - }, |
6871 | | - { |
6872 | | - "name": "stdout", |
6873 | | - "output_type": "stream", |
6874 | | - "text": [ |
6875 | | - "torch.Size([64, 10])\n", |
6876 | | - "torch.Size([64, 1])\n" |
6877 | | - ] |
6878 | | - }, |
6879 | | - { |
6880 | | - "name": "stderr", |
6881 | | - "output_type": "stream", |
6882 | | - "text": [ |
6883 | | - "/Users/bartz/miniforge3/envs/spot312/lib/python3.12/site-packages/lightning/pytorch/trainer/connectors/data_connector.py:424: The 'train_dataloader' does not have many workers which may be a bottleneck. Consider increasing the value of the `num_workers` argument` to `num_workers=15` in the `DataLoader` to improve performance.\n", |
6884 | | - "/Users/bartz/miniforge3/envs/spot312/lib/python3.12/site-packages/lightning/pytorch/loops/fit_loop.py:298: The number of training batches (16) is smaller than the logging interval Trainer(log_every_n_steps=50). Set a lower value for log_every_n_steps if you want to see logs for the training epoch.\n" |
6885 | | - ] |
6886 | | - }, |
6887 | | - { |
6888 | | - "data": { |
6889 | | - "application/vnd.jupyter.widget-view+json": { |
6890 | | - "model_id": "cb522602e47244489babba8b4056bf38", |
6891 | | - "version_major": 2, |
6892 | | - "version_minor": 0 |
6893 | | - }, |
6894 | | - "text/plain": [ |
6895 | | - "Training: | | 0/? [00:00<?, ?it/s]" |
6896 | | - ] |
6897 | | - }, |
6898 | | - "metadata": {}, |
6899 | | - "output_type": "display_data" |
6900 | | - }, |
6901 | | - { |
6902 | | - "name": "stderr", |
6903 | | - "output_type": "stream", |
6904 | | - "text": [ |
6905 | | - "`Trainer.fit` stopped: `max_epochs=2` reached.\n", |
6906 | | - "/Users/bartz/miniforge3/envs/spot312/lib/python3.12/site-packages/lightning/pytorch/trainer/connectors/data_connector.py:424: The 'val_dataloader' does not have many workers which may be a bottleneck. Consider increasing the value of the `num_workers` argument` to `num_workers=15` in the `DataLoader` to improve performance.\n" |
6907 | | - ] |
6908 | | - }, |
6909 | | - { |
6910 | | - "data": { |
6911 | | - "application/vnd.jupyter.widget-view+json": { |
6912 | | - "model_id": "8576e16320cb450ca1a0c679b8595d01", |
6913 | | - "version_major": 2, |
6914 | | - "version_minor": 0 |
6915 | | - }, |
6916 | | - "text/plain": [ |
6917 | | - "Validation: | | 0/? [00:00<?, ?it/s]" |
6918 | | - ] |
6919 | | - }, |
6920 | | - "metadata": {}, |
6921 | | - "output_type": "display_data" |
6922 | | - }, |
6923 | | - { |
6924 | | - "data": { |
6925 | | - "text/html": [ |
6926 | | - "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", |
6927 | | - "┃<span style=\"font-weight: bold\"> Validate metric </span>┃<span style=\"font-weight: bold\"> DataLoader 0 </span>┃\n", |
6928 | | - "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", |
6929 | | - "│<span style=\"color: #008080; text-decoration-color: #008080\"> hp_metric </span>│<span style=\"color: #800080; text-decoration-color: #800080\"> 75.71305847167969 </span>│\n", |
6930 | | - "│<span style=\"color: #008080; text-decoration-color: #008080\"> val_loss </span>│<span style=\"color: #800080; text-decoration-color: #800080\"> 75.71305847167969 </span>│\n", |
6931 | | - "└───────────────────────────┴───────────────────────────┘\n", |
6932 | | - "</pre>\n" |
6933 | | - ], |
6934 | | - "text/plain": [ |
6935 | | - "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", |
6936 | | - "┃\u001b[1m \u001b[0m\u001b[1m Validate metric \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m DataLoader 0 \u001b[0m\u001b[1m \u001b[0m┃\n", |
6937 | | - "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", |
6938 | | - "│\u001b[36m \u001b[0m\u001b[36m hp_metric \u001b[0m\u001b[36m \u001b[0m│\u001b[35m \u001b[0m\u001b[35m 75.71305847167969 \u001b[0m\u001b[35m \u001b[0m│\n", |
6939 | | - "│\u001b[36m \u001b[0m\u001b[36m val_loss \u001b[0m\u001b[36m \u001b[0m│\u001b[35m \u001b[0m\u001b[35m 75.71305847167969 \u001b[0m\u001b[35m \u001b[0m│\n", |
6940 | | - "└───────────────────────────┴───────────────────────────┘\n" |
6941 | | - ] |
6942 | | - }, |
6943 | | - "metadata": {}, |
6944 | | - "output_type": "display_data" |
6945 | | - }, |
6946 | | - { |
6947 | | - "name": "stderr", |
6948 | | - "output_type": "stream", |
6949 | | - "text": [ |
6950 | | - "/Users/bartz/miniforge3/envs/spot312/lib/python3.12/site-packages/lightning/pytorch/trainer/connectors/data_connector.py:424: The 'test_dataloader' does not have many workers which may be a bottleneck. Consider increasing the value of the `num_workers` argument` to `num_workers=15` in the `DataLoader` to improve performance.\n" |
6951 | | - ] |
6952 | | - }, |
6953 | | - { |
6954 | | - "data": { |
6955 | | - "application/vnd.jupyter.widget-view+json": { |
6956 | | - "model_id": "dcc3313d031f480ca1c5ad7e6dad00e4", |
6957 | | - "version_major": 2, |
6958 | | - "version_minor": 0 |
6959 | | - }, |
6960 | | - "text/plain": [ |
6961 | | - "Testing: | | 0/? [00:00<?, ?it/s]" |
6962 | | - ] |
6963 | | - }, |
6964 | | - "metadata": {}, |
6965 | | - "output_type": "display_data" |
6966 | | - }, |
6967 | | - { |
6968 | | - "data": { |
6969 | | - "text/html": [ |
6970 | | - "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", |
6971 | | - "┃<span style=\"font-weight: bold\"> Test metric </span>┃<span style=\"font-weight: bold\"> DataLoader 0 </span>┃\n", |
6972 | | - "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", |
6973 | | - "│<span style=\"color: #008080; text-decoration-color: #008080\"> hp_metric </span>│<span style=\"color: #800080; text-decoration-color: #800080\"> 75.71305847167969 </span>│\n", |
6974 | | - "│<span style=\"color: #008080; text-decoration-color: #008080\"> val_loss </span>│<span style=\"color: #800080; text-decoration-color: #800080\"> 75.71305847167969 </span>│\n", |
6975 | | - "└───────────────────────────┴───────────────────────────┘\n", |
6976 | | - "</pre>\n" |
6977 | | - ], |
6978 | | - "text/plain": [ |
6979 | | - "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", |
6980 | | - "┃\u001b[1m \u001b[0m\u001b[1m Test metric \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m DataLoader 0 \u001b[0m\u001b[1m \u001b[0m┃\n", |
6981 | | - "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", |
6982 | | - "│\u001b[36m \u001b[0m\u001b[36m hp_metric \u001b[0m\u001b[36m \u001b[0m│\u001b[35m \u001b[0m\u001b[35m 75.71305847167969 \u001b[0m\u001b[35m \u001b[0m│\n", |
6983 | | - "│\u001b[36m \u001b[0m\u001b[36m val_loss \u001b[0m\u001b[36m \u001b[0m│\u001b[35m \u001b[0m\u001b[35m 75.71305847167969 \u001b[0m\u001b[35m \u001b[0m│\n", |
6984 | | - "└───────────────────────────┴───────────────────────────┘\n" |
6985 | | - ] |
6986 | | - }, |
6987 | | - "metadata": {}, |
6988 | | - "output_type": "display_data" |
6989 | | - }, |
6990 | | - { |
6991 | | - "data": { |
6992 | | - "text/plain": [ |
6993 | | - "[{'val_loss': 75.71305847167969, 'hp_metric': 75.71305847167969}]" |
6994 | | - ] |
6995 | | - }, |
6996 | | - "execution_count": 1, |
6997 | | - "metadata": {}, |
6998 | | - "output_type": "execute_result" |
6999 | | - } |
7000 | | - ], |
| 6801 | + "outputs": [], |
7001 | 6802 | "source": [ |
7002 | 6803 | "from torch.utils.data import DataLoader\n", |
7003 | 6804 | "from spotpython.light.regression import NNLinearRegressor\n", |
|
7049 | 6850 | }, |
7050 | 6851 | { |
7051 | 6852 | "cell_type": "code", |
7052 | | - "execution_count": 2, |
| 6853 | + "execution_count": null, |
7053 | 6854 | "metadata": {}, |
7054 | | - "outputs": [ |
7055 | | - { |
7056 | | - "data": { |
7057 | | - "text/plain": [ |
7058 | | - "array([ 36., 405., -3.])" |
7059 | | - ] |
7060 | | - }, |
7061 | | - "execution_count": 2, |
7062 | | - "metadata": {}, |
7063 | | - "output_type": "execute_result" |
7064 | | - } |
7065 | | - ], |
| 6855 | + "outputs": [], |
7066 | 6856 | "source": [ |
7067 | 6857 | "from spotpython.fun.objectivefunctions import Analytical\n", |
7068 | 6858 | "import numpy as np\n", |
|
7073 | 6863 | }, |
7074 | 6864 | { |
7075 | 6865 | "cell_type": "code", |
7076 | | - "execution_count": 5, |
| 6866 | + "execution_count": null, |
| 6867 | + "metadata": {}, |
| 6868 | + "outputs": [], |
| 6869 | + "source": [ |
| 6870 | + "from spotpython.fun.objectivefunctions import Analytical\n", |
| 6871 | + "import numpy as np\n", |
| 6872 | + "X = np.array([np.zeros(10), np.ones(10)])\n", |
| 6873 | + "fun = analytical()\n", |
| 6874 | + "fun.fun_wingwt(X)" |
| 6875 | + ] |
| 6876 | + }, |
| 6877 | + { |
| 6878 | + "cell_type": "markdown", |
| 6879 | + "metadata": {}, |
| 6880 | + "source": [ |
| 6881 | + "# Test architecture" |
| 6882 | + ] |
| 6883 | + }, |
| 6884 | + { |
| 6885 | + "cell_type": "code", |
| 6886 | + "execution_count": null, |
| 6887 | + "metadata": {}, |
| 6888 | + "outputs": [], |
| 6889 | + "source": [ |
| 6890 | + "from spotpython.hyperparameters.architecture import generate_div2_list\n", |
| 6891 | + "# call the function with all integer values between 5 and 10\n", |
| 6892 | + "for n in range(5, 21):\n", |
| 6893 | + " print(generate_div2_list(n, n_min=5))" |
| 6894 | + ] |
| 6895 | + }, |
| 6896 | + { |
| 6897 | + "cell_type": "code", |
| 6898 | + "execution_count": null, |
| 6899 | + "metadata": {}, |
| 6900 | + "outputs": [], |
| 6901 | + "source": [ |
| 6902 | + "from spotpython.hyperparameters.architecture import get_hidden_sizes\n", |
| 6903 | + "_L_in = 10\n", |
| 6904 | + "max_n = 10\n", |
| 6905 | + "for l1 in range(5, 20): \n", |
| 6906 | + " print(get_hidden_sizes(_L_in, l1, max_n))" |
| 6907 | + ] |
| 6908 | + }, |
| 6909 | + { |
| 6910 | + "cell_type": "code", |
| 6911 | + "execution_count": 3, |
| 6912 | + "metadata": {}, |
| 6913 | + "outputs": [], |
| 6914 | + "source": [ |
| 6915 | + "from math import ceil\n", |
| 6916 | + "def get_three_layers(_L_in, l1) -> list:\n", |
| 6917 | + " \"\"\"\n", |
| 6918 | + " Calculate three layers based on input values.\n", |
| 6919 | + "\n", |
| 6920 | + " Args:\n", |
| 6921 | + " _L_in (float): The input value to be multiplied.\n", |
| 6922 | + " l1 (float): The multiplier for the layers.\n", |
| 6923 | + "\n", |
| 6924 | + " Returns:\n", |
| 6925 | + " list: A list containing three calculated layers [a, b, c] where:\n", |
| 6926 | + " - a = 3 * l1 * _L_in\n", |
| 6927 | + " - b = 2 * l1 * _L_in\n", |
| 6928 | + " - c = l1 * _L_in\n", |
| 6929 | + "\n", |
| 6930 | + " Examples:\n", |
| 6931 | + " >>> from spotpython.hyperparameters.architecture import get_three_layers\n", |
| 6932 | + " _L_in = 10\n", |
| 6933 | + " l1 = 20\n", |
| 6934 | + " get_three_layers(_L_in, l1)\n", |
| 6935 | + " [600, 400, 200]\n", |
| 6936 | + " \"\"\"\n", |
| 6937 | + " a = 3 * l1 * _L_in\n", |
| 6938 | + " b = 2 * l1 * _L_in\n", |
| 6939 | + " c = ceil(l1/2) * _L_in\n", |
| 6940 | + " return [a, b, a, b, b, c, c] " |
| 6941 | + ] |
| 6942 | + }, |
| 6943 | + { |
| 6944 | + "cell_type": "code", |
| 6945 | + "execution_count": 4, |
7077 | 6946 | "metadata": {}, |
7078 | 6947 | "outputs": [ |
7079 | 6948 | { |
7080 | 6949 | "data": { |
7081 | 6950 | "text/plain": [ |
7082 | | - "array([158.28245046, 409.33182691])" |
| 6951 | + "[240, 160, 240, 160, 160, 40, 40]" |
7083 | 6952 | ] |
7084 | 6953 | }, |
7085 | | - "execution_count": 5, |
| 6954 | + "execution_count": 4, |
7086 | 6955 | "metadata": {}, |
7087 | 6956 | "output_type": "execute_result" |
| 6957 | + }, |
| 6958 | + { |
| 6959 | + "ename": "", |
| 6960 | + "evalue": "", |
| 6961 | + "output_type": "error", |
| 6962 | + "traceback": [ |
| 6963 | + "\u001b[1;31mThe Kernel crashed while executing code in the current cell or a previous cell. \n", |
| 6964 | + "\u001b[1;31mPlease review the code in the cell(s) to identify a possible cause of the failure. \n", |
| 6965 | + "\u001b[1;31mClick <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. \n", |
| 6966 | + "\u001b[1;31mView Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details." |
| 6967 | + ] |
7088 | 6968 | } |
7089 | 6969 | ], |
7090 | 6970 | "source": [ |
7091 | | - "from spotpython.fun.objectivefunctions import Analytical\n", |
7092 | | - "import numpy as np\n", |
7093 | | - "X = np.array([np.zeros(10), np.ones(10)])\n", |
7094 | | - "fun = analytical()\n", |
7095 | | - "fun.fun_wingwt(X)" |
| 6971 | + "_L_in = 20\n", |
| 6972 | + "l1 = 4\n", |
| 6973 | + "get_three_layers(_L_in, l1)" |
7096 | 6974 | ] |
7097 | 6975 | }, |
7098 | 6976 | { |
|
0 commit comments