-
Notifications
You must be signed in to change notification settings - Fork 0
/
experiment.py
139 lines (116 loc) · 4.46 KB
/
experiment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
from engine import *
import sys
import csv
def userPrompt():
print("Welcome to CFA Experiment Simulation")
print("Enter \'exit\' to quit.\n")
userIn = "Enter number for which experiment to conduct:"
userIn += "\n1) Delayed Conditioning 6) Simultaneous Conditioning"
userIn += "\n2) Second Order Conditioning 7) Compound Conditioning"
userIn += "\n3) Latent Inhibition 8) Sensory Preconditioning"
userIn += "\n4) Extinction 9) Blocking"
userIn += "\n5) Partial Reinforcement 10) Extinction in Second Order Conditioning"
userIn += "\n\nExperiment #"
try:
experiment = int(input(userIn))
fileName = input("\nPlease enter a file name:\n")
if experiment == 1:
print("\nStarting Delayed Conditioning . . .")
delayedConditioning()
elif experiment == 2:
print("\nStarting Second Order Conditioning . . .")
secondOrderConditioning()
elif experiment == 3:
print("\nStarting Latent Inhibition . . .")
latentInhibition()
elif experiment == 4:
print("\nStarting Extinction . . .")
extinction()
elif experiment == 5:
print("\nStarting Partial Reinforcement . . .")
partialReinforcement()
elif experiment == 6:
print("\nStarting Simultaneous Conditioning . . .")
simultaneousConditioning()
elif experiment == 7:
print("\nStarting Compound Conditioning . . .")
compoundConditioning()
elif experiment == 8:
print("\nStarting Sensory Preconditioning . . .")
sensoryPreconditioning()
elif experiment == 9:
print("\nStarting Blocking . . .")
blocking()
elif experiment == 10:
print("\nStarting Extinction in Second Order Conditioning . . .")
extinctionSecondOrder()
elif experiment == 11:
print("\nStarting Delayed Conditioning Full . . .")
delayedConditioningFull(fileName)
elif experiment == 12:
print("\nStarting Second Order Conditioning Full . . .")
secondOrderConditioningFull(fileName)
elif experiment == 13:
print("\nStarting Latent Inhibition Full . . .")
latentInhibitionFull(fileName)
else:
print("Not a valid experiment")
sys.exit()
except ValueError:
print("Not a valid command")
sys.exit()
def delayedConditioning():
main('delayedConditioning.txt', 'delayedConditioningInput.txt', 'delayedOutput.txt', 1)
def delayedConditioningFull(fileName):
if not os.path.exists("trials1"):
os.makedirs("trials1")
main('delayedConditioning.txt', 'delayedConditioningInput.txt', 'trials1/delayedOutput_' + str(fileName) + '.txt', 1)
def secondOrderConditioning():
main('secondOrderConditioning.txt', 'secondOrderConditioningInput.txt', 'secondOrderOutput.txt', 2)
def secondOrderConditioningFull(fileName):
if not os.path.exists("trials2"):
os.makedirs("trials2")
main('secondOrderConditioning.txt', 'secondOrderConditioningInput.txt', 'trials2/secondOrderOutput_' + str(fileName) + '.txt', 2)
def latentInhibition():
main('latentInhibition.txt', 'latentInhibitionInput.txt', 'latentInhibitionOutput.txt', 3)
def latentInhibitionFull(fileName):
if not os.path.exists("trials3"):
os.makedirs("trials3")
main('latentInhibition.txt', 'latentInhibitionInput.txt', 'trials2/latentInhibitionOutput_' + str(fileName) + '.txt', 3)
def extinction():
pass
def partialReinforcement():
pass
def simultaneousConditioning():
pass
def compoundConditioning():
pass
def sensoryPreconditioning():
pass
def blocking():
pass
def extinctionSecondOrder():
pass
def outputToCSV(extractFile, stateI, stateF, csvFilename):
# Extract information from output file
with open(extractFile, 'r') as myfile:
data = myfile.read().replace('\n', '')
data = data.strip()
finalList = []
strSplit = data.split("------------------------- Trial #")
for line in strSplit:
if line.find("State " + str(stateI) + " -> State " + str(stateF)) != -1:
lastStrLoc = line.find("State " + str(stateI) + " -> State " + str(stateF))
strToFind = line[:int(lastStrLoc)]
tempEnd = strToFind[strToFind.rfind("<")+1:]
outputSymbol = tempEnd[:tempEnd.index(">")]
finalList.append(str(line[0:line.find(" ")] + ":" + str(outputSymbol)))
# View output symbols as list
# print(finalList)
# Info to CSV
with open(csvFilename, 'wb') as myfile:
out = csv.writer(open(csvFilename,"w"), delimiter=',',quoting=csv.QUOTE_ALL)
out.writerow(finalList)
print("[Message] Output converted to CSV as \'" + str(csvFilename) + "\'")
if __name__ == "__main__":
userPrompt()