zoukankan      html  css  js  c++  java
  • open_spiel 随笔

    ------------恢复内容开始------------

    ------------恢复内容开始------------

    遇到的一些疑惑且已经解决的

    1. SPIEL_CHECK_GT()诸如此类的函数还有EQ 等
    我猜测都是类似java的
    EQ 就是 EQUAL等于
    NE就是 NOT EQUAL不等于
    GT 就是 GREATER THAN大于 
    LT 就是 LESS THAN小于
    GE 就是 GREATER THAN OR EQUAL 大于等于
    LE 就是 LESS THAN OR EQUAL 小于等于
    没找到这些宏定义或者是函数
    但是结合代码来看,逻辑是说得通的。
    2. Action 类
    其实是类型,就是一个64位的int, 定义在 spiel_util.h 文件中
    using Action = int64_t;

    3. RankActionMixedBase 和 UnrankActionMixedBase
    就是将向量转换为 integer,和它的逆过程

    定义如下:
     1 // Helpers used to convert actions represented as integers in mixed bases.
     2 // E.g. RankActionMixedBase({2, 3, 6}, {1, 1, 1}) = 1*18 + 1*6 + 1 = 25,
     3 // and UnrankActioMixedBase(25, {2, 3, 6}, &digits) sets digits to {1, 1, 1}.
     4 // For the rank, both vectors must be the same size. For the unrank, the digits
     5 // must already have size equal to bases.size().
     6 Action RankActionMixedBase(const std::vector<int>& bases,
     7                            const std::vector<int>& digits);
     8 
     9 void UnrankActionMixedBase(Action action, const std::vector<int>& bases,
    10                            std::vector<int>* digits);
    怎么将一个向量转化为一个整数?
    代码比较简单
     1 // Used to convert actions represented as integers in mixed bases.
     2 Action RankActionMixedBase(const std::vector<int>& bases,
     3                            const std::vector<int>& digits) {
     4   SPIEL_CHECK_EQ(bases.size(), digits.size());
     5   SPIEL_CHECK_GT(digits.size(), 0);
     6 
     7   Action action = 0;
     8   int one_plus_max = 1;
     9   for (int i = digits.size() - 1; i >= 0; --i) {
    10     SPIEL_CHECK_GE(digits[i], 0);
    11     SPIEL_CHECK_LT(digits[i], bases[i]);
    12     SPIEL_CHECK_GT(bases[i], 1);
    13     action += digits[i] * one_plus_max;
    14     one_plus_max *= bases[i];
    15     SPIEL_CHECK_LT(action, one_plus_max);
    16   }
    17 
    18   return action;
    19 }
     1 void UnrankActionMixedBase(Action action, const std::vector<int>& bases,
     2                            std::vector<int>* digits) {
     3   SPIEL_CHECK_EQ(bases.size(), digits->size());
     4   for (int i = digits->size() - 1; i >= 0; --i) {
     5     SPIEL_CHECK_GT(bases[i], 1);
     6     (*digits)[i] = action % bases[i];
     7     action /= bases[i];
     8   }
     9   SPIEL_CHECK_EQ(action, 0);
    10 }

    以下是原理

    三个判断要求 base[i] > 1, digits[i] >= 0, base[i] >= digits[i]

    生成的整数是一系列的因式和, 而除了第一个因式之外的所有因式都有base[-1](这里的-1表示倒数第一个),又因为digits[-1]<base[-1] 所以取模运算后就是digits[-1]

    然后再整除一下,进行上面的操作就可以得到倒数第二个数。

    ------------恢复内容结束------------

    ------------恢复内容结束------------

  • 相关阅读:
    IBM X3650 M4服务器安装centos找不到硬盘的解决方法
    页面头部title、description、keywords标签的优化
    SEO优化之Title 和 Meta 标签
    WPA字典锦集
    PIN码计算锦集
    神经网络入门 第6章 识别手写字体
    神经网络入门 第5章 实现多层神经网络BP算法
    神经网络入门 第4章 神经网络可以模拟任意函数
    神经网络入门 第3章 S函数
    神经网络入门 第2章 编写第一个神经元
  • 原文地址:https://www.cnblogs.com/zh1903/p/12832163.html
Copyright © 2011-2022 走看看