示例#1
0
 def __init__(self, graph, predictorList, penList = [], rounds = 500,
         eventFunction = lambda : Induction.getRandomEvent(2.0/3.0)):
     self.graph = graph
     self.rounds = rounds
     self.predictorList = copy.deepcopy(predictorList)
     self.world = Induction.World(eventFunction)
     for predictor in self.predictorList:
         self.world.register(predictor)
     penBox = copy.copy(penList)
     for predictor in self.predictorList:
         pen = penBox[0]; del penBox[0]
         pen.lineWidth = Gfx.MEDIUM
         self.graph.addPen(str(predictor), pen, updateCaption = False)
     if SHOW_MI_MEAN:
         pen = Gfx.Pen((0.0, 0.0, 0.0), lineWidth=Gfx.THICK,
                       linePattern=Gfx.CONTINUOUS)
         self.graph.addPen("miMean", pen, updateCaption = False)
     if SHOW_NON_MI_MEAN:
         pen = Gfx.Pen((0.3, 0.0, 0.6), lineWidth=Gfx.THICK,
                       linePattern=Gfx.CONTINUOUS)
         self.graph.addPen("non_miMean", pen, updateCaption = False)
     self.graph.redrawCaption()
     self.interrupt = False
     self.isRunning = False
     self.last_xPixel = -1
bluePens = [Gfx.Pen(c) for c in filter(bright,filter(Colors.BlueFilter, Colors.colors))]
greenPens = [Gfx.Pen(c) for c in filter(bright,filter(Colors.GreenFilter, Colors.colors))]
yellowPens = [Gfx.Pen(c) for c in filter(bright,filter(Colors.YellowFilter, Colors.colors))]
emptyPens = [Graph.DONT_DRAW_PEN]*10

exampleList = {}

exampleList["01(MI): MI + Forecasters"]  =  \
    ("Example 01(MI): MI + Forecasters",
     [Induction.DelayedForecaster(0.7, 40, "Forecaster 1 (success; delay)"),
      Induction.ForecasterFromBottom(0.90, "Forecaster 2 (success; recovers from zero)"),
      Induction.MetaInductivist("Meta-Inductivist"),
      Induction.ObjectInductivist("Object-Inductivist")],
     bluePens[:2] + redPens[:1] + greenPens,
     500,
     lambda : Induction.getRandomEvent(2.0/3.0))

exampleList["02(MI): MI + Amplitude-Oscillator + OI"] = \
    ("Example 02(MI): MI + Amplitude-Oscillator + OI",
     [Induction.AmplitudeOscillator(0.3, 0.85, "AmpOsc"),
      Induction.MetaInductivist("Meta-Inductivist"),
      Induction.ObjectInductivist("Object-Inductivist")],
     bluePens[:1] + redPens[:1] + greenPens,
     500,
     lambda : Induction.getRandomEvent(2.0/3.0))

exampleList["03(MI): MI + 1 Systematic Oscillator + OI"] = \
    ("Example 03(MI): MI + 1 Systematic Oscillator + OI",
     [Induction.SystOscillator("SystOscillator"),
     Induction.MetaInductivist("Meta-Inductivist"),
      Induction.ObjectInductivist("Object-Inductivist")],
    def Sim(self, title, predictorList, penList = [], rounds = 500,
            eventFunction = lambda : Induction.getRandomEvent(2.0/3.0)):
# die Axen wird entsprechend den Menüvorgaben angepasst
        self.graph.reset(1, 0.0, rounds, 1.0)
        if self.win.absoluteSuccess:
            self.graph.setLabels(yaxis="Absolute Success")
        else:
            self.graph.setLabels(yaxis="Success Rate")
        self.graph.setTitle(title)
        self.zoomlist = [(1, 0.0, rounds, 1.0)]
        self.zoomPos = 0
        self.predictorList = copy.deepcopy(predictorList)
#nun wird die Klasse World aus Induction.py initialisiert bzw. erzeugt; siehe Step 6
        self.world = Induction.World(eventFunction)
#nun wird jeder predictor der predictorList aus dem Example bei der Klasse world
        #angemeldet, das führt zu Step 6 in Induction.py
        for predictor in self.predictorList:
            self.world.register(predictor)
        if self.worldDeception:
            self.world.worldDeceived = self.world.miList[0]
# Hier oben bei [0] moegliche Veraenderung des Betrogenen MI eintragen
#"0" ist die erste Stelle der miList; der wird betrogen, falls
# worldDeception an ist

#Step7:  nun werden den predictors die entprechenden zeichenfarben zugeordnet
        penBox = ProxyPenGenerator(penList)
        for predictor in self.predictorList:
            pen = penBox.next()
            pen.lineWidth = Gfx.MEDIUM
            if self.win.blackwhite:  p = greyscale(pen)
            else: p = pen
            # print pen.lineWidth
            self.graph.addPen(str(predictor), p)
        pen = penBox.next()
        pen.lineWidth = Gfx.MEDIUM
        #if self.win.blackwhite:  greyscale(pen)        
        #if self.win.hiddenOI:
        #    self.graph.addPen(str(self.world.OI), pen)

        Np = len(self.world.getPredictorList())
        Nmi = len(self.world.miList)
        Nn_mi = len(self.world.non_miList)
        
#Step7-Fortsetzung: Hier wird die Legende der Logging-Ausgabe erzeugt,
#falls Logging an ist. Danach folgt Mittelwertfarbeneinstellung.
        self.win.clearLog()
        self.fmtStr = "%5i:| " + \
                      "%1.2f "*(Np) + \
                      "|" + " %4s"*Nmi + \
                      " ||" + "%4s|"*Nn_mi + "\n" 
        s0 = "Round | "
        s0+= ("Success Rates"+" "*100)[:5*Np] + "|"
        s0+= (" Favorites"+" "*100)[:5*Nmi] + " ||"
        s0+= ("Deceivers"+" "*100)[:5*Nn_mi]
        self.win.logAppend(s0+"\n")
        s = "      | "
        for p in self.world.getPredictorList():
            s += "%4s " % self.shortName(p)
        s += "|"        
        for mi in self.world.miList:
            s += " %4s" % self.shortName(mi)
        s += " ||"
        for p in self.world.non_miList:
            s += "%4s|"  % self.shortName(p)
        self.win.logAppend(s+"\n")
        self.win.logAppend("-"*len(s)+"\n")

# Zur Mittelwertberechnung
# p1 ist der Farbenwert von non_miMean; und p2 der von miMean
        if self.win.showMeanValues:
            p1 = Gfx.Pen((0.3, 0.0, 0.6), lineWidth=Gfx.THICK,
                         linePattern=Gfx.CONTINUOUS)
            p2 = Gfx.Pen((0.0, 0.0, 0.0), lineWidth=Gfx.THICK,
                         linePattern=Gfx.CONTINUOUS)
            if self.win.blackwhite:
                p1 = greyscaleMean(p1); p1.lineWidth = Gfx.THICK
                p2 = greyscaleMean(p2); p2.lineWidth = Gfx.THICK
# Non-MI-Mean-Out: folgende Zeile auskommentieren, um non-MI-mean anzuzeigen                
            p1 = Graph.DONT_DRAW_PEN
            self.graph.addPen("non_miMean", p1)           
            self.graph.addPen("miMean", p2)
# Mittelwerberechnung Ende

#Option 6: PrintEventfrequency
# p = Gfx.Pen((0.8, 0.5, 0.0), lineWidth=Gfx.MEDIUM,  \
# linePattern=Gfx.CONTINUOUS)
# self.graph.addPen("Event Frequency", p)   

#Step8: Jetzt erst beginnt die HAUPTschleife
        self.calcNdraw(1, rounds)
示例#4
0
    def Sim(self, title, predictorList, penList = [], rounds = 500,
            eventFunction = lambda : Induction.getRandomEvent(2.0/3.0)):
        self.graph.reset(1, 0.0, rounds, 1.0)
        if self.win.absoluteSuccess:
            self.graph.setLabels(yaxis="Absolute Success")
        else:
            self.graph.setLabels(yaxis="Success Rate")
        self.graph.setTitle(title)
        self.zoomlist = [(1, 0.0, rounds, 1.0)]
        self.zoomPos = 0
        self.predictorList = copy.deepcopy(predictorList)
        self.world = Induction.World(eventFunction)
        for predictor in self.predictorList:
            self.world.register(predictor)
        if self.worldDeception:
            # Hier bei [0] moegliche Veraenderung des Betrogenen MI eintragen
            self.world.worldDeceived = self.world.miList[0]
        penBox = ProxyPenGenerator(penList)
        for predictor in self.predictorList:
            pen = penBox.next()
            pen.lineWidth = Gfx.MEDIUM
            if self.win.blackwhite:  p = greyscale(pen)
            else: p = pen
            # print pen.lineWidth
            self.graph.addPen(str(predictor), p)
        pen = penBox.next()
        pen.lineWidth = Gfx.MEDIUM
        #if self.win.blackwhite:  greyscale(pen)        

        Np = len(self.world.getPredictorList())
        Nmi = len(self.world.miList)
        Nn_mi = len(self.world.non_miList)
        
        self.win.clearLog()
        self.fmtStr = "%5i:| " + \
                      "%1.2f "*(Np) + \
                      "|" + " %4s"*Nmi + \
                      " ||" + "%4s|"*Nn_mi + "\n" 
        s0 = "Round | "
        s0+= ("Success Rates"+" "*100)[:5*Np] + "|"
        s0+= (" Favorites"+" "*100)[:5*Nmi] + " ||"
        s0+= ("Deceivers"+" "*100)[:5*Nn_mi]
        self.win.logAppend(s0+"\n")
        s = "      | "
        for p in self.world.getPredictorList():
            s += "%4s " % self.shortName(p)
        s += "|"        
        for mi in self.world.miList:
            s += " %4s" % self.shortName(mi)
        s += " ||"
        for p in self.world.non_miList:
            s += "%4s|"  % self.shortName(p)
        self.win.logAppend(s+"\n")
        self.win.logAppend("-"*len(s)+"\n")

# Zur Mittelwertberechnung      
        if self.win.showMeanValues:
            p1 = Gfx.Pen((0.3, 0.0, 0.6), lineWidth=Gfx.THICK,
                         linePattern=Gfx.CONTINUOUS)
            p2 = Gfx.Pen((0.0, 0.0, 0.0), lineWidth=Gfx.THICK,
                         linePattern=Gfx.CONTINUOUS)
            if self.win.blackwhite:
                p1 = greyscaleMean(p1); p1.lineWidth = Gfx.THICK
                p2 = greyscaleMean(p2); p2.lineWidth = Gfx.THICK
# Non-MI-Mean-Out: folgende Zeile auskommentieren, um non-MI-mean anzuzeigen                
            p1 = Graph.DONT_DRAW_PEN
            self.graph.addPen("non_miMean", p1)           
            self.graph.addPen("miMean", p2)
# Mittelwerberechnung Ende


#Option 6:
#        p = Gfx.Pen((0.8, 0.5, 0.0), lineWidth=Gfx.MEDIUM,  \
#        linePattern=Gfx.CONTINUOUS)
#        self.graph.addPen("Event Frequency", p)   

        self.calcNdraw(1, rounds)
示例#5
0
###############################################################################
#
# list of examples
#
###############################################################################

exampleList = {}
exampleList["A: MI Demonstration"]  =  \
    ("Example 01(MI): MI + Forecasters",
     [Induction.DelayedForecaster(0.7, 40, "Forecaster 1 (success; delay)"),
      Induction.ForecasterFromBottom(0.90, "Forecaster 2 (success; recovers from zero)"),
      Induction.MetaInductivist("Meta-Inductivist"),
      Induction.ObjectInductivist("Object-Inductivist")],
     bluePens[:2] + redPens[:1] + greenPens,
     500,
     lambda : Induction.getRandomEvent(2.0/3.0),
     """ "MI Demonstration" demonstrates how a meta-inductivist works:
     The meta-inductivist simply follows the predictor that had the highest
     success rate so far. This predictor is called its "favorite". If another
     predictor becomes better than the favorite, the meta-inductivists choses this
     predictor as its new favorite.
     """)
exampleList["B: Amp. Oscillators"] = \
    ("Example 02(MI): MI + Amplitude-Oscillator + OI",
     [Induction.AmplitudeOscillator(0.3, 0.85, "AmpOsc"),
      Induction.MetaInductivist("Meta-Inductivist"),
      Induction.ObjectInductivist("Object-Inductivist")],
     bluePens[:1] + redPens[:1] + greenPens,
     500,
     lambda : Induction.getRandomEvent(2.0/3.0),
     """Hier noch eine Beschreibung einfügen...