# Carlos Pedro Gonçalves (2015) # Lectures on Artificial Intelligence for Decision Making # Decision Support Automaton: # - Classes definitions # - For implementation examples (with Portuguese lecture notes) see the two part lecture materials: # Part I: # http://pythonfiddle.com/autmato-de-suporte--tomada-de-deciso # Part II: # http://pythonfiddle.com/parte-ii-autmato-de-suporte--tomada-de-deciso # # For more details and lecture materials (in Portuguese) see: # https://sites.google.com/site/autonomouscomputingsystems/lectures-in-portuguese/decision-support-methods class gamble: def __init__(self,name,consequence,probability): self.name = name self.consequence = consequence self.probability = probability # Métodos (parte visível para o autómato) # (nos diapositivos das aulas foi dispensado este método, é introduzido aqui) def showName(self,NameAlt): NameAlt = NameAlt + [self.name] return NameAlt def showPayoff(self,Pay): Pay = Pay + [self.consequence] return Pay def showProb(self,Prob): Prob = Prob + [self.probability] return Prob class automaton: # Definição dos atributos: # "alternatives": lista de tuplos de payoffs (um tuplo para cada alternativa) # "probabilities": lista de distribuições de probabilidades (uma para cada alternativa) # "expectations": lista de expectativas formadas # "chosen": lista de alternativa(s) escolhida(s) def __init__(self,alternatives,probabilities,expectations,chosen): self.alternatives = alternatives self.probabilities = probabilities self.expectations = expectations self.chosen = chosen # Método de suporte à tomada de decisão (passo): # 1 - Olha para as alternativas (nos diapositivos das aulas foi dispensado este método, é introduzido aqui) # 2 - Forma as expectativas em torno dos payoffs # 3 - Selecciona a(s) alternativa(s) que oferece(m) os payoffs esperados mais elevados # A cada passo corresponde um método (POO) distinto: # # Passo 1: def lookAt(self,Pay,Prob): for i in range(0,len(Pay)): self.alternatives = self.alternatives + [Pay[i]] for j in range(0,len(Prob)): self.probabilities = self.probabilities + [Prob[j]] # Passo 2: def formExpect(self): for i in range(0,len(self.alternatives)): A = self.alternatives[i] Prob = self.probabilities[i] Weigh = [] for j in range(0,len(A)): Weigh = Weigh + [A[j] * Prob[j]] self.expectations = self.expectations + [sum(Weigh)] # Passo 3: def choose(self,NameAlt): for i in range(0,len(NameAlt)): print "Alternative:", NameAlt[i], "| Expected Payoff:", self.expectations[i] M = max(self.expectations) for j in range(0,len(self.expectations)): if self.expectations[j] == M: self.choice = NameAlt[j] self.chosen = self.chosen + [NameAlt[j]] print("\nThe chosen alternatives are:") for k in range(0,len(self.chosen)): print self.chosen[k] print "\nWith associated expected payoff: "+str(M) ############################################################################################################ # Caso Activsion Blizzard VR = gamble('Apostar no core business',(5,4,2.5),(0.65,0.25,0.1)) VRAR1 = gamble('AR como negócio secundário',(4,5,3),(0.65,0.25,0.1)) VRAR2 = gamble('VR e AR como linhas de negócio centrais',(3,4,3.5),(0.65,0.25,0.1)) Alternativas = [VR, VRAR1, VRAR2] Pay = [] Prob = [] NameAlt = [] for i in range(0,len(Alternativas)): NameAlt = Alternativas[i].showName(NameAlt) Pay = Alternativas[i].showPayoff(Pay) Prob = Alternativas[i].showProb(Prob) Empresa = automaton([],[],[],[]) Empresa.lookAt(Pay,Prob) Empresa.formExpect() Empresa.choose(NameAlt)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question