Skip to content

Instantly share code, notes, and snippets.

@shaabhishek
Last active April 16, 2021 16:10
Show Gist options
  • Save shaabhishek/7df10eddd699f7c0f32a13de8afe3278 to your computer and use it in GitHub Desktop.
Save shaabhishek/7df10eddd699f7c0f32a13de8afe3278 to your computer and use it in GitHub Desktop.
contour plot experiments
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "contour plot experiments",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyM4QyWFkd3n7KbNt8x5Wcqt",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/shaabhishek/7df10eddd699f7c0f32a13de8afe3278/contour-plot-experiments.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "FupenEW807rx"
},
"source": [
"import numpy as np\n",
"import torch\n",
"import matplotlib.pyplot as plt\n",
"from scipy.optimize import minimize"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "vFviWO2G1Bz1"
},
"source": [
"x = np.linspace(0, 1, 5)\n",
"y = np.linspace(0, 1, 5)\n",
"\n",
"X, Y = np.meshgrid(x, y)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "zE-IlsRY1NrL"
},
"source": [
"def f(x, y):\n",
" return (x-.5) ** 2 + (y-.5) ** 2"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "vuD9aHvP9mDX"
},
"source": [
"F = lambda x: f(*x)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 392
},
"id": "e2NeN9DU1HgR",
"outputId": "e2a08aea-3deb-44db-caeb-e60c054b1cab"
},
"source": [
"fig, ax = plt.subplots(1, 1, figsize=(6, 6))\n",
"mappable = ax.contourf(X, Y, f(X,Y));\n",
"ax.scatter(*minimize(F, np.zeros(2)).x, marker='x', c='red')\n",
"fig.colorbar(mappable, ax=ax)\n",
"f(X,Y).shape"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"(5, 5)"
]
},
"metadata": {
"tags": []
},
"execution_count": 20
},
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAFpCAYAAABnHGgVAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3df/RcdX3n8ecrgQCVGJEo2iRIqpE1okc0i1aPFeWHwd0l3fVXYG1hF5uKpmuXumfx2IMu2l2sqz21jdVUqcg5NkRPa79njYIiHFpbMLGwQMJGQkD4RioCMYr8CIH3/jH3i8Nkvt+5M3Nn5nM/9/U453uYe+9n7nxuZnjd93zunXsVEZiZWV7mTboDZmZWPYe7mVmGHO5mZhlyuJuZZcjhbmaWIYe7mVmGeoa7pEsl3Sfp1lmWS9KnJe2SdLOkV1bfTTOz9ElaLWlnkYcXztHurZJC0qq2eR8snrdT0puH7UuZyv2LwOo5lp8BrCj+1gF/MWynzMzqRtJ8YAOtTFwJnCVpZZd2C4H3Aze0zVsJrAVeSitvP1Osb2A9wz0irgMenKPJGuBL0XI98CxJzx+mU2ZmNXQSsCsidkfEfmATrXzs9FHg48CjbfPWAJsi4rGIuBPYVaxvYFWMuS8B7mmbni7mmZk1Sc8sLIatl0XE1/t9br8OGebJ/ZK0jtbQDVqw4FWHHvPcyl9j/mFPVL7OnDxzwaO9G5kVjp7/0KS7AMCOWx6/PyKeM8w6Xnfy4fHTB58cp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xrFpVglLaY1TLN7nJ0cQJntuhs4BUDSS2iF+0/G2svqTQG/XZw18xpgX/zySovWadRHbGkd4f4BraP7HyrmXUwrGKD1ofsKsAv4HvBrkz7KXME2fRv4MXBT8Tc16T5XsV0dba8l8bNlSr5XojXctIPWBTTXTrrPFW3XSuC7tM6kuQk4fdJ9LrFNfw3cCzxO6xvVecB7gPe0vVcbim2+pQ6fv0n++ReqZmYZ8i9Uzcwy5HA3M8uQw93MLEMOdzOzDDnczcwy5HA3M8uQw93MLEMOdzOzDP1/ahxurCyNi1UAAAAASUVORK5CYII=\n",
"text/plain": [
"<Figure size 432x432 with 2 Axes>"
]
},
"metadata": {
"tags": [],
"needs_background": "light"
}
}
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "xIgmJAX81nHc",
"outputId": "66c0f993-bc08-4f24-9910-2891a8b0967c"
},
"source": [
"np.mgrid[0:1.1:.25, 0:1.1:.25]"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([[[0. , 0. , 0. , 0. , 0. ],\n",
" [0.25, 0.25, 0.25, 0.25, 0.25],\n",
" [0.5 , 0.5 , 0.5 , 0.5 , 0.5 ],\n",
" [0.75, 0.75, 0.75, 0.75, 0.75],\n",
" [1. , 1. , 1. , 1. , 1. ]],\n",
"\n",
" [[0. , 0.25, 0.5 , 0.75, 1. ],\n",
" [0. , 0.25, 0.5 , 0.75, 1. ],\n",
" [0. , 0.25, 0.5 , 0.75, 1. ],\n",
" [0. , 0.25, 0.5 , 0.75, 1. ],\n",
" [0. , 0.25, 0.5 , 0.75, 1. ]]])"
]
},
"metadata": {
"tags": []
},
"execution_count": 47
}
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Y1w3Ug_V2qf1",
"outputId": "788753c2-125f-402e-f65a-eeacce9d1070"
},
"source": [
"np.mgrid[0:1.1:.25, 0:1.1:.25].reshape(2, -1).T#.reshape(2, 5, 5)"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([[0. , 0. ],\n",
" [0. , 0.25],\n",
" [0. , 0.5 ],\n",
" [0. , 0.75],\n",
" [0. , 1. ],\n",
" [0.25, 0. ],\n",
" [0.25, 0.25],\n",
" [0.25, 0.5 ],\n",
" [0.25, 0.75],\n",
" [0.25, 1. ],\n",
" [0.5 , 0. ],\n",
" [0.5 , 0.25],\n",
" [0.5 , 0.5 ],\n",
" [0.5 , 0.75],\n",
" [0.5 , 1. ],\n",
" [0.75, 0. ],\n",
" [0.75, 0.25],\n",
" [0.75, 0.5 ],\n",
" [0.75, 0.75],\n",
" [0.75, 1. ],\n",
" [1. , 0. ],\n",
" [1. , 0.25],\n",
" [1. , 0.5 ],\n",
" [1. , 0.75],\n",
" [1. , 1. ]])"
]
},
"metadata": {
"tags": []
},
"execution_count": 49
}
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "dz0dd6Ni4uJu",
"outputId": "2b81f039-bfc4-4e7e-a6d2-63279cb661e9"
},
"source": [
"phi_grid = np.mgrid[0:1.1:.25, 0:1.1:.25].reshape(2, -1).T\n",
"# torch.from_numpy(phi_grid)"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"tensor([[0.0000, 0.0000],\n",
" [0.0000, 0.2500],\n",
" [0.0000, 0.5000],\n",
" [0.0000, 0.7500],\n",
" [0.0000, 1.0000],\n",
" [0.2500, 0.0000],\n",
" [0.2500, 0.2500],\n",
" [0.2500, 0.5000],\n",
" [0.2500, 0.7500],\n",
" [0.2500, 1.0000],\n",
" [0.5000, 0.0000],\n",
" [0.5000, 0.2500],\n",
" [0.5000, 0.5000],\n",
" [0.5000, 0.7500],\n",
" [0.5000, 1.0000],\n",
" [0.7500, 0.0000],\n",
" [0.7500, 0.2500],\n",
" [0.7500, 0.5000],\n",
" [0.7500, 0.7500],\n",
" [0.7500, 1.0000],\n",
" [1.0000, 0.0000],\n",
" [1.0000, 0.2500],\n",
" [1.0000, 0.5000],\n",
" [1.0000, 0.7500],\n",
" [1.0000, 1.0000]], dtype=torch.float64)"
]
},
"metadata": {
"tags": []
},
"execution_count": 61
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "2r5XdoAUAvNv"
},
"source": [
"elbos = np.random.rand(len(phi_grid))"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "75m_J0xoAcK2"
},
"source": [
"elbo_xi = {str(phi.astype(int)): elbo for phi, elbo in zip(phi_grid, elbos) if tuple(phi) in [(0,0), (0,1), (1,0), (1,1)]}\n",
"sorted_phi = sorted(elbo_xi.keys(), key=lambda phi: elbo_xi[phi])"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"id": "YZsk8zgBA2uB",
"outputId": "2b678010-44c6-4285-cc22-5ce45bd8342f"
},
"source": [
"# print(\"ELBO order: \")\n",
"\" < \".join(sorted_phi)"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'[0 1] < [1 1] < [1 0] < [0 0]'"
]
},
"metadata": {
"tags": []
},
"execution_count": 105
}
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "5YCFpbD8BVIC",
"outputId": "952cc1be-c17b-4161-aba3-fcb018880378"
},
"source": [
"np.mgrid[0:1.01:.2, 0:1.01:.2].shape"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"(2, 6, 6)"
]
},
"metadata": {
"tags": []
},
"execution_count": 110
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment