当前位置: 首页>>代码示例>>Python>>正文


Python Region.runCLA方法代码示例

本文整理汇总了Python中region.Region.runCLA方法的典型用法代码示例。如果您正苦于以下问题:Python Region.runCLA方法的具体用法?Python Region.runCLA怎么用?Python Region.runCLA使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在region.Region的用法示例。


在下文中一共展示了Region.runCLA方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: experiment

# 需要导入模块: from region import Region [as 别名]
# 或者: from region.Region import runCLA [as 别名]
def experiment():
    rows = 5
    cols = 5
    coverage = 20
    numbits = 10 # I may need more bits for my readngs.
    numRounds = 10
    numRuns = 1
    minimum_distance = 7
    #trainingRounds = numRounds/4
    accuracies = []
    sonarPositionResults = []
    originalInputVector = InputVector(numbits)
    inputVector = InputVector(0)
    predictions = dict()
    state = "Going Forwards"

 
    # 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
    
    robot = Robot()
    starting_position = robot.sonarReading()
    robot.move()
 

    # 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): 
        if state == "Kill Switch: Engage!":
            break
        end_this_round = False
        stuck_counter = 0
        print state
        round_number = round+1
        print ("Round: %d" % round_number) # Prints the number of the round
            #printStats(inputString, currentPredictionString)
        robot.move()
        
        while end_this_round is False:            
            val = robot.sonarReading()
            print ("Sonar: %d cm" % val)
            sonarPositionResults.append(robot.currentSonarReading)
            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: # If output string has been seen before, 
                currentPredictionString = predictions[outputString] 
                # summon the last input that caused that prediction and make it the "currentPredictionString"? That's confusing...
            else:
                currentPredictionString = "[New input]" # If not seen before, 
            predictions[outputString] = inputString # Update the i/o record with the new relationship 
                            
            #if (round > trainingRounds): 
            correctBitPredictions += stringOverlap(currentPredictionString, predictions[outputString]) 
            #    without training rounds, stringOverlap will be trying to compare binary stings with the string 'New input'. So correct BitPredictions is going to be 0 for a while,
            #    until inputs start repeating.
                
            newRegion.runCLA() # The CLA bit!
            numRuns += 1
            
            #printColumnStats(newRegion) 
            accuracy = float(correctBitPredictions)/float(30*numRuns) 
            # Times thirty becuase it's measuring the correct prediction of BITS not whole bit-strings, and there are 30 bits per input.
            # This makes sense as bits have semantic meaning where as bit-strings dont!
            accuracies.append(accuracy)
            
            if robot.killSwitch() == True: # This will terminate all loops and move to the end of the program
                end_this_round = True
                state = "Kill Switch: Engage!"
                print state
            if state == "Going Forwards":
                if robot.currentSonarReading <= minimum_distance: 
                    stuck_counter += 1
                if stuck_counter == 2:     # This routine confirms that a wall is hit, then sends the robot back to the start position
                    robot.stop()             
                    print "Stuck Reflex"
#.........这里部分代码省略.........
开发者ID:FizzyMcPhysics,项目名称:cla,代码行数:103,代码来源:test2.py


注:本文中的region.Region.runCLA方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。