{ "metadata": { "name": "", "signature": "sha256:fa841b88a125a93576145fa0c59ab0b6f8070e5b9216257b1f990e785a13c015" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "#What is Fuzzy Logic?\n", "Everything is true to Degrees.\n", "\n", "The chief but superficial similarity is that both describe uncertainty with the numbers in the unit interval $[0,1]$\n", "\n", "##What is Logic?\n", "1. Is it always true that $A \\cap A^{c} = \\emptyset$\n", "\n", "Why does that even matter?\n", "\n", "Because everything in the world that isn't classical mathematics is Fuzzy. Fuzzy veganism, fuzzy politics. \n", "\n", "##Paradox\n", "Remember the yoga teacher paradox:\n", "In a village there is ONE yoga teacher rules are:\n", "\n", "1. (Everyone who does not teach themselves yoga) [Group A], is (taught by the yoga teacher) [Group B].\n", "2. (Everyone who is taught by the Yoga teacher) [Group B] does (not teach themselves) [Group A].\n", "\n", "Question: Who teaches the Yoga Teacher? \n", "or __Does the Yoga Teacher Teach Themselves?__\n", "\n", "Let's assume True -> False\n", "\n", "Lets assume False -> True\n", "\n", "## Paradox is the maximally Fuzzy value\n", "\n", "$ T \\rightarrow F$\n", "and $F \\rightarrow T$\n", "\n", "So. $T = F$\n", "\n", "And classical logic says $F = 1 - T$\n", "\n", "Thus $T = 1 - T$\n", "\n", "or $2T = 1$\n", "\n", "Finally $T = \\frac{1}{2}$\n", "\n", "The __truthiness is one-half__.\n", "\n", "##Fuzzy Rice Cooker\n", "```\n", "IF temperature IS very cold THEN stop fan\n", "IF temperature IS cold THEN turn down fan\n", "IF temperature IS normal THEN maintain fan\n", "IF temperature IS hot THEN speed up fan\n", "```\n", "##What is operator overloading?\n", "\n", "How to add a hobbit an apple. \n" ] }, { "cell_type": "code", "collapsed": false, "input": [ "True & False" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 66, "text": [ "False" ] } ], "prompt_number": 66 }, { "cell_type": "code", "collapsed": false, "input": [ "True | False" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 67, "text": [ "True" ] } ], "prompt_number": 67 }, { "cell_type": "code", "collapsed": false, "input": [ "not True" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 68, "text": [ "False" ] } ], "prompt_number": 68 }, { "cell_type": "code", "collapsed": false, "input": [ "int(True), int(False)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "if '':\n", " print \"'' is False\"\n", "\n", "if ' ':\n", " print \"' ' is True\"" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "'a' & 'b'" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "class fuzzy:\n", " value = 0\n", " \n", " def __init__(self, value):\n", " if (value >= 0) and (value <= 1):\n", " self.value = value\n", " else:\n", " raise ValueError('{} not in range [0,1]'.format(value))\n", " \n", " def __and__(self, other):\n", " if isinstance(other, fuzzy):\n", " return min(self.value, other.value)\n", " if isinstance(other, float):\n", " return min(self.value, other)\n", " \n", " def __or__(self, other):\n", " return max(self.value, other.value)\n", " \n", " def __neg__(self):\n", " return 1-self.value" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 91 }, { "cell_type": "code", "collapsed": false, "input": [ "pretty_warm = fuzzy(0.1)\n", "ice_cold = fuzzy(0.8)\n", "absolute_zero = fuzzy(1)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 92 }, { "cell_type": "code", "collapsed": false, "input": [ "pretty_warm | ice_cold" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 79, "text": [ "0.8" ] } ], "prompt_number": 79 }, { "cell_type": "code", "collapsed": false, "input": [ "absolute_zero & ice_cold" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 80, "text": [ "0.8" ] } ], "prompt_number": 80 }, { "cell_type": "code", "collapsed": false, "input": [ "-pretty_warm" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 81, "text": [ "0.9" ] } ], "prompt_number": 81 }, { "cell_type": "code", "collapsed": false, "input": [ "temp = 0.2 and pretty_warm" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 95 }, { "cell_type": "code", "collapsed": false, "input": [ "isinstance(temp, fuzzy)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 99, "text": [ "True" ] } ], "prompt_number": 99 }, { "cell_type": "code", "collapsed": false, "input": [ "isinstance(pretty_warm, fuzzy)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "class FuzzyObj:\n", " \n", " def __init__(self, value):\n", " self.value = value\n", " \n", " def fuzzy_and(self, fo):\n", " return min(self.value, fo.value)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 73 }, { "cell_type": "code", "collapsed": false, "input": [ "a = FuzzyObj(1)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 74 }, { "cell_type": "code", "collapsed": false, "input": [ "b = FuzzyObj(0.5)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 75 }, { "cell_type": "code", "collapsed": false, "input": [ "a.fuzzy_and(b)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 76, "text": [ "0.5" ] } ], "prompt_number": 76 }, { "cell_type": "code", "collapsed": false, "input": [ "a & b" ], "language": "python", "metadata": {}, "outputs": [ { "ename": "TypeError", "evalue": "unsupported operand type(s) for &: 'instance' and 'instance'", "output_type": "pyerr", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0ma\u001b[0m \u001b[1;33m&\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for &: 'instance' and 'instance'" ] } ], "prompt_number": 77 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }