本文整理汇总了Python中experiment.Experiment类的典型用法代码示例。如果您正苦于以下问题:Python Experiment类的具体用法?Python Experiment怎么用?Python Experiment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Experiment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
def test(self):
""" Test that every image is correctly recognized. """
Experiment.test(self)
start = time.time()
num_confused = 0.0
classifier = self.network.get_classifier()
i = 0
while self.image_iterator.has_next():
image, category, img_idx = self.image_iterator.next()
recognized = self.network.do_inference(numpy.array(image), category)
if not recognized:
active_cats = classifier.get_winning_category()
#print colored("Failed: " + category + " recognized as "+active_cats, 'red')
num_confused += 1
i += 1
if i % self.PRINT_INCR == 0: print "Iter:", i
confusion_rate = num_confused / float(i)
elapsed = (time.time() - start)
print "Testing time:", elapsed
print "Time per category:", (elapsed / i)
print colored("Testing complete", "green")
print colored("\nConfusion rate: " + str(confusion_rate), 'cyan')
示例2: run_experiment
def run_experiment(args):
""" Parallelizable method for computing experiments.
This method is used in parallel computation for running experiments in
parallel. Due to the nature of pickling, it must be declared globally,
because instance methods cannot be pickled.
"""
# args is a tuple, so that we can map over an array of tuples.
# see run_parallel_experiments()
params, param_name, val = args
params = params.copy()
params[param_name] = val
while True:
try:
start_time = time.clock()
exp = Experiment(**params)
exp.compute_informativeness()
break
except Exception:
traceback.print_exc()
elapsed_time = time.clock() - start_time
print "Experiment with val %s added in %0.2f seconds" % \
(str(val), elapsed_time)
return val, exp
示例3: train
def train(self):
""" Store a copy of every image in the iterator. """
Experiment.train(self)
start = time.time()
gabor = GaborRegion((144, 192), rotations=3,
initial_wavelength=3,
num_wavelengths=2)
# Regions = [ GaborRegion, AndRegion, OrRegion (classifier) ]
self.network = AndOrNetwork((144,192), num_regions=1,
input_region = gabor)
and_region = self.network.regions[1]
classifier = self.network.get_classifier()
i = 0
while self.image_iterator.has_next():
image, category, img_idx = self.image_iterator.next()
gabor.do_inference(numpy.array(image))
active_nodes = gabor.get_active_nodes()
pos = and_region.create_node((0,0), cxns = active_nodes)
classifier.create_node(category, pos)
i += 1
if i % self.PRINT_INCR == 0: print "Iter:", i
and_region.prepare_for_inference()
classifier.prepare_for_inference()
num_cxns = and_region.get_num_cxns() + classifier.get_num_cxns()
print "Number of connections:", num_cxns
elapsed = (time.time() - start)
print "Training time:", elapsed
print "Time per category:", (elapsed / i)
print colored("Training complete", "green")
示例4: __init__
def __init__(self):
Experiment.__init__(self)
persistance.Dommable.__init__(self)
self.amplifiers = {'None':'bridge', 'Prana':'Prana', 'Milmega 1':'Milmega', 'Milmega 2':'Milmega'}
self.amplifier = EnumerateProperty('None',['Automatic'] + self.amplifiers.keys())
self.amplifier.changedTo.connect(self.setAmplifier)
示例5: individualStrategies
def individualStrategies():
#allxVals = {1: range(4, 10, 5), 2: range(100, 111, 10)}
allxVals = {1: range(4, 101, 5), 2: range(100, 1001, 10)}
allPlayerTypes = {'Random Play': players.RandomPlayer,
'Honest Play': players.HonestPlayer,
'Minimum Guessing': players.MinimumGuessingPlayer,
'Constant Guessing': players.ConstantGuessPlayer,
'Mean Guessing': players.MeanGuessPlayer,
'Quantile Guessing': players.QuantileGuessPlayer,
}
allExperimentTypes = [2]
allStatistics = [2]
for statistic in allStatistics:
for experimentType in allExperimentTypes:
xVals = allxVals[experimentType]
for title, playerType in allPlayerTypes.items():
playerTypes = {playerType: 1.0}
savefile = title.replace(' ', '_')+str(experimentType)+str(statistic)+'.png'
print "Running "+savefile
exp = Experiment(xVals, playerTypes, experimentType, statistic)
yVals = exp.run()
print yVals
plotResults(exp, yVals, title, savefile)
print
示例6: testQValueNetwork
def testQValueNetwork(startTurn=0, loopNum=1000, type=''):
agents = []
win_nums = {}
test_name = PLAYER_LIST[type][0]
test_filename = TEST[type]
if os.path.isfile(test_filename):
with open(test_filename, 'r') as f:
win_nums = pickle.load(f)
for i in range(0, 3):
playerName = PLAYER_LIST[type][i]
nw = NETWORK[type](playerName)
if playerName == test_name:
nw.loadNet(playerName, startTurn)
rfa = AGENT[type](playerName, nw)
agents.append(rfa)
env = RunFastEnvironment()
exp = Experiment(env, agents)
for i in range(loopNum):
if not win_nums.get(startTurn):
win_nums[startTurn] = {}
testHistory = exp.doTest(test_name)
for j in range(0,3):
playerName = PLAYER_LIST[type][j]
if not win_nums[startTurn].get(playerName):
win_nums[startTurn][playerName] = {'point': 0, 'win': 0}
win_nums[startTurn][playerName]['point'] += testHistory[playerName]
if testHistory['name'] == playerName:
win_nums[startTurn][playerName]['win'] += 1
with open(test_filename, 'w') as f:
pickle.dump(win_nums, f)
示例7: altruism
def altruism(self, altruisticProbability, selfishProbability, altruismCost,
altruismBenefit, disease, harshness, numTicks):
"""
Runs an experiment of the Biology/Evolution/Altruism model.
:returns: The table output of the experiment.
"""
job = uuid4()
exp_path = '/tmp/%s/experiment.xml' % job
out_path = '/tmp/%s/out.csv' % job
params = {
'altruistic-probability': altruisticProbability,
'selfish-probability': selfishProbability,
'cost-of-altruism': altruismCost,
'benefit-from-altruism': altruismBenefit,
'disease': disease,
'harshness': harshness,
}
exp = Experiment(steps=numTicks, params=params)
exp.add_metric(color='pink').add_metric(color='green')
exp.write_xml(exp_path)
model = '%s/models/Sample Models/Biology/Evolution/Altruism.nlogo' % NETLOGO_HOME
self.call_experiment(model, exp_path, exp.name, out_path)
with open(out_path, 'r') as out_file:
return out_file.read()
示例8: train
def train(self):
""" Store a copy of every image in the iterator. """
Experiment.train(self)
start = time.time()
self.image_shape = (144, 192)
gabor = GaborRegion(self.image_shape, rotations=3,
initial_wavelength=3,
num_wavelengths=2)
# Regions = [ GaborRegion, AndRegion, OrRegion (classifier) ]
self.network = AndOrNetwork((144,192), num_regions=2,
input_region = gabor)
f1 = self.network.regions[1]
f2 = self.network.regions[2]
classifier = self.network.get_classifier()
self.gabor_acts = gabor.precompute_image_activations(self.image_iter)
windows = self.get_windows()
for window in windows:
self.network.prepare_for_inference(1)
elapsed = (time.time() - start)
total_cxns = 0
for i, r in enumerate(self.network.regions[1:]):
num_cxns = r.get_num_cxns()
print "Region %s cxns: %s" % (i, num_cxns)
total_cxns += num_cxns
print "Total connections:", total_cxns
print "Training time:", elapsed
print "Time per category:", (elapsed / i)
print colored("Training complete", "green")
def test(self):
""" Test that every image is correctly recognized. """
Experiment.test(self)
start = time.time()
classifier = self.network.get_classifier()
i = 0
while self.image_iterator.has_next():
image, category = self.image_iterator.next()
recognized = self.network.do_inference(numpy.array(image), category)
if not recognized:
active_cats = classifier.get_active_categories()
print colored("Failed: " + category + " recognized as "+repr(active_cats), 'red')
i += 1
if i % self.PRINT_INCR == 0: print "Iter:", i
elapsed = (time.time() - start)
print "Testing time:", elapsed
print "Time per category:", (elapsed / i)
print colored("Testing complete", "green")
示例9: __init__
def __init__(self, output_path=None, linewidth=1.5):
e = Experiment(output_path)
self.linewidth = linewidth
if output_path is None:
self.output_path = os.path.join(e.final_output_path, self.default_plots_path_addon)
else:
self.output_path = output_path
e.makedir(self.output_path)
示例10: __init__
def __init__(self):
Experiment.__init__(self)
self.passCriterion = ExperimentSlot(parent=self,defaultValue='VoltageCriterion')
self.transmittedPower = ExperimentSlot(parent=self,defaultValue='TransmittedPower')
self.powerMinimum = Property(Power(-30.,'dBm'),changedSignal=self.settingsChanged)
self.powerMaximum = Property(Power(+15.,'dBm'),changedSignal=self.settingsChanged)
self.frequencies = SweepRange(Frequency(150e3),Frequency(1500e6),21,changedSignal=self.settingsChanged)
示例11: load_code_from_file
def load_code_from_file(self, filename):
experiment = Experiment()
experiment.load_code_from_file(filename)
self.project.experiments.append(experiment)
self.project.active_experiment = experiment
self.update_functions_UI(self.project.active_experiment.exec_model.statements)
self.update_functions_context(self.project.active_experiment,
self.project.active_experiment.exec_model.statements)
示例12: main
def main():
try:
folder_name = sys.argv[1]
experiment = Experiment(folder_name)
except IndexError:
experiment = Experiment()
experiment.retrieve_data()
parser = FeatureParser()
parser.initialize_matrix(experiment.raw_data_set)
parser.print_global_names()
示例13: quantileStrategy
def quantileStrategy():
xVals = [10]
playerTypes = {players.QuantileGuessPlayer: 1.0}
experimentType = 2
statistic = 1
title = "Quantile Guessing"
exp = Experiment(xVals, playerTypes, experimentType, statistic)
yVals = exp.run()
print yVals
示例14: main
def main():
data = Experiment()
data.retrieve_data()
emails = []
for example in data.raw_data_set:
emails.append(Email(example[1]))
i = 1
with open("dates.csv", "w") as dates_file:
for email in emails:
dates_file.write(str(i) + ","+str(email.get_hour()) + "\n")
示例15: runExperiment
def runExperiment(self):
try:
e = Experiment(int(self.sampleEntry.get()), int(self.populationEntry.get()),
int(self.numSuccessesEntry.get()))
e.perform(int(self.numTrialsEntry.get()))
self.drawResult(e.results, 0)
except AssertionError as error:
tkMessageBox.showerror('Data Entry Error', error.args[0])
except ValueError as error:
tkMessageBox.showerror('Data Entry Error', 'Please make sure each field is filled out'
+ ' and only contains numbers')