• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.vector_add函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中utils.vector_add函数的典型用法代码示例。如果您正苦于以下问题:Python vector_add函数的具体用法?Python vector_add怎么用?Python vector_add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: on_mouse_move

    def on_mouse_move(self, event, position):
        if self.scroll_point:
            change = utils.make_vector(position, self.scroll_point)
            self.canvas.set_viewport(
                utils.vector_add(self.canvas.get_viewport(), change))
            return

        if self.drag_items:
            change = utils.make_vector(self.drag_mouse_origin, position)
            for i, item in enumerate(self.drag_items):
                new_position = utils.vector_add(self.drag_items_origin[i], change)
                new_position = utils.snap_to_grid(new_position, self.grid_size)
                item.set_position(new_position)
            self.canvas.redraw()
            return

        item = self.get_item_at_position(position)
        if item:
            self.canvas.set_cursor(get_cursor(item.action))
            if self.selection:
                self.mouseover_items = item.get_group()
                self.set_highlight()
        elif self.mouseover_items:
            self.canvas.set_cursor(None)
            self.mouseover_items = []
            self.set_highlight()
        else:
            self.canvas.set_cursor(None)
开发者ID:Palasekm,项目名称:Kaira,代码行数:28,代码来源:cconfig.py


示例2: add_extra_simrun_items

    def add_extra_simrun_items(self, items):
        def text_fn(text, item, attr):
            return lambda: ("{0}: {1}".format(text,
                                              getattr(item, attr)),)
        for item in self.net.transitions():
            box_position = item.box.get_position()
            if item.get_time_substitution():
                size = item.box.size
                position = utils.vector_add_t(box_position, size, 0.5)
                i = citems.SimRunLabel(
                    None, "simrunbox", citems.RelativePlacement(item.box, position))
                i.text_fn = text_fn("time", item, "time_substitution_code")
                items.append(i)
                box_position = utils.vector_add(box_position, (0, 20))

            if item.get_clock_substitution():
                size = item.box.size
                position = utils.vector_add_t(box_position, size, 0.5)
                i = citems.SimRunLabel(
                    None, "simrunbox", citems.RelativePlacement(item.box, position))
                i.text_fn = text_fn("clock", item, "clock_substitution_code")
                items.append(i)

        for item in self.net.edges():
            if item.get_size_substitution():
                position = utils.vector_add(item.inscription.get_position(), (0, 10))
                i = citems.SimRunLabel(
                    None, "simrunbox", citems.RelativePlacement(item.inscription, position))
                i.text_fn = text_fn("size", item, "size_substitution_code")
                items.append(i)
开发者ID:Palasekm,项目名称:Kaira,代码行数:30,代码来源:neteditcc.py


示例3: get_packet_items

    def get_packet_items(self):
        def get_size(self, cr):
            if not self.texts:
                return
            tx = max(utils.text_size(cr, t)[0] for t in self.texts)
            tx += 20
            ty = 13 * len(self.texts) + 4
            return (tx, ty)

        result = []
        color = (0.8, 0.3, 0.1, 0.85)
        color_active = (1, 1, 1)
        color_inactive = (0.8, 0.8, 0.8)
        for edge in self.perspective.runinstance.net.edges_out():
            packets = self.perspective.get_packets_info(edge.id)
            packet_box = self.packet_boxes.get(edge.id)
            if packet_box is None:
                position = utils.vector_add(edge.inscription.get_position(),
                                            (0, 15))
                placement = citems.AbsPlacement(position)
                packet_box = citems.Box(None,
                                        "packetbox",
                                        placement)
                packet_box.size_fn = get_size
                packet_box.background = color
                packet_box.radius = 5

                self.packet_boxes[edge.id] = packet_box
            result.append(packet_box)
            packet_box.texts = [ p[3] for p in packets ]
            for i, (process_id, origin_id, top, text) in enumerate(packets):
                position = utils.vector_add(packet_box.get_position(),
                                            (10, 13 * i))
                t = citems.Text(
                    None,
                    "packet",
                    packet_box.get_relative_placement(position),
                    text)
                if top:
                    t.color = color_active
                    t.packet_data = (process_id, origin_id)
                else:
                    t.color = color_inactive
                    t.packet_data = None
                t.padding_y = 4
                t.z_level = 15
                t.action = None
                result.append(t)
        return result
开发者ID:Palasekm,项目名称:Kaira,代码行数:49,代码来源:netview.py


示例4: solve_move

 def solve_move(self, ntuple):
     print('mock solver: begin move')
     world = self.world
     home_pos = world.robot1_instance.pos
     for parameters in ntuple.parameters:
         acted_upon = parameters.acted_upon
         heading = parameters.heading
         direction = parameters.direction
         goal = parameters.goal
         inst = getattr(world, acted_upon)
         if goal:
             # TODO: super/subtype relations missing!
             if goal.ontological_category.type() == 'location':
                 print('|  move(x={x}, y={y}, z=0.0)'.format(x=goal.xCoord, y=goal.yCoord))
                 self.setpos(inst, (float(goal.xCoord), float(goal.yCoord), 0.0))    
             else:
                 # We assume it's an object, like a box or a block
                 obj = getattr(world, goal.referent.type())
                 print('|  move(x={x}, y={y}, z={z})'.format(x=obj.pos.x, y=obj.pos.y, z=obj.pos.z))
                 self.setpos(inst, (obj.pos.x, obj.pos.y, obj.pos.z))    
         elif direction == 'home':
             print('|  move(x={x}, y={y}, z=0.0)'.format(x=home_pos.x, y=home_pos.y))
             self.setpos(inst, (home_pos.x, home_pos.y, home_pos.z))    
         elif heading:
             n = float(parameters.distance.value)
             pos = self.getpos(inst)
             newpos = vector_add(pos, vector_mul(n, self.headings[heading]))
             print('|  move(x={0[0]}, y={0[1]}, z={0[2]})'.format(newpos))
             self.setpos(inst, newpos)
     print('mock solver: end move')        
开发者ID:icsi-berkeley,项目名称:ecg-specializer,代码行数:30,代码来源:solver_test.py


示例5: is_legal_move

    def is_legal_move(self, board, start, steps, player):
        """Move is a tuple which contains starting points of checkers to be
		moved during a player's turn. An on-board move is legal if both the destinations
		are open. A bear-off move is the one where a checker is moved off-board.
        It is legal only after a player has moved all his checkers to his home."""
        dest1, dest2 = vector_add(start, steps)
        dest_range = range(0, 24)
        move1_legal = move2_legal = False
        if dest1 in dest_range:
            if self.is_point_open(player, board[dest1]):
                self.move_checker(board, start[0], steps[0], player)
                move1_legal = True
        else:
            if self.allow_bear_off[player]:
                self.move_checker(board, start[0], steps[0], player)
                move1_legal = True
        if not move1_legal:
            return False
        if dest2 in dest_range:
            if self.is_point_open(player, board[dest2]):
                move2_legal = True
        else:
            if self.allow_bear_off[player]:
                move2_legal = True
        return move1_legal and move2_legal
开发者ID:bcorfman,项目名称:aima-python,代码行数:25,代码来源:games.py


示例6: get_canvas_items

 def get_canvas_items(self):
     items = [ self.box, self.guard ]
     if self.clock:
         p = utils.vector_add(self.box.get_position(), (-9, 7))
         items.append(citems.ClockIcon(
             self, "clock", self.box.get_relative_placement(p)))
     return items
开发者ID:Palasekm,项目名称:Kaira,代码行数:7,代码来源:net.py


示例7: __init__

 def __init__(self, net, id, position, size):
     NetItem.__init__(self, net, id)
     self.point1 = citems.Point(self, "point1", citems.AbsPlacement(position))
     self.point1.action = "resize_ltop"
     self.point2 = citems.Point(self, "point2", citems.AbsPlacement(
         utils.vector_add(position, size)))
     self.point2.owner = self
     self.point2.action = "resize_rbottom"
开发者ID:MrPablozOne,项目名称:Bakalarka_Kaira,代码行数:8,代码来源:net.py


示例8: on_mouse_move

 def on_mouse_move(self, event, position):
     if self.resize_item:
         change = utils.make_vector(self.initial_mouse, position)
         change = utils.snap_to_grid(change, self.grid_size)
         new_size = utils.vector_add(self.initial_size, change)
         new_size = utils.vector_at_least(new_size, 0, 0)
         self.resize_item.size = new_size
         self.canvas.redraw()
     else:
         NetEditCanvasConfig.on_mouse_move(self, event, position)
