{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"markdown","source":"$ \\sigma_{clipped} = max(\\sigma, 70), $\n\n$ \\Delta_{clipped} = min ( |FVC_{true} - FVC_{predicted}|, 1000 ), $\n\n$ s_{clipped} = - \\frac{\\sqrt{2} \\Delta_{clipped}}{\\sigma_{clipped}} - \\ln ( \\sqrt{2} \\sigma_{clipped} ). $","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"def score(delta_clipped,sigma_clipped):\n    score = - np.sqrt(2) * delta_clipped / sigma_clipped - np.log(np.sqrt(2) * sigma_clipped)\n    return score","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"delta_values = [x for x in range(0,350,10)]\nsigma_values = [x for x in range(70,8000,10)]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from pylab import meshgrid\nX,Y = meshgrid(delta_values, sigma_values)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from mpl_toolkits.mplot3d import Axes3D\nfrom matplotlib import cm\nfrom matplotlib.ticker import LinearLocator, FormatStrFormatter\n\nfig = plt.figure(figsize=(10,10))\nax = fig.gca(projection='3d')\nsurf = ax.plot_surface(X, Y, score(X,Y), rstride=1, cstride=1, \n                      cmap=cm.RdBu,linewidth=0, antialiased=False)\n\nax.zaxis.set_major_locator(LinearLocator(10))\nax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))\n\nfig.colorbar(surf, shrink=0.5, aspect=10)\n\nax.view_init(20, 310)\n\n\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"- For bad prediction, i.e. large value $\\Delta$, a large uncertainty of the prediction, i.e. large $\\sigma_{pred}$, shows that the model knows about its own limitations, which is rewarded by the loss function as smaller error value.\n- However, for very good predictions it is necessary to be at also certain, i.e. ther exists a optimum value, $\\sigma_{true}$, for the confidence value:\n   - $\\sigma_{true} = \\sqrt{2} \\Delta(y_{pred}, y_{true})$","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"$$ s = - \\frac{\\sqrt{2} \\Delta}{\\sigma} - \\ln ( \\sqrt{2} \\sigma ). $$\n$$ \\frac{\\partial s}{\\partial \\sigma} \\overset{!}{=}0 $$\n$$ \\rightarrow \\sigma_{max} = \\sqrt{2} \\Delta  = \\sigma_{true} $$","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}