本文整理匯總了Python中visualizer.Visualizer.append_cost方法的典型用法代碼示例。如果您正苦於以下問題:Python Visualizer.append_cost方法的具體用法?Python Visualizer.append_cost怎麽用?Python Visualizer.append_cost使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類visualizer.Visualizer
的用法示例。
在下文中一共展示了Visualizer.append_cost方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Worker
# 需要導入模塊: from visualizer import Visualizer [as 別名]
# 或者: from visualizer.Visualizer import append_cost [as 別名]
class Worker(QtCore.QThread):
started = QtCore.Signal()
updated = QtCore.Signal(numpy.ndarray, numpy.ndarray)
stopped = QtCore.Signal()
def __init__(self, parent=None):
super(Worker, self).__init__(parent)
self.bed = None
self.gen = None
self.delay = 1.0
self.stop_flg = False
self.mutex = QtCore.QMutex()
def setup(self, window_size=20, t_in=2, w=10, h=10, d=1, t_out=1, hidden_layers_sizes=[100], pretrain_step=1):
self.bed = TestBed(window_size=window_size, t_in=t_in, w=w, h=h, d=d, t_out=t_out, hidden_layers_sizes=hidden_layers_sizes)
self.gen = SinGenerator(w=w, h=h, d=1)
# self.gen = RadarGenerator('../data/radar', w=w, h=h, left=0, top=80)
self.vis = Visualizer(w=w, h=h, t_out=t_out)
self.pretrain_step = pretrain_step
# fill the window with data
for i in xrange(window_size):
y = self.gen.next()
self.bed.supply(y)
def setGeneratorParams(self, k, n):
pass
def setDelay(self, delay):
self.delay = delay
def setLearningParams(self, params):
self.finetune_epochs = params['finetune_epochs']
self.finetune_lr = params['finetune_lr']
self.finetune_batch_size = params['finetune_batch_size']
self.pretrain_epochs = params['pretrain_epochs']
self.pretrain_lr = params['pretrain_lr']
self.pretrain_batch_size = params['pretrain_batch_size']
def stop(self):
with QtCore.QMutexLocker(self.mutex):
self.stop_flg = True
def run(self):
print("Worker: started")
with QtCore.QMutexLocker(self.mutex):
self.stop_flg = False
self.started.emit()
for i,yt in enumerate(self.gen):
# predict
y_preds = self.bed.predict()
print("{0}: yt={1}, y_pred={2}".format(i, yt, y_preds))
self.bed.supply(yt)
self.vis.append_data(yt, y_preds)
if i % self.pretrain_step == 0 and 0 < self.pretrain_epochs:
# pretrain
avg_cost = self.bed.pretrain(self.pretrain_epochs, learning_rate=self.pretrain_lr, batch_size=self.pretrain_batch_size)
print(" pretrain cost: {0}".format(avg_cost))
pass
# finetune
costs = self.bed.finetune(self.finetune_epochs, learning_rate=self.finetune_lr, batch_size=self.finetune_batch_size)
train_cost, valid_cost, test_cost = costs
print(" train cost: {0}".format(train_cost))
self.vis.append_cost(train_cost, valid_cost, test_cost)
self.updated.emit(yt, y_preds)
time.sleep(self.delay)
if self.stop_flg:
print(' --- iteration end ---')
break
self.stopped.emit()