diff --git a/py/.vscode/settings.json b/py/.vscode/settings.json new file mode 100644 index 0000000..0c094c9 --- /dev/null +++ b/py/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "~/miniconda3/bin/python" +} \ No newline at end of file diff --git a/py/.vscode/settings.json b/py/.vscode/settings.json new file mode 100644 index 0000000..0c094c9 --- /dev/null +++ b/py/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "~/miniconda3/bin/python" +} \ No newline at end of file diff --git a/py/bayes.ipynb b/py/bayes.ipynb deleted file mode 100644 index 786f655..0000000 --- a/py/bayes.ipynb +++ /dev/null @@ -1,59 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 5, - "outputs": [], - "source": "\nimport numpy as np\n\nnp.arange(16)\n??np\n\n", - "metadata": { - "pycharm": { - "metadata": false, - "name": "#%%\n", - "is_executing": false - } - } - }, - { - "cell_type": "code", - "execution_count": null, - "outputs": [], - "source": "paste(\u0027a\u0027,\u0027b\u0027)\n\n??", - "metadata": { - "pycharm": { - "metadata": false, - "name": "#%%\n" - } - } - } - ], - "metadata": { - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 2 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.6" - }, - "kernelspec": { - "name": "python3", - "language": "python", - "display_name": "Python 3" - }, - "stem_cell": { - "cell_type": "raw", - "source": "", - "metadata": { - "pycharm": { - "metadata": false - } - } - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/py/.vscode/settings.json b/py/.vscode/settings.json new file mode 100644 index 0000000..0c094c9 --- /dev/null +++ b/py/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "~/miniconda3/bin/python" +} \ No newline at end of file diff --git a/py/bayes.ipynb b/py/bayes.ipynb deleted file mode 100644 index 786f655..0000000 --- a/py/bayes.ipynb +++ /dev/null @@ -1,59 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 5, - "outputs": [], - "source": "\nimport numpy as np\n\nnp.arange(16)\n??np\n\n", - "metadata": { - "pycharm": { - "metadata": false, - "name": "#%%\n", - "is_executing": false - } - } - }, - { - "cell_type": "code", - "execution_count": null, - "outputs": [], - "source": "paste(\u0027a\u0027,\u0027b\u0027)\n\n??", - "metadata": { - "pycharm": { - "metadata": false, - "name": "#%%\n" - } - } - } - ], - "metadata": { - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 2 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.6" - }, - "kernelspec": { - "name": "python3", - "language": "python", - "display_name": "Python 3" - }, - "stem_cell": { - "cell_type": "raw", - "source": "", - "metadata": { - "pycharm": { - "metadata": false - } - } - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/py/bayesian_inference.py b/py/bayesian_inference.py new file mode 100644 index 0000000..01ef6b0 --- /dev/null +++ b/py/bayesian_inference.py @@ -0,0 +1,9 @@ +# To add a new cell, type '#%%' +# To add a new markdown cell, type '#%% [markdown]' + +#%% + +import numpy as np + +np.arange(16) + diff --git a/py/.vscode/settings.json b/py/.vscode/settings.json new file mode 100644 index 0000000..0c094c9 --- /dev/null +++ b/py/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "~/miniconda3/bin/python" +} \ No newline at end of file diff --git a/py/bayes.ipynb b/py/bayes.ipynb deleted file mode 100644 index 786f655..0000000 --- a/py/bayes.ipynb +++ /dev/null @@ -1,59 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 5, - "outputs": [], - "source": "\nimport numpy as np\n\nnp.arange(16)\n??np\n\n", - "metadata": { - "pycharm": { - "metadata": false, - "name": "#%%\n", - "is_executing": false - } - } - }, - { - "cell_type": "code", - "execution_count": null, - "outputs": [], - "source": "paste(\u0027a\u0027,\u0027b\u0027)\n\n??", - "metadata": { - "pycharm": { - "metadata": false, - "name": "#%%\n" - } - } - } - ], - "metadata": { - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 2 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.6" - }, - "kernelspec": { - "name": "python3", - "language": "python", - "display_name": "Python 3" - }, - "stem_cell": { - "cell_type": "raw", - "source": "", - "metadata": { - "pycharm": { - "metadata": false - } - } - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/py/bayesian_inference.py b/py/bayesian_inference.py new file mode 100644 index 0000000..01ef6b0 --- /dev/null +++ b/py/bayesian_inference.py @@ -0,0 +1,9 @@ +# To add a new cell, type '#%%' +# To add a new markdown cell, type '#%% [markdown]' + +#%% + +import numpy as np + +np.arange(16) + diff --git a/py/kl.py b/py/kl.py new file mode 100644 index 0000000..c65d079 --- /dev/null +++ b/py/kl.py @@ -0,0 +1,55 @@ +#%% +import numpy as np +from scipy.stats import norm, poisson + +from matplotlib import pyplot as plt +import tensorflow as tf +import seaborn as sns +sns.set() + + +def kl(p, q): + return np.sum(np.where(p!=0, p*np.log(p/q),0)) + + +# example +x = np.arange(-10,10,0.001) +p = norm.pdf(x,0,1) +q = norm.pdf(x,1,2) + +plt.title(f'KL(P||Q) = {kl(p,q):.2f}') +plt.plot(x,p) +plt.plot(x,q, color="red") +plt.show() +#%% +# poisson distribution +from scipy.stats import poisson as poi +r = poisson.cdf(x, 0.9) +plt.plot(x, r, color="green") +plt.show() + +x = np.arange(20) +lambda_ = [1.5, 4.25] +colors = ["#348ABD", "#A60628"] + +# lambda = 1.5 +plt.bar(x, poi.pmf(x, 1.5), color="red", label="$\lambda = 1.5$", alpha=0.60, lw="3") + +plt.bar(x, poi.pmf(x, 4.5), color="blue", label="$\lambda = 4.5$", alpha=0.60, lw="3") + +plt.xticks(x + 0.4, x) +plt.ylabel("Probability of $k$") +plt.xlabel("$k$") +plt.show() + +#%% +# exponentional dist (EXP) +from scipy.stats import expon as expo + +x = np.linspace(0,4,100) +colors = ['red','blue'] +lambdas = [0.5, 1.0] + +for l, c in zip(lambdas, colors): + y = expo.pdf(x, scale=1.0/l) + plt.plot(x, y, lw=2, color=c) diff --git a/py/.vscode/settings.json b/py/.vscode/settings.json new file mode 100644 index 0000000..0c094c9 --- /dev/null +++ b/py/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "~/miniconda3/bin/python" +} \ No newline at end of file diff --git a/py/bayes.ipynb b/py/bayes.ipynb deleted file mode 100644 index 786f655..0000000 --- a/py/bayes.ipynb +++ /dev/null @@ -1,59 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 5, - "outputs": [], - "source": "\nimport numpy as np\n\nnp.arange(16)\n??np\n\n", - "metadata": { - "pycharm": { - "metadata": false, - "name": "#%%\n", - "is_executing": false - } - } - }, - { - "cell_type": "code", - "execution_count": null, - "outputs": [], - "source": "paste(\u0027a\u0027,\u0027b\u0027)\n\n??", - "metadata": { - "pycharm": { - "metadata": false, - "name": "#%%\n" - } - } - } - ], - "metadata": { - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 2 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.6" - }, - "kernelspec": { - "name": "python3", - "language": "python", - "display_name": "Python 3" - }, - "stem_cell": { - "cell_type": "raw", - "source": "", - "metadata": { - "pycharm": { - "metadata": false - } - } - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/py/bayesian_inference.py b/py/bayesian_inference.py new file mode 100644 index 0000000..01ef6b0 --- /dev/null +++ b/py/bayesian_inference.py @@ -0,0 +1,9 @@ +# To add a new cell, type '#%%' +# To add a new markdown cell, type '#%% [markdown]' + +#%% + +import numpy as np + +np.arange(16) + diff --git a/py/kl.py b/py/kl.py new file mode 100644 index 0000000..c65d079 --- /dev/null +++ b/py/kl.py @@ -0,0 +1,55 @@ +#%% +import numpy as np +from scipy.stats import norm, poisson + +from matplotlib import pyplot as plt +import tensorflow as tf +import seaborn as sns +sns.set() + + +def kl(p, q): + return np.sum(np.where(p!=0, p*np.log(p/q),0)) + + +# example +x = np.arange(-10,10,0.001) +p = norm.pdf(x,0,1) +q = norm.pdf(x,1,2) + +plt.title(f'KL(P||Q) = {kl(p,q):.2f}') +plt.plot(x,p) +plt.plot(x,q, color="red") +plt.show() +#%% +# poisson distribution +from scipy.stats import poisson as poi +r = poisson.cdf(x, 0.9) +plt.plot(x, r, color="green") +plt.show() + +x = np.arange(20) +lambda_ = [1.5, 4.25] +colors = ["#348ABD", "#A60628"] + +# lambda = 1.5 +plt.bar(x, poi.pmf(x, 1.5), color="red", label="$\lambda = 1.5$", alpha=0.60, lw="3") + +plt.bar(x, poi.pmf(x, 4.5), color="blue", label="$\lambda = 4.5$", alpha=0.60, lw="3") + +plt.xticks(x + 0.4, x) +plt.ylabel("Probability of $k$") +plt.xlabel("$k$") +plt.show() + +#%% +# exponentional dist (EXP) +from scipy.stats import expon as expo + +x = np.linspace(0,4,100) +colors = ['red','blue'] +lambdas = [0.5, 1.0] + +for l, c in zip(lambdas, colors): + y = expo.pdf(x, scale=1.0/l) + plt.plot(x, y, lw=2, color=c) diff --git a/py/python.py b/py/python.py new file mode 100644 index 0000000..21c8795 --- /dev/null +++ b/py/python.py @@ -0,0 +1,7 @@ +#%% + +import this + + +#%% +print 2 diff --git a/py/.vscode/settings.json b/py/.vscode/settings.json new file mode 100644 index 0000000..0c094c9 --- /dev/null +++ b/py/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "~/miniconda3/bin/python" +} \ No newline at end of file diff --git a/py/bayes.ipynb b/py/bayes.ipynb deleted file mode 100644 index 786f655..0000000 --- a/py/bayes.ipynb +++ /dev/null @@ -1,59 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 5, - "outputs": [], - "source": "\nimport numpy as np\n\nnp.arange(16)\n??np\n\n", - "metadata": { - "pycharm": { - "metadata": false, - "name": "#%%\n", - "is_executing": false - } - } - }, - { - "cell_type": "code", - "execution_count": null, - "outputs": [], - "source": "paste(\u0027a\u0027,\u0027b\u0027)\n\n??", - "metadata": { - "pycharm": { - "metadata": false, - "name": "#%%\n" - } - } - } - ], - "metadata": { - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 2 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.6" - }, - "kernelspec": { - "name": "python3", - "language": "python", - "display_name": "Python 3" - }, - "stem_cell": { - "cell_type": "raw", - "source": "", - "metadata": { - "pycharm": { - "metadata": false - } - } - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/py/bayesian_inference.py b/py/bayesian_inference.py new file mode 100644 index 0000000..01ef6b0 --- /dev/null +++ b/py/bayesian_inference.py @@ -0,0 +1,9 @@ +# To add a new cell, type '#%%' +# To add a new markdown cell, type '#%% [markdown]' + +#%% + +import numpy as np + +np.arange(16) + diff --git a/py/kl.py b/py/kl.py new file mode 100644 index 0000000..c65d079 --- /dev/null +++ b/py/kl.py @@ -0,0 +1,55 @@ +#%% +import numpy as np +from scipy.stats import norm, poisson + +from matplotlib import pyplot as plt +import tensorflow as tf +import seaborn as sns +sns.set() + + +def kl(p, q): + return np.sum(np.where(p!=0, p*np.log(p/q),0)) + + +# example +x = np.arange(-10,10,0.001) +p = norm.pdf(x,0,1) +q = norm.pdf(x,1,2) + +plt.title(f'KL(P||Q) = {kl(p,q):.2f}') +plt.plot(x,p) +plt.plot(x,q, color="red") +plt.show() +#%% +# poisson distribution +from scipy.stats import poisson as poi +r = poisson.cdf(x, 0.9) +plt.plot(x, r, color="green") +plt.show() + +x = np.arange(20) +lambda_ = [1.5, 4.25] +colors = ["#348ABD", "#A60628"] + +# lambda = 1.5 +plt.bar(x, poi.pmf(x, 1.5), color="red", label="$\lambda = 1.5$", alpha=0.60, lw="3") + +plt.bar(x, poi.pmf(x, 4.5), color="blue", label="$\lambda = 4.5$", alpha=0.60, lw="3") + +plt.xticks(x + 0.4, x) +plt.ylabel("Probability of $k$") +plt.xlabel("$k$") +plt.show() + +#%% +# exponentional dist (EXP) +from scipy.stats import expon as expo + +x = np.linspace(0,4,100) +colors = ['red','blue'] +lambdas = [0.5, 1.0] + +for l, c in zip(lambdas, colors): + y = expo.pdf(x, scale=1.0/l) + plt.plot(x, y, lw=2, color=c) diff --git a/py/python.py b/py/python.py new file mode 100644 index 0000000..21c8795 --- /dev/null +++ b/py/python.py @@ -0,0 +1,7 @@ +#%% + +import this + + +#%% +print 2 diff --git a/py/tensorflow_playground.py b/py/tensorflow_playground.py new file mode 100644 index 0000000..e00498e --- /dev/null +++ b/py/tensorflow_playground.py @@ -0,0 +1,39 @@ +#%% +import tensorflow as tf + +from tensorflow import keras + +import numpy as np +import matplotlib.pyplot as plt + + +print(tf.__version__) +fashion_mnist = keras.datasets.fashion_mnist + +(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data() + + +class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot'] + +plt.figure() +plt.imshow(train_images[10]) +plt.colorbar() +plt.grid(False) +plt.show() + +# scale +train_images = train_images / 255.0 +test_images = test_images / 255.0 + + +plt.figure(figsize=(10,10)) + +for i in range(25): + plt.subplot(5,5, i+1) + plt.xticks([]) + plt.yticks([]) + plt.imshow(train_images[i], cmap=plt.cm.Blues) + plt.xlabel(class_names[train_labels[i]]) +plt.show() + +#%%