Created
April 20, 2017 14:27
-
-
Save shotarok/053f5d4ce890d55b224198020ed03d8e to your computer and use it in GitHub Desktop.
Alternating Direction Method of Multipliers (ADMM) for Lasso
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"'%.3f'" | |
] | |
}, | |
"execution_count": 1, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"import numpy as np\n", | |
"import numpy.random as random\n", | |
"import scipy as sp\n", | |
"from pandas import Series,DataFrame\n", | |
"import pandas as pd\n", | |
"\n", | |
"# 可視化モジュール\n", | |
"import matplotlib.pyplot as plt\n", | |
"import matplotlib as mpl\n", | |
"import seaborn as sns\n", | |
"%matplotlib inline\n", | |
"\n", | |
"# 小数第3まで表示\n", | |
"%precision 3" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# ADMM\n", | |
"ref. http://www-adsys.sys.i.kyoto-u.ac.jp/mohzeki/Presentation/lecturenote20160822.pdf" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"N = 100\n", | |
"M = 50\n", | |
"K = 10\n", | |
"# A = random.random((M, N))\n", | |
"A = random.random((N, N))\n", | |
"x0 = np.vstack((random.random((K, 1)), np.zeros((N-K, 1))))\n", | |
"random.shuffle(x0)\n", | |
"y = np.dot(A, x0)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"# ADMM\n", | |
"# initialization\n", | |
"x = np.zeros((N, 1))\n", | |
"z = np.zeros((N, 1))\n", | |
"u = np.zeros((N, 1))\n", | |
"\n", | |
"# coefficient of the penalty term\n", | |
"mu = 1.0\n", | |
"lam = 1.0\n", | |
"\n", | |
"A1 = np.dot(A.T, np.linalg.inv(np.dot(A, A.T)))\n", | |
"A2 = np.eye(N, N) - np.dot(A1, A)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"def soft_threshold(y, lam):\n", | |
" y[y > lam] -= lam\n", | |
" y[y < lam] += lam\n", | |
" return y" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"[ 0.084 0.973 0.791 0.821 0.213 0.103 0.21 0.87 0.19 0.67 ]\n", | |
"[ 0.084 0.973 0.791 0.821 0.213 0.103 0.21 0.87 0.19 0.67 ]\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAD4CAYAAADxeG0DAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnXuQLNdd3z+ne2Z2796792p1tZIsgW38OsaYl4yChG0s\nI4eXqXKBRSVVEGKwiwSUlCEViHkG4gSnoFwKMvkDVx4ESAxVJH6VDcg4jmUQCbJclsEWR35I+KHX\nXt2re/c+dmf6kT+6T0/PbO/u7M7p7TPdv0+VSnPnsXPOTPd3fv09v/P7qTRNEQRBEBaXoOkBCIIg\nCPMhQi4IgrDgiJALgiAsOCLkgiAIC44IuSAIwoLTO+o33NjYPHSazNraCufOXXY5nIWgi/Pu4pyh\nm/Pu4pzh4PNeX19Vuz22UBF5rxc2PYRG6OK8uzhn6Oa8uzhncDvvmSJyrfVLgfcCdxljfmvqsdcA\nvwbEwAeNMW91NjpBEARhX/aNyLXWx4F3AB/e5Sl3A68HXg58p9b6Je6G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vI1v7eS4wAr4C/BDwO0zNVWt9B/AzZOnV7zDG/PeDvNfCCLkg\nCIJQzaJYK4IgCMIuiJALgiAsOCLkgiAIC44IuSAIwoIjQi4IgrDgiJALgiAsOCLkgiAIC87/B9XJ\naMOUScdOAAAAAElFTkSuQmCC\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x7f68fc7f1c50>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"def ADMM(T, x, z, u):\n", | |
" for t in range(T):\n", | |
" x = np.dot(A1, y) + np.dot(A2, z - u)\n", | |
" z = soft_threshold(x + u, 1/mu)\n", | |
" u = u + x - z\n", | |
" return x\n", | |
"\n", | |
"ans = ADMM(10, x, z, u)\n", | |
"\n", | |
"print(ans[ans > 0.01])\n", | |
"print(x0[x0 > 0.01])\n", | |
" \n", | |
"plt.plot(range(N), ans)\n", | |
"plt.plot(range(N), x0)\n", | |
"plt.grid(True)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.0" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment