<commit_before>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Code for Gradient disent "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code for calculating local minima for f(x,y)= x^4 + y^4 - x^2 - y^2 with partial derivative wrt x : 4x^3 - 2x and partial derivative wrt y: 4y^3 - 2y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Local Minimum at 0.707106781187 , 0.707106781187\n"
     ]
    }
   ],
   "source": [
    "max_iter = 1000\n",
    "x_o=0\n",
    "y_o=0\n",
    "alpha = 0.01 ## Step Size\n",
    "x_k=2 ## Starting position of x coordinate \n",
    "y_k=2 ## Starting position of y coordinate \n",
    "def devx(x): ## Defining partial derivative wrt x\n",
    "    return 4*x**3 - 2*x\n",
    "def devy(y): ## Defining partial derivation wrt y\n",
    "    return 4*y**3 -2*y\n",
    "for i in range(max_iter):\n",
    "    x_o = x_k\n",
    "    y_o = y_k\n",
    "    x_k = x_o - alpha * devx(x_o)\n",
    "    y_k = y_o - alpha * devy(y_o)\n",
    "\n",
    "print \"Local Minimum at\",x_k,\",\",y_k"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "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.10"
  }
 },<commit_msg>Updated Gradient<commit_after>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Code for Gradient disent "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code for calculating local minima for $$f(x,y)= x^4 + y^4 - x^2 - y^2$$ with partial derivative wrt x : $$4x^3 - 2x$$ and partial derivative wrt y: $$4y^3 - 2y$$ "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "max_iter = 1000\n",
    "x_o=0\n",
    "y_o=0\n",
    "alpha = 0.01 ## Step Size\n",
    "x_k=2 ## Starting position of x coordinate \n",
    "y_k=2 ## Starting position of y coordinate \n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here we set the Max iterations as 1000 and starting coordinte in ($x_k,y_k$) = (2,2) and Step size as 0.01 donated by alpha "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def devx(x): ## Defining partial derivative wrt x\n",
    "    return 4*x**3 - 2*x\n",
    "def devy(y): ## Defining partial derivation wrt y\n",
    "    return 4*y**3 -2*y\n",
    "for i in range(max_iter):\n",
    "    x_o = x_k\n",
    "    y_o = y_k\n",
    "    x_k = x_o - alpha * devx(x_o)\n",
    "    y_k = y_o - alpha * devy(y_o)\n",
    "\n",
    "print \"Local Minimum at\",x_k,\",\",y_k"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here We define 2 functions devx(x) and devy(y) as the partial derivative with respect to x:$$4x^3 - 2x$$ and partial derivative with respect to y: $$4y^3 - 2y$$ respectively . In the following loop we calculate the local minima using equations : ![Alt Text](http://www.codeproject.com/KB/recipes/879043/GradientDescent.jpg \"Gradient Descent\"). "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "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.10"
  }
 },
{'fraction_non_alphanumeric': 0.20230057514378594, 'fraction_numerical': 0.02975743935983996, 'mean_word_length': 2.5304501323918798, 'pattern_counts': {'":': 71, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3358806', 'n_tokens_mistral': 1687, 'n_tokens_neox': 1591, 'n_words': 370}