开发者ID:cie0037,项目名称:kaira,代码行数:10,代码来源:neteditcc.py


示例9: solve_move

    def solve_move(self, parameters):
        color = None
        size = None
        world = self.world
        print('solver: begin move_to_destination')
        #for parameters in ntuple.parameters:
        protagonist = self.get_described_obj(parameters.protagonist['objectDescriptor'])
        speed = parameters.speed * 6
        heading = parameters.heading
        goal = parameters.goal
        direction = parameters.direction
        inst =protagonist 
        #getattr(self.world, protagonist)
        if goal:
            # TODO: super/subtype relations missing!
#             print(goal)
            if 'location' in goal:
                #inst.move(x=float(goal['location'][0]), y=float(goal['location'][1]), z=0.0)
                if goal['location'] == 'home':
                    self.move(inst, self.home_pos.x, self.home_pos.y, self.home_pos.z, tolerance= 2, speed=speed) 
                else:
                    self.move(inst,float(goal['location'][0]), float(goal['location'][1]), 0.0, speed=speed) 

            elif goal == 'home':
                self.move(inst, home_pos.x, home_pos.y, home_pos.z, speed=speed)    
            elif 'referent' in goal:
                obj = getattr(self.world, goal['referent']) 
                #inst.move(x=obj.pos.x, y=obj.pos.y, z=obj.pos.z)
                self.move(inst, obj.pos.x, obj.pos.y, obj.pos.z, speed=speed)
            elif ('partDescriptor' in goal):
                if goal['partDescriptor']['relation']['type'] == 'side':
                    loc = self.get_described_part_pos(goal['partDescriptor'],inst)
                    if (loc):
                        self.move(inst, loc[0], loc[1], tolerance= 2, speed=speed)
            else:
                if ('objectDescriptor') in goal: 
                    properties = goal['objectDescriptor']
                    obj = self.get_described_obj(properties, multiple=True)
                    if (obj):
                        self.move(inst, obj.pos.x, obj.pos.y, obj.pos.z, speed=speed)         
                elif ('locationDescriptor') in goal:
                    properties = goal['locationDescriptor']
                    loc = self.get_described_loc_pos(properties,getattr(self.world, inst))
                    if (loc):
                        self.move(inst, loc[0], loc[1], speed=speed)    
        elif heading:
            n = float(parameters.distance.value)
            print(inst)
            name = getattr(inst, 'name')
            #pos = getattr(inst, 'pos') #self.getpos(inst)
            pos = self.getpos(name)
            newpos = vector_add(pos, vector_mul(n, self.headings[heading]))
            self.move(inst, newpos[0], newpos[1], newpos[2], speed=speed)
        print('solver: end move_to_destination')
开发者ID:icsi-berkeley,项目名称:ecg-specializer,代码行数:54,代码来源:solver2.py


示例10: get_canvas_items

    def get_canvas_items(self, view_mode):
        items = NetElement.get_canvas_items(self, view_mode)
        items.append(self.guard)
        if self.collective:
            items.append(self.root)

        if self.clock:
            p = utils.vector_add(self.box.get_position(), (-9, 7))
            items.append(citems.ClockIcon(
                self, "clock", self.box.get_relative_placement(p)))
        return items
开发者ID:MrPablozOne,项目名称:Bakalarka_Kaira,代码行数:11,代码来源:net.py


示例11: create_activations

 def create_activations(self, values):
     results = []
     position = self.get_position()
     start = utils.vector_add(position, (12, 0))
     position = start
     count = 0
     for text, color, data in values:
         activation = TransitionActivation(data,
                                           "activation",
                                           self.get_relative_placement(position),
                                           text,
                                           color)
         results.append(activation)
         position = utils.vector_add(position, (self.space_x + activation.size[0], 0))
         count += 1
         if count == 6:
             count = 0
             start = utils.vector_add(start, (0, self.space_y + activation.size[1]))
             position = start
     return results
开发者ID:DiPi22,项目名称:kaira,代码行数:20,代码来源:citems.py


