#!/usr/bin/env python import os, sys, wx, config import matplotlib import matplotlib.numerix as nx from numpy import linalg from math import * from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg from matplotlib.figure import Figure from pyx import * matplotlib.interactive(False) def fwhm2k(fwhm): # for matplotlib Gaussian and Singleton curves """ Converts fwhm value to k (see above) """ return fwhm/(2 * nx.sqrt(nx.log(2))) def gauss1d(r, fwhm, center): """ Returns the 1d gaussian given by fwhm (full-width at half-max), and c (center) at positions given by r """ return nx.exp(-(r-center)**2 / fwhm2k(fwhm)**2) def boltzman(x, xmid, tau): """ Evaluate the boltzman function with midpoint, xmid, and time constant tau over x """ return 1.0 / (1.0 + nx.exp(-(x-xmid)/tau)) # ------------------------------------------------------------------------------ def gaussCurve(midpt, width): center = midpt fwhm = width x = nx.arange(0, 100, 0.1) G = gauss1d(x, fwhm, center) p = graph.axis.painter.regular(titlepos=0.3, titledirection=None) g = graph.graphxy(width=8, x2=None, y2=None, x=graph.axis.linear(min=0, max=100, title='Universe of Discourse'), y=graph.axis.linear(min=0.0, max=1.0, title='Membership Grade')) g.plot(x, G) # ------------------------------------------------------------------------------ def sCurve(left, right): leftend = left rightend = right midpt = ((rightend-leftend)/2.0) + leftend tau = 5.0 x = nx.arange(leftend, rightend, 0.1) S = boltzman(x, midpt, tau) p = graph.axis.painter.regular(titlepos=0.3, titledirection=None) g = graph.graphxy(width=8, x2=None, y2=None, x=graph.axis.linear(min=0, max=100, title='Universe of Discourse'), y=graph.axis.linear(min=0.0, max=1.0, title='Membership Grade')) g.plot(x, S) # ------------------------------------------------------------------------------ def zCurve(left, right): leftend = left rightend = right midpt = rightend/2.0 tau = 5.0 x = nx.arange(leftend, rightend, 0.1) Z = 1.0-boltzman(x, midpt, tau) p = graph.axis.painter.regular(titlepos=0.3, titledirection=None) g = graph.graphxy(width=8, x2=None, y2=None, x=graph.axis.linear(min=0, max=100, title='Universe of Discourse'), y=graph.axis.linear(min=0.0, max=1.0, title='Membership Grade')) g.plot(x, Z) #------------------------------------------------------------------------------ def trapezoidCurve(ll, hl, hr, lr): lowLeft = ll hiLeft = hl hiRight = hr lowRight = lr x, y = zip(*[(lowLeft, 0.0), (hiLeft, 1.0), (hiRight, 1.0), (lowRight, 0.0)]) p = graph.axis.painter.regular(titlepos=0.3, titledirection=None) g = graph.graphxy(width=8, x2=None, y2=None, x=graph.axis.linear(min=0, max=100, title='Universe of Discourse'), y=graph.axis.linear(min=0.0, max=1.0, title='Membership Grade')) g.plot(x, y) # ------------------------------------------------------------------------------ def leftShoulderCurve(hl, hr, lr): hiLeft = hl hiRight = hr lowRight = lr x, y = zip(*[(hiLeft, 1.0), (hiRight, 1.0), (lowRight, 0.0)]) p = graph.axis.painter.regular(titlepos=0.3, titledirection=None) g = graph.graphxy(width=8, x2=None, y2=None, x=graph.axis.linear(min=0, max=100, title='Universe of Discourse'), y=graph.axis.linear(min=0.0, max=1.0, title='Membership Grade')) g.plot(x, y) # ------------------------------------------------------------------------------ def rightShoulderCurve(ll, hl, hr): lowLeft = ll hiLeft = hl hiRight = hr x, y = zip(*[(lowLeft, 0.0), (hiLeft, 1.0), (hiRight, 1.0)]) p = graph.axis.painter.regular(titlepos=0.3, titledirection=None) g = graph.graphxy(width=8, x2=None, y2=None, x=graph.axis.linear(min=0, max=100, title='Universe of Discourse'), y=graph.axis.linear(min=0.0, max=1.0, title='Membership Grade')) g.plot(x, y) # ------------------------------------------------------------------------------ def triangleCurve(ll, cen, lr): lowLeft = ll center = cen lowRight = lr x, y = zip(*[(lowLeft, 0.0), (center, 1.0), (lowRight, 0.0)]) p = graph.axis.painter.regular(titlepos=0.3, titledirection=None) g = graph.graphxy(width=8, x2=None, y2=None, x=graph.axis.linear(min=0, max=100, title='Universe of Discourse'), y=graph.axis.linear(min=0.0, max=1.0, title='Membership Grade')) g.plot(x, y) # ------------------------------------------------------------------------------ def singletonCurve(cen, width): center = cen fwhm = width x = nx.arange(0, 100, 0.1) S = gauss1d(x, fwhm, center) p = graph.axis.painter.regular(titlepos=0.3, titledirection=None) g = graph.graphxy(width=8, x2=None, y2=None, x=graph.axis.linear(min=0, max=100, title='Universe of Discourse'), y=graph.axis.linear(min=0.0, max=1.0, title='Membership Grade')) g.plot(x, y) # ------------------------------------------------------------------------------ def betaCurve(cen, inflPt, width): pass # ------------------------------------------------------------------------------ def dataCurve(ptList): pass # ------------------------------------------------------------------------------ def rectangleCurve(ll, hl, hr, lr): pass # ------------------------------------------------------------------------------ def linearIncrCurve(ll, hr): lowLeft = ll highRight = hr x, y = zip(*[(lowLeft, 0.0), (highRight, 1.0)]) p = graph.axis.painter.regular(titlepos=0.3, titledirection=None) g = graph.graphxy(width=8, x2=None, y2=None, x=graph.axis.linear(min=0, max=100, title='Universe of Discourse'), y=graph.axis.linear(min=0.0, max=1.0, title='Membership Grade')) g.plot(x, y) # ------------------------------------------------------------------------------ def linearDecrCurve(hl, lr): highLeft = hl lowRight = lr x, y = zip(*[(highLeft, 1.0), (lowRight, 0.0)]) p = graph.axis.painter.regular(titlepos=0.3, titledirection=None) g = graph.graphxy(width=8, x2=None, y2=None, x=graph.axis.linear(min=0, max=100, title='Universe of Discourse'), y=graph.axis.linear(min=0.0, max=1.0, title='Membership Grade')) g.plot(x, y) # ------------------------------------------------------------------------------ def outcomeCurve(): pass # EOF functions