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


Python Model.update方法代码示例

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


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

示例1: update

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import update [as 别名]
def update():
    '''
    Prompt user to insert a new record or update an existing record
    to data file.
    '''
    # Read file
    m = Model(compute=False)
    print('\n', m.df.tail())

    # Enter date. Default is today.
    today = str(datetime.now().date())
    date = input('Enter {0} ({1}): '.format(DATE, today))
    if date == '':
        date = today
    d = pd.Timestamp(date)

    # Enter weight.
    weight = input('Enter {0}: '.format(WEIGHT))
    w = float(weight)

    # Update table
    m.update(d, w)
    print('\n', m.df.tail())

    # Write file
    confirm = input('Write file (y/[n])?: ')
    if confirm == 'y':
        m.write()
开发者ID:tomboo,项目名称:weight,代码行数:30,代码来源:update.py

示例2: __init__

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import update [as 别名]
class Perceptron:
    '''
    word_sta is in the form:
    word -> tag -> count
    '''
    def __init__(self, train_data_file, feature_template_list, model_file, old_model_file = None, word_sta = {}):
        self.train_data_file = train_data_file
        self.model = Model(feature_template_list, list(ALL_LABEL), old_model_file)
        self.model_file = model_file
        self.prior = word_sta

    def train(self, iteration, keep):
        '''
        perceptron train algorithm
        '''
        for it in xrange(iteration):
            viterbi_time = 0
            update_time = 0
            on = 0
            ln = 0
            label_len = len(ALL_LABEL) ** 2
            same = [0, 0]
            print >> sys.stdout, 'perceptron iteration', it + 1
            for (chunk, line) in read_train_data(self.train_data_file):
                ln += 1
                if ln % 1000 == 0:
                    print >> sys.stdout, 'complete %d sentences in %d secs' % (ln, viterbi_time)
                if random.random() > keep:
                    continue
                observe_data = [w[0] for w in line]
                ideal_lable = [w[1] for w in line]
                start = time.clock()
                infer_label = self.model.viterbi(observe_data, self.prior)
                end = time.clock()
                ss = 0
                for li in xrange(len(ideal_lable)): ss += 1 if ideal_lable[li] == infer_label[li] else 0
                same[0] += float(ss) / len(ideal_lable)
                same[1] += 1
                on += len(observe_data) * label_len                
                viterbi_time += end - start
                start = time.clock()
                self.model.update(observe_data, ideal_lable, infer_label)
                end = time.clock()
                update_time += end - start                
            print >> sys.stdout, 'complete %d iteration in %d secs with precision %f' %(it + 1, viterbi_time, same[0] / same[1])
            print >> open(self.model_file + '.delta' + str(it + 1), 'w'), self.model
        print >> open(self.model_file, 'w'), self.model
开发者ID:jzbjyb,项目名称:globalLinearModel,代码行数:49,代码来源:perceptron.py

示例3: Engine

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import update [as 别名]
class Engine(threading.Thread):
    def __init__(self, reset, preset):
        threading.Thread.__init__(self)
        random.seed()
        self.terminated = False
        self.model = Model(reset, preset)
        self.speed = 10.0 #update rate in seconds
        self.update_flag_tick = [threading.Event(), threading.Event()]
        self.update_flag_global = threading.Event()
        self.tick = 1
        self.time0 = time.time()
        self.update_flag_global.set()
        self.update_flag_tick[1].set()
        self.date = datetime.date(1000,1,1)
        self.day = datetime.timedelta(days=1)

    def run(self):
        print('Engine started.')
        while not self.terminated:
            #update rate
            if (time.time() - self.time0) < self.speed:
                time.sleep(self.speed - (time.time() - self.time0))
            print("Start Update")
            self.time0 = time.time()
            #Update clock
            #Update model
            if self.tick%2:
                self.update_flag_tick[1].clear()
            else:
                self.update_flag_tick[0].clear()
            
            self.update_flag_global.clear()

            self.model.update(self.date)
            self.tick += 1
            self.date += self.day
            print("Finish Update")
            self.update_flag_global.set()
            if self.tick%2:
                self.update_flag_tick[1].set()
            else:
                self.update_flag_tick[0].set()
开发者ID:matteli,项目名称:histemul,代码行数:44,代码来源:engine.py

示例4: DrawablePlayer

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import update [as 别名]
class DrawablePlayer(object):
    """docstring for DrawablePlayer"""
    def __init__(self, player, batch, fac):
        super(DrawablePlayer, self).__init__()
        self.state = player.state
        # self.rect = player.rect.copy()
        # self.batch = batch
        self.model = Model(path.join('graphics', 'metatest.dae'), fac.x)
        self.model.change_color([c / 255. for c in player.rect.color] + [1.])
        self.weapon = None
        # self.scale(fac)

    def scale(self, fac):
        self.rect.pos *= fac
        self.rect.width *= fac.x
        self.rect.height *= fac.y
        self.rect.add(self.batch)

    def update(self, state, fac):
        pos = vec2(*state.pos) * fac
        # self.rect.update(*pos)
        self.state = state.copy()
        self.state.mpos = state.mpos - state.pos - vec2(16, 54)
        self.state.pos = pos

    def animate(self, dt):
        self.model.update(dt, self.state)

    def update_weapon(self, weapon):
        if weapon != self.weapon:
            self.model.update_weapon(weaponcolors[weapon])
            self.weapon = weapon

    def attack(self):
        self.model.start_attack()

    def draw(self, mvp):
        self.model.draw(mvp)

    def remove(self):
        # self.rect.remove()
        self.model.remove()
开发者ID:mokapharr,项目名称:python_game,代码行数:44,代码来源:views.py

示例5: zip

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import update [as 别名]
        for row, col in zip(*np.where(node.grid == 0)):
            newnode = Node(move = 4, grid = node.grid)
            newnode.grid[row, col] = 2
            node.children.append(decide(newnode, depth - 1))
        node.getScore()
        return node



if __name__ == "__main__":
    # pygame.init()
    while True:
        current_model = Model()
        # view = View(current_model)
        while True:
            grid = current_model.grid.copy()
            if len(np.where(grid != 0)[0]) > 8:
                depth = 5
            else:
                depth = 3
            node = decide(Node(5, grid), depth = depth)
            move = node.bestMove()
            if move == None:
                print "GAMEOVER"
                break
            current_model.move(move)
            # view.draw()
            current_model.update()
            # view.draw()
        print np.max(node.grid)
开发者ID:sihrc,项目名称:2048-Python-ML,代码行数:32,代码来源:minimax.py


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