示例12: get_activation_items

 def get_activation_items(self):
     result = []
     for transition in self.perspective.runinstance.net.transitions():
         activations = self.activations.get(transition.id)
         if activations is None:
             position = utils.vector_add(transition.box.get_position(), (0, transition.box.size[1] + 10))
             activations = citems.TransitionActivations(None, "activations", citems.AbsPlacement(position))
             self.activations[transition.id] = activations
         values = self.perspective.get_activations_values(transition)
         if values:
             result.append(activations)
             result += activations.create_activations(values)
     return result
开发者ID:Kobzol,项目名称:kaira,代码行数:13,代码来源:netview.py


示例13: get_error_items

 def get_error_items(self):
     result = []
     messages = self.net.project.get_error_messages(self)
     if not messages:
         return result
     items = self.get_canvas_items_dict(None)
     for name in messages:
         item = items.get(name)
         if item is None:
             # Key was not found, take first item
             # For transition/place it is expected that "box" is returned
             item = self.get_canvas_items()[0]
         position = utils.vector_add(item.get_position(), item.size)
         position = utils.vector_add(position, (0, 0))
         placement = item.get_relative_placement(position)
         error_item = citems.Text(None, "error", placement)
         error_item.delegate_selection = item
         error_item.background_color = (255, 0, 0)
         error_item.border_color = (0, 0, 0)
         error_item.align_y = 0
         error_item.z_level = 20
         error_item.text = messages[name][0]
         result.append(error_item)
     return result
开发者ID:MrPablozOne,项目名称:Bakalarka_Kaira,代码行数:24,代码来源:net.py


示例14: get_token_items

 def get_token_items(self):
     places = self.perspective.runinstance.net.places()
     result = []
     for place in places:
         token_box = self.token_boxes.get(place.id)
         if token_box is None:
             sx, sy = place.box.size
             position = utils.vector_add(place.box.get_position(),
                                         (sx + 20, sy / 2))
             token_box = citems.TokenBox(None, "tokenbox", citems.AbsPlacement(position))
             self.token_boxes[place.id] = token_box
         token_box.set_tokens(self.perspective.get_tokens(place),
                              self.perspective.get_new_tokens(place),
                              self.perspective.get_removed_tokens(place))
         result.append(token_box)
     return result
开发者ID:Palasekm,项目名称:Kaira,代码行数:16,代码来源:netview.py


示例15: ray_cast

 def ray_cast(self, sensor_num, kin_state):
     """Returns distace to nearest obstacle or map boundary in the direction of sensor"""
     pos = kin_state[:2]
     orient = kin_state[2]
     # sensor layout when orientation is 0 (towards North)
     #  0
     # 3R1
     #  2
     delta = ((sensor_num%2 == 0)*(sensor_num - 1), (sensor_num%2 == 1)*(2 - sensor_num))
     # sensor direction changes based on orientation
     for _ in range(orient):
         delta = (delta[1], -delta[0])
     range_count = 0
     while (0 <= pos[0] < self.nrows) and (0 <= pos[1] < self.nrows) and (not self.m[pos[0]][pos[1]]):
         pos = vector_add(pos, delta)
         range_count += 1
     return range_count
开发者ID:Chipe1,项目名称:aima-python,代码行数:17,代码来源:probability.py


示例16: particle_filtering

def particle_filtering(e, N, HMM):
    """Particle filtering considering two states variables."""
    s = []
    dist = [0.5, 0.5]
    # State Initialization
    s = ['A' if probability(dist[0]) else 'B' for i in range(N)]
    # Weight Initialization
    w = [0 for i in range(N)]
    # STEP 1
    # Propagate one step using transition model given prior state
    dist = vector_add(scalar_vector_product(dist[0], HMM.transition_model[0]),
                      scalar_vector_product(dist[1], HMM.transition_model[1]))
    # Assign state according to probability
    s = ['A' if probability(dist[0]) else 'B' for i in range(N)]
    w_tot = 0
    # Calculate importance weight given evidence e
    for i in range(N):
        if s[i] == 'A':
            # P(U|A)*P(A)
            w_i = HMM.sensor_dist(e)[0]*dist[0]
        if s[i] == 'B':
            # P(U|B)*P(B)
            w_i = HMM.sensor_dist(e)[1]*dist[1]
        w[i] = w_i
        w_tot += w_i

    # Normalize all the weights
    for i in range(N):
        w[i] = w[i]/w_tot

    # Limit weights to 4 digits
    for i in range(N):
        w[i] = float("{0:.4f}".format(w[i]))

    # STEP 2
    s = weighted_sample_with_replacement(N, s, w)
    return s
开发者ID:rajul,项目名称:aima-python,代码行数:37,代码来源:probability.py


示例17: BackPropagationLearner

def BackPropagationLearner(dataset, net, learning_rate, epochs):
    """[Figure 18.23] The back-propagation algorithm for multilayer network"""
    # Initialise weights
    for layer in net:
        for node in layer:
            node.weights = random_weights(min_value=-0.5, max_value=0.5,
                                          num_weights=len(node.weights))

    examples = dataset.examples
    '''
    As of now dataset.target gives an int instead of list,
    Changing dataset class will have effect on all the learners.
    Will be taken care of later
    '''
    o_nodes = net[-1]
    i_nodes = net[0]
    o_units = len(o_nodes)
    idx_t = dataset.target
    idx_i = dataset.inputs
    n_layers = len(net)

    inputs, targets = init_examples(examples, idx_i, idx_t, o_units)

    for epoch in range(epochs):
        # Iterate over each example
        for e in range(len(examples)):
            i_val = inputs[e]
            t_val = targets[e]

            # Activate input layer
            for v, n in zip(i_val, i_nodes):
                n.value = v

            # Forward pass
            for layer in net[1:]:
                for node in layer:
                    inc = [n.value for n in node.inputs]
                    in_val = dotproduct(inc, node.weights)
                    node.value = node.activation(in_val)

            # Initialize delta
            delta = [[] for i in range(n_layers)]

            # Compute outer layer delta

            # Error for the MSE cost function
            err = [t_val[i] - o_nodes[i].value for i in range(o_units)]
            # The activation function used is the sigmoid function
            delta[-1] = [sigmoid_derivative(o_nodes[i].value) * err[i] for i in range(o_units)]

            # Backward pass
            h_layers = n_layers - 2
            for i in range(h_layers, 0, -1):
                layer = net[i]
                h_units = len(layer)
                nx_layer = net[i+1]
                # weights from each ith layer node to each i + 1th layer node
                w = [[node.weights[k] for node in nx_layer] for k in range(h_units)]

                delta[i] = [sigmoid_derivative(layer[j].value) * dotproduct(w[j], delta[i+1])
                            for j in range(h_units)]

            #  Update weights
            for i in range(1, n_layers):
                layer = net[i]
                inc = [node.value for node in net[i-1]]
                units = len(layer)
                for j in range(units):
                    layer[j].weights = vector_add(layer[j].weights,
                                                  scalar_vector_product(
                                                  learning_rate * delta[i][j], inc))

    return net
开发者ID:Seenivasanseeni,项目名称:aima-python,代码行数:73,代码来源:learning.py


示例18: backward

def backward(HMM, b, ev):
    sensor_dist = HMM.sensor_dist(ev)
    prediction = element_wise_product(sensor_dist, b)

    return(normalize(vector_add(scalar_vector_product(prediction[0], HMM.transition_model[0]),
                                scalar_vector_product(prediction[1], HMM.transition_model[1]))))
开发者ID:rajul,项目名称:aima-python,代码行数:6,代码来源:probability.py


示例19: forward

def forward(HMM, fv, ev):
    prediction = vector_add(scalar_vector_product(fv[0], HMM.transition_model[0]),
                            scalar_vector_product(fv[1], HMM.transition_model[1]))
    sensor_dist = HMM.sensor_dist(ev)

    return(normalize(element_wise_product(sensor_dist, prediction)))
开发者ID:rajul,项目名称:aima-python,代码行数:6,代码来源:probability.py


示例20: get_relative_placement

 def get_relative_placement(self, position, absolute=True):
     if not absolute:
         position = utils.vector_add(position, self.placement.get_position())
     return RelativePlacement(self.placement, position)
开发者ID:DiPi22,项目名称:kaira,代码行数:4,代码来源:citems.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.visualize_samples函数代码示例发布时间:2022-05-26
下一篇:
Python utils.validate_topology函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap