本文整理汇总了Python中machine.Machine.update方法的典型用法代码示例。如果您正苦于以下问题:Python Machine.update方法的具体用法?Python Machine.update怎么用?Python Machine.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类machine.Machine
的用法示例。
在下文中一共展示了Machine.update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: while
# 需要导入模块: from machine import Machine [as 别名]
# 或者: from machine.Machine import update [as 别名]
sync = False # Flag to check if weights are sync
nb_updates = 0 # Update counter
nb_eve_updates = 0 # To count the number of times eve updated
start_time = time.time() # Start time
sync_history = [] # to store the sync score after every update
while(not sync):
X = random() # Create random vector of dimensions [k, n]
tauA = Alice(X) # Get output from Alice
tauB = Bob(X) # Get output from Bob
tauE = Eve(X) # Get output from Eve
Alice.update(tauB, update_rule) # Update Alice with Bob's output
Bob.update(tauA, update_rule) # Update Bob with Alice's output
#Eve would update only if tauA = tauB = tauE
if tauA == tauB == tauE:
Eve.update(tauA, update_rule)
nb_eve_updates += 1
nb_updates += 1
score = 100 * sync_score(Alice, Bob) # Calculate the synchronization of the 2 machines
sync_history.append(score) # Add sync score to history, so that we can plot a graph later.
sys.stdout.write('\r' + "Synchronization = " + str(int(score)) + "% / Updates = " + str(nb_updates) + " / Eve's updates = " + str(nb_eve_updates))
if score == 100: # If synchronization score is 100%, set sync flag = True