本文整理匯總了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