本文整理匯總了Python中region.Region.doRound方法的典型用法代碼示例。如果您正苦於以下問題:Python Region.doRound方法的具體用法?Python Region.doRound怎麽用?Python Region.doRound使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類region.Region
的用法示例。
在下文中一共展示了Region.doRound方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testCount
# 需要導入模塊: from region import Region [as 別名]
# 或者: from region.Region import doRound [as 別名]
def testCount():
rows = 5
cols = 5
coverage = 20
numbits = 10
numRounds = 500
trainingRounds = numRounds/4
originalInputVector = InputVector(numbits)
inputVector = InputVector(0)
predictions = dict()
#repeat several times to increase activity:
for i in range(3):
inputVector.extendVector(originalInputVector)
desiredLocalActivity = DESIRED_LOCAL_ACTIVITY
newRegion = Region(rows,cols,inputVector,coverage,desiredLocalActivity)
outputVector = newRegion.getOutputVector()
correctBitPredictions = 0
for round in range(numRounds): # This test executes the CLA for a set number of rounds.
#print("Round: " + str(round))
# if (round % 2 == 0):
# val = 682
# else:
# val = 341
val = Ultrasonic(brick, PORT_1).get_sample()
setInput(originalInputVector,val)
inputString = inputVector.toString()
outputString = outputVector.toString()
#print(originalInputVector.toString())
#for bit in originalInputVector.getVector():
# print(bit.bit)
# print('')
# print(inputString)
if outputString in predictions:
currentPredictionString = predictions[outputString]
else:
currentPredictionString = "[New input]"
pred[outputString] = inputString
print("Round: %d" % round) # Prints the number of the round
printStats(inputString, currentPredictionString)
if (round > trainingRounds):
correctBitPredictions += stringOverlap(currentPredictionString, predictions[outputString])
newRegion.doRound()
printColumnStats(newRegion)
for key in predictions:
print("key: " + key + " predictions: " + predictions[key])
print("Accuracy: " + str(float(correctBitPredictions)/float((30*(numRounds-trainingRounds)))))
示例2: testCount
# 需要導入模塊: from region import Region [as 別名]
# 或者: from region.Region import doRound [as 別名]
def testCount():
rows = 5
cols = 5
coverage = 20
numbits = 10 # I may need more bits for my readngs.
numRounds = 500
trainingRounds = numRounds/4
originalInputVector = InputVector(numbits)
inputVector = InputVector(0)
predictions = dict()
# Repeat several times to increase activity:
# Seems to just extend the number of elements in inputVector by numbits (10) 3 times.
# Why not extend it by 3*numbits?
# I think becuase rather than make it 3 times as long, it actually repeats the vector three times,
# probably so as to, as said above, increase activity in those cells and aid learning.
# Good old repartition. In which case, I'm not sure I want to use this in my tests...
for i in range(3):
inputVector.extendVector(originalInputVector)
# Get a non-local variable and feed it to a local one for local manipulation.
desiredLocalActivity = DESIRED_LOCAL_ACTIVITY
# This sets up a new region, called newRegion,
# a variable called ouputVector, which calls a method to find just that,
# and a variable for the number of correct prodicitons, initialised as 0.
newRegion = Region(rows,cols,inputVector,coverage,desiredLocalActivity)
outputVector = newRegion.getOutputVector()
correctBitPredictions = 0
# This is where the action starts. This loop forms the main body of the test.
# For every time round, an input is given, the CLA updates spacial and temporal
# poolers with this new input and an output is found.
for round in range(numRounds):
# The old version gave two inputs alternatly. The aim was to get the CLA to
# predict one of two numbers.
#print("Round: " + str(round))
# if (round % 2 == 0):
# val = 682
# else:
# val = 341
val = Ultrasonic(brick, PORT_1).get_sample() # Instead I'm now feeding in readings from the sonar.
setInput(originalInputVector,val) # These next few lines convert the inputs and outputs from integers to bitstrings,
inputString = inputVector.toString() # so that the CLA can handle them.
outputString = outputVector.toString()
#print(originalInputVector.toString())
#for bit in originalInputVector.getVector():
# print(bit.bit)
# print('')
# print(inputString)
if outputString in predictions: # predictions was set up at the start, you might have missed it.
currentPredictionString = predictions[outputString]
else:
currentPredictionString = "[New input]"
predictions[outputString] = inputString # I'm sure this line should be here. It's not indented in the origonal.
print("Round: %d" % round) # Prints the number of the round
printStats(inputString, currentPredictionString)
if (round > trainingRounds):
correctBitPredictions += stringOverlap(currentPredictionString, predictions[outputString])
newRegion.doRound() # The CLA bit!
printColumnStats(newRegion)
# With the experiment now over, stat summaries are now printed.
for key in predictions:
print("key: " + key + " predictions: " + predictions[key])
print("Accuracy: " + str(float(correctBitPredictions)/float(30*(numRounds-trainingRounds))))