在 Chapel 中使用域进行随机子集化的模式
Pattern for random subsetting with domains in Chapel
这是我的设置。在曲棍球比赛中,球员组成 "lines" 同时在冰上。 "forward" 线是左翼、中翼和右翼的三重奏。 "D" 线是一对左 D 线和右 D 线。在啤酒联赛中,您通常为 13 名滑冰运动员穿衣 = 3 条前锋线、2 条 D 线和一个守门员。
假设我有20个人想玩。我想从 13 名随机滑冰者中构建线条。我必须保留他们的名字和球衣号码。我想知道这是否是 Chapel Domains 的工作。例如,像
var player_ids: domain(1) = {1..20}
var jerseys [player_ids] = [71, 99, 97, ...]
var names [player_ids] = ['Alice', 'Bonobo', 'Changarakoo'...]
这是一个简单的想法,但现在我想
1. Pick three random players and assign them to Line 1 F
2. Pick three from the remainders and assign the to Line 2 F
...
n-1: Use the player ids to create an indicator matrix (details aren't important)
n: WIN!
n-1
的重点是我必须能够在最后引用球员ID和球衣号码。
Chapel 中正确的模式是什么?
啤酒曲棍球队教练
可以使用这个概念
也
( live >>> online )
( sure, numbers will vary, no fixed RNG-seed was set )
让我们更深入地了解一下这个过程。随机选择是故事中数学上更难的部分(与教练本人相比,合规性会使滑冰场外领域的问题更加复杂(参考下文))。
所以,让我们接受团队设置是静态地图,其中球员的序号映射到 F_line{1..3,1..3}, D_line{1..2,1..2}, G, Rest{1..7}
use Random;
var aRandomTEAM = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ]; // a known, contiguous ENUM of <anonymised_HASH_ID#s>
permutation( aRandomTEAM ); // a known, static MAP of aRandomTEAM -> F_line{1..3}, D_line1{1..2}, G, Rest
for id in {1..13}{
writeln( " a Static MAP position of TEAM[",
id, "]: will be played by anonymised_HASH_ID#( ",
aRandomTEAM[id], " )"
);
}
对于人类可读的检查,这会产生:
a Static MAP position of TEAM[1]: will be played by anonymised_HASH_ID#( 20 )
a Static MAP position of TEAM[2]: will be played by anonymised_HASH_ID#( 5 )
a Static MAP position of TEAM[3]: will be played by anonymised_HASH_ID#( 11 )
a Static MAP position of TEAM[4]: will be played by anonymised_HASH_ID#( 4 )
a Static MAP position of TEAM[5]: will be played by anonymised_HASH_ID#( 15 )
a Static MAP position of TEAM[6]: will be played by anonymised_HASH_ID#( 7 )
a Static MAP position of TEAM[7]: will be played by anonymised_HASH_ID#( 16 )
a Static MAP position of TEAM[8]: will be played by anonymised_HASH_ID#( 12 )
a Static MAP position of TEAM[9]: will be played by anonymised_HASH_ID#( 8 )
a Static MAP position of TEAM[10]: will be played by anonymised_HASH_ID#( 18 )
a Static MAP position of TEAM[11]: will be played by anonymised_HASH_ID#( 19 )
a Static MAP position of TEAM[12]: will be played by anonymised_HASH_ID#( 17 )
a Static MAP position of TEAM[13]: will be played by anonymised_HASH_ID#( 3 )
然而,机器可读的 post-processing 可能会将这些映射到请求的数组,保持敏感的个人详细信息安全和独立,让 GUUID#-reference 链接到名称和所有其他详细信息安全。引用完整性既便宜又安全,并且从(有意)连续序数到代理匿名哈希表的静态唯一关联映射的实现是微不足道的(参考不透明域和数组以获得可能的进一步灵感)。
法律警告:
如果在受监管的领域使用随机化,则应格外小心,因为必须记录合规性,并执行和验证方法稳健性的积极证据。
文档可能会提供有关在某些具有法律要求的领域中使用当前随机化实施的已知风险的更多详细信息:
Permuted Linear Congruential Random Number Generator
This module provides PCG random number generation routines. See http://www.pcg-random.org/ and the paper, PCG: A Family of Simple Fast Space-Efficient Statistically Good Algorithms for Random Number Generation by M.E. O'Neill.
应特别注意一些已知的潜在限制,例如:
Note
For integers, this class uses a strategy for generating a value in a particular range that has not been subject to rigorous study and may have statistical problems.
For real numbers, this class generates a random value in [max, min] by computing a random value in [0,1] and scaling and shifting that value. Note that not all possible floating point values in the interval [min, max] can be constructed in this way.
像这样的评论应该始终引起合规官的应有注意,以便在他们预期的(受监管的)问题域强制实践和受控环境的要求中仔细预先验证使用的可行性。
这是我的建议。要不替换地抽取玩家,我在概念上想到 洗牌 一副纸牌 - 每张纸牌上都有一个玩家的名字。所以这段代码使用 Random.shuffle.
use Random;
var player_ids = {1..20};
// jersey number, name are simply keyed off off player_id
// Generate an array of player IDs
var ids_array = [i in player_ids] i;
// Randomly shuffle player IDs
shuffle(ids_array);
// Now select from the shuffled IDs the players for the game.
var cur = 1;
getLine(cur, "Forward1", 3, ids_array);
getLine(cur, "Forward2", 3, ids_array);
getLine(cur, "Forward3", 3, ids_array);
getLine(cur, "D1", 2, ids_array);
getLine(cur, "D2", 2, ids_array);
getLine(cur, "Goalie", 1, ids_array);
proc getLine(ref curIndex, lineName, playersNeeded, ids_array) {
writeln("Line ", lineName, ":");
for i in 1..playersNeeded {
writeln(" player ", ids_array[curIndex]); // would use name & jersey..
curIndex += 1;
}
}
这是我的设置。在曲棍球比赛中,球员组成 "lines" 同时在冰上。 "forward" 线是左翼、中翼和右翼的三重奏。 "D" 线是一对左 D 线和右 D 线。在啤酒联赛中,您通常为 13 名滑冰运动员穿衣 = 3 条前锋线、2 条 D 线和一个守门员。
假设我有20个人想玩。我想从 13 名随机滑冰者中构建线条。我必须保留他们的名字和球衣号码。我想知道这是否是 Chapel Domains 的工作。例如,像
var player_ids: domain(1) = {1..20}
var jerseys [player_ids] = [71, 99, 97, ...]
var names [player_ids] = ['Alice', 'Bonobo', 'Changarakoo'...]
这是一个简单的想法,但现在我想
1. Pick three random players and assign them to Line 1 F
2. Pick three from the remainders and assign the to Line 2 F
...
n-1: Use the player ids to create an indicator matrix (details aren't important)
n: WIN!
n-1
的重点是我必须能够在最后引用球员ID和球衣号码。
Chapel 中正确的模式是什么?
啤酒曲棍球队教练
可以使用这个概念
也
( live >>> online )
( sure, numbers will vary, no fixed RNG-seed was set )
让我们更深入地了解一下这个过程。随机选择是故事中数学上更难的部分(与教练本人相比,合规性会使滑冰场外领域的问题更加复杂(参考下文))。
所以,让我们接受团队设置是静态地图,其中球员的序号映射到 F_line{1..3,1..3}, D_line{1..2,1..2}, G, Rest{1..7}
use Random;
var aRandomTEAM = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ]; // a known, contiguous ENUM of <anonymised_HASH_ID#s>
permutation( aRandomTEAM ); // a known, static MAP of aRandomTEAM -> F_line{1..3}, D_line1{1..2}, G, Rest
for id in {1..13}{
writeln( " a Static MAP position of TEAM[",
id, "]: will be played by anonymised_HASH_ID#( ",
aRandomTEAM[id], " )"
);
}
对于人类可读的检查,这会产生:
a Static MAP position of TEAM[1]: will be played by anonymised_HASH_ID#( 20 )
a Static MAP position of TEAM[2]: will be played by anonymised_HASH_ID#( 5 )
a Static MAP position of TEAM[3]: will be played by anonymised_HASH_ID#( 11 )
a Static MAP position of TEAM[4]: will be played by anonymised_HASH_ID#( 4 )
a Static MAP position of TEAM[5]: will be played by anonymised_HASH_ID#( 15 )
a Static MAP position of TEAM[6]: will be played by anonymised_HASH_ID#( 7 )
a Static MAP position of TEAM[7]: will be played by anonymised_HASH_ID#( 16 )
a Static MAP position of TEAM[8]: will be played by anonymised_HASH_ID#( 12 )
a Static MAP position of TEAM[9]: will be played by anonymised_HASH_ID#( 8 )
a Static MAP position of TEAM[10]: will be played by anonymised_HASH_ID#( 18 )
a Static MAP position of TEAM[11]: will be played by anonymised_HASH_ID#( 19 )
a Static MAP position of TEAM[12]: will be played by anonymised_HASH_ID#( 17 )
a Static MAP position of TEAM[13]: will be played by anonymised_HASH_ID#( 3 )
然而,机器可读的 post-processing 可能会将这些映射到请求的数组,保持敏感的个人详细信息安全和独立,让 GUUID#-reference 链接到名称和所有其他详细信息安全。引用完整性既便宜又安全,并且从(有意)连续序数到代理匿名哈希表的静态唯一关联映射的实现是微不足道的(参考不透明域和数组以获得可能的进一步灵感)。
法律警告:
如果在受监管的领域使用随机化,则应格外小心,因为必须记录合规性,并执行和验证方法稳健性的积极证据。
文档可能会提供有关在某些具有法律要求的领域中使用当前随机化实施的已知风险的更多详细信息:
Permuted Linear Congruential Random Number Generator
This module provides PCG random number generation routines. See http://www.pcg-random.org/ and the paper, PCG: A Family of Simple Fast Space-Efficient Statistically Good Algorithms for Random Number Generation by M.E. O'Neill.
应特别注意一些已知的潜在限制,例如:
Note
For integers, this class uses a strategy for generating a value in a particular range that has not been subject to rigorous study and may have statistical problems.
For real numbers, this class generates a random value in [max, min] by computing a random value in [0,1] and scaling and shifting that value. Note that not all possible floating point values in the interval [min, max] can be constructed in this way.
像这样的评论应该始终引起合规官的应有注意,以便在他们预期的(受监管的)问题域强制实践和受控环境的要求中仔细预先验证使用的可行性。
这是我的建议。要不替换地抽取玩家,我在概念上想到 洗牌 一副纸牌 - 每张纸牌上都有一个玩家的名字。所以这段代码使用 Random.shuffle.
use Random;
var player_ids = {1..20};
// jersey number, name are simply keyed off off player_id
// Generate an array of player IDs
var ids_array = [i in player_ids] i;
// Randomly shuffle player IDs
shuffle(ids_array);
// Now select from the shuffled IDs the players for the game.
var cur = 1;
getLine(cur, "Forward1", 3, ids_array);
getLine(cur, "Forward2", 3, ids_array);
getLine(cur, "Forward3", 3, ids_array);
getLine(cur, "D1", 2, ids_array);
getLine(cur, "D2", 2, ids_array);
getLine(cur, "Goalie", 1, ids_array);
proc getLine(ref curIndex, lineName, playersNeeded, ids_array) {
writeln("Line ", lineName, ":");
for i in 1..playersNeeded {
writeln(" player ", ids_array[curIndex]); // would use name & jersey..
curIndex += 1;
}
}