Skip to content

Instantly share code, notes, and snippets.

@fnielsen
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fnielsen/efe0becb61729f1aa31a to your computer and use it in GitHub Desktop.
Save fnielsen/efe0becb61729f1aa31a to your computer and use it in GitHub Desktop.
Self-referential implication
from math import exp
import numpy as np
import matplotlib.pyplot as plt
def sigmoid(x):
return 1.0 / (1.0 + exp(-x))
def implication(a, b):
if (-0.5 * a + 1.0 * b) > -0.5:
return 1.0
else:
return 0.0
def soft_implication(a, b):
return -0.5 * a + 1.0 * b + 0.5
def sigmoid_implication(a, b):
return sigmoid(-0.5 * a + 1.0 * b - 0.5)
plt.figure()
for n in range(4):
plt.subplot(2, 2, n+1)
a = n // 2
b = n % 2
aa = [a]
a0 = a
for n in range(20):
a = soft_implication(a, b)
aa.append(a)
plt.plot(aa, linewidth=3.0)
plt.title('a = %d, b = %d' % (a0, b,))
plt.ylim(0, 2.)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment