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


Python Optimizer.run方法代码示例

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


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

示例1: main

# 需要导入模块: from optimizer import Optimizer [as 别名]
# 或者: from optimizer.Optimizer import run [as 别名]
def main(args, profile=False):
    db = DataBase(args.games)
    results = db.load_game_results(mingames=50)
    print('{} games loaded.'.format(len(results)))
    players = db.load_players()
    optimizer = Optimizer(disp=True)
    optimizer.load_games(results)
    maxiter = 30 if profile else 0
    ratings, f, v = optimizer.run(method='l-bfgs-b', maxiter=maxiter)

    if profile:
        return
    print()

    by_rating = []
    for iplayer, rating in ratings.items():
        print(players[iplayer])
        mr = 0
        for date, r in sorted(rating.items()):
            date = datetime.date.fromtimestamp(date * 24 * 3600)
            print(date.isoformat(), r)
            if r > mr:
                mr = r
        by_rating.append((mr, players[iplayer]))

        print()
    print(f)
    print(f.calc(0.2) - f.calc(-0.2))

    best = list(sorted(by_rating))[-20:]
    for r, p in reversed(best):
        print('{:24} {}'.format(p, r))
开发者ID:eterevsky,项目名称:gamerank,代码行数:34,代码来源:gamerank.py

示例2: test_symmetric_wins

# 需要导入模块: from optimizer import Optimizer [as 别名]
# 或者: from optimizer.Optimizer import run [as 别名]
    def test_symmetric_wins(self):
        o = Optimizer(rand_seed=239)
        o.load_games([(1, 2, 1, 1), (1, 2, 1, 0), (2, 1, 1, 1), (2, 1, 1, 0)])
        rating, f, v = o.run(method='Newton-CG')

        self.assertAlmostEqual(
            f.calc(convert_rating_diff(rating[1][1] - rating[2][1])), 0.5, 2)
        self.assertLess(abs(rating[1][1] - rating[2][1]), 5)
开发者ID:eterevsky,项目名称:gamerank,代码行数:10,代码来源:test_optimizer.py

示例3: test_draw

# 需要导入模块: from optimizer import Optimizer [as 别名]
# 或者: from optimizer.Optimizer import run [as 别名]
    def test_draw(self):
        o = Optimizer(rand_seed=239)
        o.load_games([(1, 2, 1, 2), (2, 1, 1, 2)])
        rating, f, v = o.run(method='cg')

        self.assertAlmostEqual(f.calc(0), 0.5, 3)
        self.assertAlmostEqual(
            f.calc(convert_rating_diff(rating[1][1] - rating[2][1])), 0.5, 2)
        self.assertLess(abs(rating[1][1] - rating[2][1]), 5)
开发者ID:eterevsky,项目名称:gamerank,代码行数:11,代码来源:test_optimizer.py

示例4: test_single_game

# 需要导入模块: from optimizer import Optimizer [as 别名]
# 或者: from optimizer.Optimizer import run [as 别名]
    def test_single_game(self):
        o = Optimizer(rand_seed=239)
        o.load_games([(1, 2, 1, 1)])
        ratings, f, v = o.run()
        (total, likelihood, regularization, smoothness,
         func_hard_reg, func_soft_reg) = o.objective(v, verbose=True)
        self.assertTrue(100 < ratings[1][1] < 4000)
        self.assertTrue(100 < ratings[2][1] < 4000)
        self.assertGreater(
            f.calc(convert_rating_diff(ratings[1][1] - ratings[2][1])), 0.5)
        self.assertGreater(ratings[1][1], ratings[2][1])

        total = o.objective(v)
开发者ID:eterevsky,项目名称:gamerank,代码行数:15,代码来源:test_optimizer.py

示例5: test_time_regularization

# 需要导入模块: from optimizer import Optimizer [as 别名]
# 或者: from optimizer.Optimizer import run [as 别名]
    def test_time_regularization(self):
        o = Optimizer(rand_seed=239)
        o.load_games([(1, 2, 1, 1), (2, 1, 1, 0), (1, 2, 2, 0), (2, 1, 2, 1)])
        rating, f, v = o.run()

        (total1, _, reg, smoothness1, func_hard_reg,
         func_soft_reg) = o.objective(v, verbose=True)
        self.assertLess(func_hard_reg, 1)
        self.assertGreater(smoothness1, 0.001)

        self.assertGreater(rating[1][1], rating[1][2])
        self.assertLess(rating[2][1], rating[2][2])
        self.assertGreater(rating[1][1], rating[2][1])
        self.assertLess(rating[1][2], rating[2][2])
        prob1 = f.calc(convert_rating_diff(rating[1][1] - rating[2][1]))
        self.assertGreater(prob1, 0.51)
        prob2 = f.calc(convert_rating_diff(rating[1][2] - rating[2][2]))
        self.assertLess(prob2, 0.49)
开发者ID:eterevsky,项目名称:gamerank,代码行数:20,代码来源:test_optimizer.py

示例6: test_games1

# 需要导入模块: from optimizer import Optimizer [as 别名]
# 或者: from optimizer.Optimizer import run [as 别名]
 def test_games1(self):
     o = Optimizer(rand_seed=239)
     o.load_games(GAMES1)
     rating, f, _ = o.run(method='newton-cg')
开发者ID:eterevsky,项目名称:gamerank,代码行数:6,代码来源:test_optimizer.py


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