def trainTDENet(self, segs):
trainData = [seg.data for seg in segs]
convs = ((25,7),) # first session
maxIter = 400
nHidden = None
poolSize = 1
poolMethod = 'average'
self.stand = ml.ClassSegStandardizer(trainData)
trainDataStd = self.stand.apply(trainData)
dialog = wx.ProgressDialog('Training Classifier',
'Featurizing', maximum=maxIter+2,
style=wx.PD_ELAPSED_TIME | wx.PD_SMOOTH)
def progressCB(optable, iteration, *args, **kwargs):
dialog.Update(iteration, 'Iteration: %d/%d' % (iteration, maxIter))
self.classifier = ml.CNA(trainDataStd, convs=convs, nHidden=nHidden, maxIter=maxIter,
optimFunc=ml.optim.scg, accuracy=0.0, precision=0.0,
poolSize=poolSize, poolMethod=poolMethod,
verbose=False, callback=progressCB)
trainCA = self.classifier.ca(trainDataStd)
trainConfusion = np.round(100*self.classifier.confusion(trainDataStd))
dialog.Destroy()
resultText = (('Final Training CA: %f\n' % trainCA) +
('Confusion Matrix:\n' + str(trainConfusion) + '\n') +
('Choices: ' + str(self.choices)))
wx.MessageBox(message=resultText,
caption='Training Completed!',
style=wx.OK | wx.ICON_INFORMATION)
self.saveResultText(resultText)
python类MessageBox()的实例源码
def trainConvNet(self, segs):
trainData = [seg.data for seg in segs]
#convs = ((16,9), (8,9))
#maxIter = 400 # 49
convs = ((8,3), (8,3), (8,3))
maxIter = 1000
nHidden = None
poolSize = 1
poolMethod = 'average'
self.stand = ml.ClassSegStandardizer(trainData)
trainDataStd = self.stand.apply(trainData)
dialog = wx.ProgressDialog('Training Classifier',
'Featurizing', maximum=maxIter+2,
style=wx.PD_ELAPSED_TIME | wx.PD_SMOOTH)
def progressCB(optable, iteration, *args, **kwargs):
dialog.Update(iteration, 'Iteration: %d/%d' % (iteration, maxIter))
self.classifier = ml.CNA(trainDataStd, convs=convs, nHidden=nHidden, maxIter=maxIter,
optimFunc=ml.optim.scg, accuracy=0.0, precision=0.0,
poolSize=poolSize, poolMethod=poolMethod,
verbose=False, callback=progressCB)
trainCA = self.classifier.ca(trainDataStd)
trainConfusion = np.round(100*self.classifier.confusion(trainDataStd))
dialog.Destroy()
resultText = (('Final Training CA: %f\n' % trainCA) +
('Confusion Matrix:\n' + str(trainConfusion) + '\n') +
('Choices: ' + str(self.choices)))
wx.MessageBox(message=resultText,
caption='Training Completed!',
style=wx.OK | wx.ICON_INFORMATION)
self.saveResultText(resultText)
def trainKNN(self, classData, dialog, metric):
ks = np.arange(1,10)
trainAUC = np.zeros(ks.shape)
validAUC = np.zeros(ks.shape)
partitionGenerator = ml.part.classRandomSubSample(classData,
self.trainFrac, self.nFold)
for fold, trainData, validData in partitionGenerator:
dialog.Update(fold, 'Validation Fold: %d' % fold)
for i, k in enumerate(ks):
classifier = ml.KNN(trainData, k=k, distMetric=metric)
trainAUC[i] += classifier.auc(trainData)
validAUC[i] += classifier.auc(validData)
dialog.Update(self.nFold, 'Training Final Classifier')
trainAUC /= self.nFold
validAUC /= self.nFold
print 'train AUC: ', trainAUC
print 'valid AUC: ', validAUC
bestK = ks[np.argmax(validAUC)]
print 'best K: ', bestK
self.classifier = ml.KNN(classData, k=bestK, distMetric=metric)
finalAUC = self.classifier.auc(classData)
dialog.Destroy()
wx.MessageBox(message=('Best K: %d\n' % bestK) + \
('Mean Validation AUC: %f\n' % np.max(validAUC)) +
('Final Training AUC: %f' % finalAUC),
caption='Training Completed!', style=wx.OK | wx.ICON_INFORMATION)
def trainKNN(self, classData, dialog, metric):
ks = np.arange(1,10)
trainAUC = np.zeros(ks.shape)
validAUC = np.zeros(ks.shape)
partitionGenerator = ml.part.classRandomSubSample(classData,
self.trainFrac, self.nFold)
for fold, trainData, validData in partitionGenerator:
dialog.Update(fold, 'Validation Fold: %d' % fold)
for i, k in enumerate(ks):
classifier = ml.KNN(trainData, k=k, distMetric=metric)
trainAUC[i] += classifier.auc(trainData)
validAUC[i] += classifier.auc(validData)
dialog.Update(self.nFold, 'Training Final Classifier')
trainAUC /= self.nFold
validAUC /= self.nFold
print 'train AUC: ', trainAUC
print 'valid AUC: ', validAUC
bestK = ks[np.argmax(validAUC)]
print 'best K: ', bestK
self.classifier = ml.KNN(classData, k=bestK, distMetric=metric)
finalAUC = self.classifier.auc(classData)
dialog.Destroy()
wx.MessageBox(message=('Best K: %d\n' % bestK) + \
('Mean Validation AUC: %f\n' % np.max(validAUC)) +
('Final Training AUC: %f' % finalAUC),
caption='Training Completed!', style=wx.OK | wx.ICON_INFORMATION)
def afterTest(self, earlyStop):
if not earlyStop:
self.saveCap()
ca = np.mean(np.diag(self.confusion))/self.nTestTrial
wx.MessageBox(('Test CA: %f\n' % ca) +
'Confusion Matrix:\n' + str(self.confusion/self.nTestTrial),
'Testing Complete', wx.OK | wx.ICON_INFORMATION)
def OnDropFiles(self, x, y, filenames):
wx.MessageBox(
u"Items Added:\n{}".format("\n".join(filenames)), #message
u'Evidence Dropped', #title
wx.OK | wx.ICON_INFORMATION
)
for filename in filenames:
self.window.EnumerateSource(
filename
)
pass
def onProcessAction(self, event):
"""Executes the requested action"""
if self.rbx_action.GetSelection() == 0:
count = SetTeardrops(self.sp_hpercent.GetValue(),
self.sp_vpercent.GetValue(),
self.sp_nbseg.GetValue(),
self.board)
wx.MessageBox("{0} Teardrops inserted".format(count))
else:
count = RmTeardrops(pcb=self.board)
wx.MessageBox("{0} Teardrops removed".format(count))
self.Destroy()
def ok_click(self, e):
# check for changes to cron
if self.cron_lamp_on.GetLabel() == "not found" or self.cron_lamp_off.GetLabel() == "not found":
mbox = wx.MessageDialog(None, "Add new job to cron?", "Are you sure?", wx.YES_NO|wx.ICON_QUESTION)
sure = mbox.ShowModal()
if sure == wx.ID_YES:
if self.cron_lamp_on.GetLabel() == "not found":
cron_task = "/home/pi/Pigrow/scripts/switches/" + "lamp_on.py"
MainApp.cron_info_pannel.add_to_onetime_list("new", "True", self.new_on_string_text.GetLabel(), cron_task)
if self.cron_lamp_off.GetLabel() == "not found":
cron_task = "/home/pi/Pigrow/scripts/switches/" + "lamp_off.py"
MainApp.cron_info_pannel.add_to_onetime_list("new", "True", self.new_off_string_text.GetLabel(), cron_task)
MainApp.cron_info_pannel.update_cron_click("e")
elif not self.new_on_string_text.GetLabel() == self.cron_lamp_on.GetLabel() or not self.new_off_string_text.GetLabel() == self.cron_lamp_off.GetLabel():
print(":" + self.new_on_string_text.GetLabel() + ":")
print(":" + self.cron_lamp_on.GetLabel() + ":")
mbox = wx.MessageDialog(None, "Update cron timing?", "Are you sure?", wx.YES_NO|wx.ICON_QUESTION)
sure = mbox.ShowModal()
result_on = 'done' # these are for cases when only one is changed
result_off = 'done' # if it attempts to update cron and fails it'll change to an error message
if sure == wx.ID_YES:
if not self.new_on_string_text.GetLabel() == self.cron_lamp_on.GetLabel():
result_on = self.change_cron_trigger("lamp_on.py", self.new_on_string_text.GetLabel())
if not self.new_off_string_text.GetLabel() == self.cron_lamp_off.GetLabel():
result_off = self.change_cron_trigger("lamp_off.py", self.new_off_string_text.GetLabel())
if result_on != "done" or result_off != "done":
wx.MessageBox('Cron update error, edit lamp switches in the cron pannel', 'Info', wx.OK | wx.ICON_INFORMATION)
else:
MainApp.cron_info_pannel.update_cron_click("e")
# check for changes to settings file
time_lamp_on = str(self.on_hour_spin.GetValue()) + ":" + str(self.on_min_spin.GetValue())
time_lamp_off = str(self.off_hour_spin.GetValue()) + ":" + str(self.off_min_spin.GetValue())
if not MainApp.config_ctrl_pannel.config_dict["time_lamp_on"] == time_lamp_on or not MainApp.config_ctrl_pannel.config_dict["time_lamp_off"] == time_lamp_off:
MainApp.config_ctrl_pannel.config_dict["time_lamp_on"] = time_lamp_on
MainApp.config_ctrl_pannel.config_dict["time_lamp_off"] = time_lamp_off
MainApp.config_ctrl_pannel.update_setting_click("e")
MainApp.config_ctrl_pannel.update_config_click("e")
self.Destroy()
def set_new_gpio_link(self, e):
#get data from combo boxes.
unused_gpio = self.list_unused_gpio(self.list_used_gpio())
config_ctrl_pnl.device_new = self.devices_combo.GetValue()
config_ctrl_pnl.gpio_new = self.gpio_tc.GetValue()
config_ctrl_pnl.wiring_new = self.wiring_combo.GetValue()
#check to see if info is valid and closes if it is
should_close = True
# check if device is set
if config_ctrl_pnl.device_new == "":
wx.MessageBox('Select a device to link from the list', 'Error', wx.OK | wx.ICON_INFORMATION)
should_close = False
#check if gpio number is valid
if not config_ctrl_pnl.gpio_new == config_ctrl_pnl.gpio_toedit or config_ctrl_pnl.gpio_toedit == "":
if not config_ctrl_pnl.gpio_new in unused_gpio and should_close == True:
wx.MessageBox('Select a valid and unused gpio pin', 'Error', wx.OK | wx.ICON_INFORMATION)
config_ctrl_pnl.gpio_new = self.gpio_tc.SetValue("")
should_close = False
# check if wiring direction is set to a valid setting
if not config_ctrl_pnl.wiring_new == "low" and should_close == True:
if not config_ctrl_pnl.wiring_new == "high":
wx.MessageBox("No wiring direction set, \nIf you don't know guess and change it if the device turns on when it should be off", 'Error', wx.OK | wx.ICON_INFORMATION)
should_close = False
# if box should be closed then close it
if should_close == True:
#checks to see if changes have been made and updates ui if so
if not config_ctrl_pnl.device_new == config_ctrl_pnl.device_toedit:
config_ctrl_pnl.currently_new = 'unlinked'
else:
if not config_ctrl_pnl.gpio_new == config_ctrl_pnl.gpio_toedit:
config_ctrl_pnl.currently_new = 'unlinked'
else:
if not config_ctrl_pnl.wiring_new == config_ctrl_pnl.wiring_toedit:
config_ctrl_pnl.currently_new = 'unlinked'
else:
config_ctrl_pnl.currently_new = config_ctrl_pnl.currently_toedit
self.Destroy()
def show_help(self, e):
script_path = self.cron_path_combo.GetValue()
script_name = self.cron_script_cb.GetValue()
helpfile = self.get_help_text(str(script_path + script_name))
msg_text = script_name + ' \n \n'
msg_text += str(helpfile)
wx.MessageBox(msg_text, 'Info', wx.OK | wx.ICON_INFORMATION)
def OnDisconnect(self, event):
msgbox = wx.MessageDialog(None, "",u'???????',wx.YES_NO | wx.ICON_QUESTION)
ret = msgbox.ShowModal()
if (ret == wx.ID_YES):
self.StopThreads()
wx.MessageBox( u"??????",u'\n??????????')
sys.exit()
def OnAbout(self, event):
wx.MessageBox(u"????????\n??????????hack?????????",u"??", wx.OK | wx.ICON_INFORMATION, self)
def OnEditorShown(self, evt):
if evt.GetRow() == 6 and evt.GetCol() == 3 and \
wx.MessageBox("Are you sure you wish to edit this cell?",
"Checking", wx.YES_NO) == wx.NO:
evt.Veto()
return
print "OnEditorShown: (%d,%d) %s\n" % (evt.GetRow(), evt.GetCol(), evt.GetPosition())
evt.Skip()
def OnEditorHidden(self, evt):
if evt.GetRow() == 6 and evt.GetCol() == 3 and \
wx.MessageBox("Are you sure you wish to finish editing this cell?",
"Checking", wx.YES_NO) == wx.NO:
evt.Veto()
return
print "OnEditorHidden: (%d,%d) %s\n" % (evt.GetRow(), evt.GetCol(), evt.GetPosition())
evt.Skip()
def doMove(self,move,score):
if move:
self.putTile()
self.drawChange(score)
if self.isGameOver():
if wx.MessageBox(u"????????????",u"??",
wx.YES_NO|wx.ICON_INFORMATION)==wx.YES:
bstScore = self.bstScore
self.initGame()
self.bstScore = bstScore
self.drawAll()
def update_status(self):
bytes_left = self._level.get_entity_bytes_left()
if bytes_left < 0:
self.Status.SetStatusText('No entity bytes left!', 0)
wx.MessageBox('There is no more room for entities. Delete entities or move entites to create empty blockmap blocks to free up more room. This level cannot be saved until enough room is made available.', 'No more room for entities', wx.ICON_EXCLAMATION | wx.OK)
else:
self.Status.SetStatusText('{} entity bytes left'.format(bytes_left), 0)
def save(self):
stream = StreamWrite.from_file(self._filename, Endianness.BIG)
levels_not_saved = 0
for level_index, level in enumerate(self._levels):
if level.modified:
if not level.can_save():
levels_not_saved += 1
continue
# Write entities first.
level.write_entities(stream)
# Save level data.
if level_index == 0:
level.save(stream)
else:
filename = 'L{}-{}'.format(self._world_index + 1, level_index + 1)
game_dir = os.path.dirname(self._filename)
filename = os.path.join(game_dir, filename)
level_stream = StreamWrite.from_file(filename, Endianness.BIG)
if self._world_index == 2 and level_index == 1:
offset = 19620
else:
offset = 0
level.save(level_stream, offset)
level_stream.write_to_file(filename)
# Save level header.
stream.seek(self._level_offsets[level_index])
level.save_header(stream)
level.modified = False
stream.write_to_file(self._filename)
if levels_not_saved:
wx.MessageBox('{} level(s) could not be saved.'.format(levels_not_saved), 'Levels not saved', wx.ICON_INFORMATION | wx.OK)
def OnPLCOpenEditorMenu(self, event):
wx.MessageBox(_("No documentation available.\nComing soon."))
def OnLinkClick(self, event):
url = event.linkinfo[0]
try:
if wx.Platform == '__WXMSW__':
import webbrowser
webbrowser.open(url)
elif subprocess.call("firefox %s" % url, shell=True) != 0:
wx.MessageBox("""Firefox browser not found.\nPlease point your browser at :\n%s""" % url)
except ImportError:
wx.MessageBox('Please point your browser at: %s' % url)