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


Python NeuralNet.get_num_weights方法代码示例

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


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

示例1: MineSweeper

# 需要导入模块: from neuralnet import NeuralNet [as 别名]
# 或者: from neuralnet.NeuralNet import get_num_weights [as 别名]

#.........这里部分代码省略.........
            if l < closest_so_far:
                closest_so_far = l
                closest_object = self.position - mine.position
                self.closest_mine = ctr
            
            ctr += 1
            
        return closest_object
     
    def update(self, all_mines):
        '''
        This is the real brains function. Takes an iterable of mines. It first
        takes sensor readings and feed these to the ANN of our minesweeper.
        The inputs are:
            1) A vector (Vector2D) to the closest mine,
            2) The "look at" vector (also a Vector2D).
        
        The brain(ANN) returns 2 outputs, ltrack and rtrack - which are forces
        applied on left and right tracks, respectively. Depending on these, the
        acceleration and/or the rotation is calculated and the position vector
        is updated accordingly.
        '''
        # Inputs to the brain.
        inputs = []
        # First input: vector to the closest mine.
        closest_mine = self.get_closest_mine(all_mines)
        closest_mine.normalize()
        # Place the inputs on the input list
        inputs.append(closest_mine.x)
        inputs.append(closest_mine.y)
        inputs.append(self.look_at.x)
        inputs.append(self.look_at.y)
        # Now, excite the brain and get the feedback
        output = self.brain.excite(inputs, settings.BIAS, filter_sigmoid=True)
        # Make sure we get back the expected number of outputs
        if len(output) != settings.NUM_OUTPUTS:
            raise Exception( 'An error occurred: The number of outputs from '
                            +'the ANN is not what was expected.')
        
        self.ltrack, self.rtrack = output
        
        rot_force = self.ltrack - self.rtrack
        rot_force = clamp(rot_force, 
                          -settings.MAX_TURN_RATE, 
                          settings.MAX_TURN_RATE)
        # New rotation and speed:
        self.rotation += rot_force
        self.speed = self.ltrack + self.rtrack
        # Get the new look at:
        self.look_at.x = -math.sin(self.rotation)
        self.look_at.y = math.cos(self.rotation)
        # Get the new position:
        self.position += (self.look_at * self.speed)
        # Wrap around the screen
        if self.position.x > settings.WINDOW_WIDTH:
            self.position.x = 0
        
        if self.position.x < 0:
            self.position.x = settings.WINDOW_WIDTH
            
        if self.position.y > settings.WINDOW_HEIGHT:
            self.position.y = 0
        
        if self.position.y < 0:
            self.position.y = settings.WINDOW_HEIGHT
        # End update()
    
    def check_for_mine(self, mines, size):
        '''
        checks for a collision with the closest mine.
        '''
        d = self.position - mines[self.closest_mine].position
        if d.length() < (size + 5):
            return self.closest_mine
        
        return -1
    
    def inc_fitness(self):
        self.fitness += 1
    
    def put_weights(self, weights):
        self.brain.put_weights(weights)
    
    def get_num_weights(self):
        return self.brain.get_num_weights()
    
    def __repr__(self):
        return '<MineSweeper: ({0}, {1})>'.format(self.position.x,
                                                 self.position.y)
    
        
            
        
        
        
        
                
        
        
        
开发者ID:Hydex,项目名称:SmartSweepers,代码行数:93,代码来源:minesweeper.py


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