{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": [],
      "authorship_tag": "ABX9TyOuVJf5JFcP9f4IvjieVGL2",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/Sahel-Eskandar/Project-Notebooks/blob/main/7_ANFIS_TensorFlow.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "!git clone https://github.com/Sahel-Eskandar/TensorANFIS.git"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "lwfEfbdD-Una",
        "outputId": "ce7b678f-3f5b-4292-8b4f-9e0a51db36cf"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Cloning into 'TensorANFIS'...\n",
            "remote: Enumerating objects: 49, done.\u001b[K\n",
            "remote: Counting objects: 100% (19/19), done.\u001b[K\n",
            "remote: Compressing objects: 100% (19/19), done.\u001b[K\n",
            "remote: Total 49 (delta 6), reused 0 (delta 0), pack-reused 30\u001b[K\n",
            "Unpacking objects: 100% (49/49), done.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "cd '/content/TensorANFIS'"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "y2qYD563ADLb",
        "outputId": "d921d9d8-45d6-438a-902b-a090cfc65e8e"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "/content/TensorANFIS\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "!git pull "
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "zhm_97-6_qbG",
        "outputId": "660dc282-c175-4ade-f491-0f76d9d10f49"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Already up to date.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "!git status"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "J4sOVU6cGpkS",
        "outputId": "aa4a8109-fad6-4535-e09f-92896059ff67"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "On branch master\n",
            "Your branch is up to date with 'origin/master'.\n",
            "\n",
            "nothing to commit, working tree clean\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "!cp /content/TensorANFIS/anfis.py ."
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "1nGdoII5nbiL",
        "outputId": "ffcdb4e5-146c-4eb6-9578-baeac9237fdd"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "cp: '/content/TensorANFIS/anfis.py' and './anfis.py' are the same file\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "import anfis"
      ],
      "metadata": {
        "id": "5NygUxrJnnR-",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "2abadba9-b1d0-4b90-def6-6dc67cd9eeac"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow/python/compat/v2_compat.py:107: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.\n",
            "Instructions for updating:\n",
            "non-resource variables are not supported in the long term\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "import time\n",
        "import tensorflow.compat.v1 as tf\n",
        "tf.disable_v2_behavior()\n",
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "from anfis import ANFIS"
      ],
      "metadata": {
        "id": "YsFNKraPp7WP"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "class ANFIS:\n",
        "    def __init__(self, n_inputs, n_rules, learning_rate=1e-2):\n",
        "        self.n = n_inputs\n",
        "        self.m = n_rules\n",
        "        self.inputs = tf.placeholder(tf.float32, shape=(None, n_inputs))  # Input\n",
        "        self.targets = tf.placeholder(tf.float32, shape=None)  # Desired output\n",
        "        mu = tf.get_variable(\"mu\", [n_rules * n_inputs],\n",
        "                             initializer=tf.random_normal_initializer(0, 1))  # Means of Gaussian MFS\n",
        "        sigma = tf.get_variable(\"sigma\", [n_rules * n_inputs],\n",
        "                                initializer=tf.random_normal_initializer(0, 1))  # Standard deviations of Gaussian MFS\n",
        "        y = tf.get_variable(\"y\", [1, n_rules], initializer=tf.random_normal_initializer(0, 1))  # Sequent centers\n",
        "\n",
        "        self.params = tf.trainable_variables()\n",
        "\n",
        "        self.rul = tf.reduce_prod(\n",
        "            tf.reshape(tf.exp(-0.5 * tf.square(tf.subtract(tf.tile(self.inputs, (1, n_rules)), mu)) / tf.square(sigma)),\n",
        "                       (-1, n_rules, n_inputs)), axis=2)  # Rule activations\n",
        "        # Fuzzy base expansion function:\n",
        "        num = tf.reduce_sum(tf.multiply(self.rul, y), axis=1)\n",
        "        den = tf.clip_by_value(tf.reduce_sum(self.rul, axis=1), 1e-12, 1e12)\n",
        "        self.out = tf.divide(num, den)\n",
        "\n",
        "        self.loss = tf.losses.huber_loss(self.targets, self.out)  # Loss function computation\n",
        "        # Other loss functions for regression, uncomment to try them:\n",
        "        # loss = tf.sqrt(tf.losses.mean_squared_error(target, out))\n",
        "        # loss = tf.losses.absolute_difference(target, out)\n",
        "        self.optimize = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(self.loss)  # Optimization step\n",
        "        # Other optimizers, uncomment to try them:\n",
        "        # self.optimize = tf.train.RMSPropOptimizer(learning_rate=learning_rate).minimize(self.loss)\n",
        "        # self.optimize = tf.train.GradientDescentOptimizer(learning_rate=learning_rate).minimize(self.loss)\n",
        "        self.init_variables = tf.global_variables_initializer()  # Variable initializer\n",
        "\n",
        "    def infer(self, sess, x, targets=None):\n",
        "        if targets is None:\n",
        "            return sess.run(self.out, feed_dict={self.inputs: x})\n",
        "        else:\n",
        "            return sess.run([self.out, self.loss], feed_dict={self.inputs: x, self.targets: targets})\n",
        "\n",
        "    def train(self, sess, x, targets):\n",
        "        yp, l, _ = sess.run([self.out, self.loss, self.optimize], feed_dict={self.inputs: x, self.targets: targets})\n",
        "        return l, yp\n",
        "\n",
        "    def plotmfs(self, sess):\n",
        "        mus = sess.run(self.params[0])\n",
        "        mus = np.reshape(mus, (self.m, self.n))\n",
        "        sigmas = sess.run(self.params[1])\n",
        "        sigmas = np.reshape(sigmas, (self.m, self.n))\n",
        "        y = sess.run(self.params[2])\n",
        "        xn = np.linspace(-1.5, 1.5, 1000)\n",
        "        for r in range(self.m):\n",
        "            if r % 4 == 0:\n",
        "                plt.figure(figsize=(11, 6), dpi=80)\n",
        "            plt.subplot(2, 2, (r % 4) + 1)\n",
        "            ax = plt.subplot(2, 2, (r % 4) + 1)\n",
        "            ax.set_title(\"Rule %d, sequent center: %f\" % ((r + 1), y[0, r]))\n",
        "            for i in range(self.n):\n",
        "                plt.plot(xn, np.exp(-0.5 * ((xn - mus[r, i]) ** 2) / (sigmas[r, i] ** 2)))\n"
      ],
      "metadata": {
        "id": "lMSfGjE-hzkB"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# Mackey-Glass series computation\n",
        "def mackey(n_iters):\n",
        "    x = np.zeros((n_iters,))\n",
        "    x[0:30] = 0.23 * np.ones((30,))\n",
        "    t_s = 30\n",
        "    for i in range(30, n_iters - 1):\n",
        "        a = x[i]\n",
        "        b = x[i - t_s]\n",
        "        y = ((0.2 * b) / (1 + b ** 10)) + 0.9 * a\n",
        "        x[i + 1] = y\n",
        "    return x"
      ],
      "metadata": {
        "id": "SeM5JxJuqHyD"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# Generate dataset\n",
        "D = 4  # number of regressors\n",
        "T = 1  # delay\n",
        "N = 2000  # Number of points to generate\n",
        "mg_series = mackey(N)[499:]  # Use last 1500 points\n",
        "data = np.zeros((N - 500 - T - (D - 1) * T, D))\n",
        "lbls = np.zeros((N - 500 - T - (D - 1) * T,))"
      ],
      "metadata": {
        "id": "L1BgLzOdrh36"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "plt.figure(1)\n",
        "plt.plot(mg_series)\n",
        "plt.show()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 265
        },
        "id": "Ei8tG4otrHqW",
        "outputId": "1f79efde-51af-41dc-ddd4-54f47603c1fe"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ],
            "image/png": "[encoded data, 40632 characters]\n"
          },
          "metadata": {
            "needs_background": "light"
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "for t in range((D - 1) * T, N - 500 - T):\n",
        "    data[t - (D - 1) * T, :] = [mg_series[t - 3 * T], mg_series[t - 2 * T], mg_series[t - T], mg_series[t]]\n",
        "    lbls[t - (D - 1) * T] = mg_series[t + T]\n",
        "trnData = data[:lbls.size - round(lbls.size * 0.3), :]\n",
        "trnLbls = lbls[:lbls.size - round(lbls.size * 0.3)]\n",
        "chkData = data[lbls.size - round(lbls.size * 0.3):, :]\n",
        "chkLbls = lbls[lbls.size - round(lbls.size * 0.3):]"
      ],
      "metadata": {
        "id": "htxywbFqrp4s"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "plt.figure(1)\n",
        "plt.plot(trnData[0])\n",
        "plt.plot(trnData[1])\n",
        "plt.plot(trnData[2])\n",
        "plt.plot(trnData[3])\n",
        "plt.plot(trnLbls)\n",
        "plt.show()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 265
        },
        "id": "LpNB7_BtsDRt",
        "outputId": "155ec162-2cca-4db0-f1e4-e83500935314"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ],
            "image/png": "[encoded data, 34792 characters]\n"
          },
          "metadata": {
            "needs_background": "light"
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# ANFIS params and Tensorflow graph initialization\n",
        "m = 16  # number of rules\n",
        "alpha = 0.01  # learning rate"
      ],
      "metadata": {
        "id": "VxR_iJu5z2T9"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "fis = ANFIS(n_inputs=D, n_rules=m, learning_rate=alpha)"
      ],
      "metadata": {
        "id": "FR5ytEgZz4nU"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "fis.inputs"
      ],
      "metadata": {
        "id": "NUI5sRaR82oE",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "4eaac10b-b62c-4691-fd51-0bed043405dc"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "<tf.Tensor 'Placeholder:0' shape=(?, 4) dtype=float32>"
            ]
          },
          "metadata": {},
          "execution_count": 15
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Training\n",
        "num_epochs = 100\n",
        "# Initialize session to make computations on the Tensorflow graph\n",
        "with tf.Session() as sess:\n",
        "    # Initialize model parameters\n",
        "    sess.run(fis.init_variables)\n",
        "    trn_costs = []\n",
        "    val_costs = []\n",
        "    time_start = time.time()\n",
        "    for epoch in range(num_epochs):\n",
        "        #  Run an update step\n",
        "        trn_loss, trn_pred = fis.train(sess, trnData, trnLbls)\n",
        "        # Evaluate on validation set\n",
        "        val_pred, val_loss = fis.infer(sess, chkData, chkLbls)\n",
        "        if epoch % 10 == 0:\n",
        "            print(\"Train cost after epoch %i: %f\" % (epoch, trn_loss))\n",
        "        if epoch == num_epochs - 1:\n",
        "            time_end = time.time()\n",
        "            print(\"Elapsed time: %f\" % (time_end - time_start))\n",
        "            print(\"Validation loss: %f\" % val_loss)\n",
        "            # Plot real vs. predicted\n",
        "            pred = np.vstack((np.expand_dims(trn_pred, 1), np.expand_dims(val_pred, 1)))\n",
        "            plt.figure(1)\n",
        "            plt.plot(mg_series)\n",
        "            plt.plot(pred)\n",
        "        trn_costs.append(trn_loss)\n",
        "        val_costs.append(val_loss)\n",
        "    # Plot the cost over epochs\n",
        "    plt.figure(2)\n",
        "    plt.subplot(2, 1, 1)\n",
        "    plt.plot(np.squeeze(trn_costs))\n",
        "    plt.title(\"Training loss, Learning rate =\" + str(alpha))\n",
        "    plt.subplot(2, 1, 2)\n",
        "    plt.plot(np.squeeze(val_costs))\n",
        "    plt.title(\"Validation loss, Learning rate =\" + str(alpha))\n",
        "    plt.ylabel('Cost')\n",
        "    plt.xlabel('Epochs')\n",
        "    # Plot resulting membership functions\n",
        "    fis.plotmfs(sess)\n",
        "    plt.show()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "id": "B-iaL-4lnKzR",
        "outputId": "a421b67a-41a5-4cc2-a389-574e61d4b4b5"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Train cost after epoch 0: 1.102231\n",
            "Train cost after epoch 10: 0.081611\n",
            "Train cost after epoch 20: 0.010721\n",
            "Train cost after epoch 30: 0.011641\n",
            "Train cost after epoch 40: 0.004743\n",
            "Train cost after epoch 50: 0.002671\n",
            "Train cost after epoch 60: 0.002349\n",
            "Train cost after epoch 70: 0.001906\n",
            "Train cost after epoch 80: 0.001709\n",
            "Train cost after epoch 90: 0.001561\n",
            "Elapsed time: 0.841418\n",
            "Validation loss: 0.001557\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "/content/TensorANFIS/anfis.py:61: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
            "  ax = plt.subplot(2, 2, (r % 4) + 1)\n",
            "/content/TensorANFIS/anfis.py:61: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
            "  ax = plt.subplot(2, 2, (r % 4) + 1)\n",
            "/content/TensorANFIS/anfis.py:61: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
            "  ax = plt.subplot(2, 2, (r % 4) + 1)\n",
            "/content/TensorANFIS/anfis.py:61: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
            "  ax = plt.subplot(2, 2, (r % 4) + 1)\n",
            "/content/TensorANFIS/anfis.py:61: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
            "  ax = plt.subplot(2, 2, (r % 4) + 1)\n",
            "/content/TensorANFIS/anfis.py:61: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
            "  ax = plt.subplot(2, 2, (r % 4) + 1)\n",
            "/content/TensorANFIS/anfis.py:61: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
            "  ax = plt.subplot(2, 2, (r % 4) + 1)\n",
            "/content/TensorANFIS/anfis.py:61: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
            "  ax = plt.subplot(2, 2, (r % 4) + 1)\n",
            "/content/TensorANFIS/anfis.py:61: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
            "  ax = plt.subplot(2, 2, (r % 4) + 1)\n",
            "/content/TensorANFIS/anfis.py:61: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
            "  ax = plt.subplot(2, 2, (r % 4) + 1)\n",
            "/content/TensorANFIS/anfis.py:61: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
            "  ax = plt.subplot(2, 2, (r % 4) + 1)\n",
            "/content/TensorANFIS/anfis.py:61: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
            "  ax = plt.subplot(2, 2, (r % 4) + 1)\n",
            "/content/TensorANFIS/anfis.py:61: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
            "  ax = plt.subplot(2, 2, (r % 4) + 1)\n",
            "/content/TensorANFIS/anfis.py:61: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
            "  ax = plt.subplot(2, 2, (r % 4) + 1)\n",
            "/content/TensorANFIS/anfis.py:61: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
            "  ax = plt.subplot(2, 2, (r % 4) + 1)\n",
            "/content/TensorANFIS/anfis.py:61: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
            "  ax = plt.subplot(2, 2, (r % 4) + 1)\n"
          ]
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ],
            "image/png": "[encoded data, 53448 characters]\n"
          },
          "metadata": {
            "needs_background": "light"
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 432x288 with 2 Axes>"
            ],
            "image/png": "[encoded data, 17748 characters]\n"
          },
          "metadata": {
            "needs_background": "light"
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 880x480 with 4 Axes>"
            ],
            "image/png": "[encoded data, 85324 characters]\n"
          },
          "metadata": {
            "needs_background": "light"
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 880x480 with 4 Axes>"
            ],
            "image/png": "[encoded data, 103960 characters]\n"
          },
          "metadata": {
            "needs_background": "light"
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 880x480 with 4 Axes>"
            ],
            "image/png": "[encoded data, 103628 characters]\n"
          },
          "metadata": {
            "needs_background": "light"
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 880x480 with 4 Axes>"
            ],
            "image/png": "[encoded data, 102636 characters]\n"
          },
          "metadata": {
            "needs_background": "light"
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "!git push ."
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "tpmYI3SunQ8k",
        "outputId": "12a72601-d4cd-4e15-9ea0-f2c46dc441da"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Everything up-to-date\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "%%writefile   ANFIS.ipynb\n",
        "print('my new notebook')"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "CagvnQZ2CfKx",
        "outputId": "0138fb7c-076d-4bca-fd41-1fb92a373ec5"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Overwriting ANFIS.ipynb\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "!git status"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "8GyTLS_4D6cp",
        "outputId": "6023ff0b-8ebe-40b7-c9d9-2009e275680e"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "On branch master\n",
            "Your branch is up to date with 'origin/master'.\n",
            "\n",
            "Changes to be committed:\n",
            "  (use \"git reset HEAD <file>...\" to unstage)\n",
            "\n",
            "\t\u001b[32mnew file:   ANFIS2.ipynb\u001b[m\n",
            "\t\u001b[32mnew file:   __pycache__/anfis.cpython-37.pyc\u001b[m\n",
            "\n",
            "Changes not staged for commit:\n",
            "  (use \"git add <file>...\" to update what will be committed)\n",
            "  (use \"git checkout -- <file>...\" to discard changes in working directory)\n",
            "\n",
            "\t\u001b[31mmodified:   ANFIS.ipynb\u001b[m\n",
            "\n",
            "Untracked files:\n",
            "  (use \"git add <file>...\" to include in what will be committed)\n",
            "\n",
            "\t\u001b[31mTensorANFIS/\u001b[m\n",
            "\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "!git commit . "
      ],
      "metadata": {
        "id": "joGN_k2MECKT",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "952352f8-aa77-458d-db88-8c83f4220e50"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "hint: Waiting for your editor to close the file... error: unable to start editor 'editor'\n",
            "Please supply the message using either -m or -F option.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "!git push /content/TensorANFIS"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "f7FljARJEP61",
        "outputId": "3a7e5228-7ee6-4a63-f026-8ddd2ce04941"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Everything up-to-date\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [],
      "metadata": {
        "id": "EAnlH5IGEZ0c"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}