还有一个逻辑
出于好奇,我正在研究一个研究问题,但我不知道如何对我想到的逻辑进行编程。让我向你解释一下:
我有四个向量,例如,
v1 = 1 1 1 1
v2 = 2 2 2 2
v3 = 3 3 3 3
v4 = 4 4 4 4
我想将它们组合起来。也就是说,
v12 = v1+v2
v13 = v1+v3
v14 = v1+v4
v23 = v2+v3
v24 = v2+v4
v34 = v3+v4
做到这一步就可以了。现在的问题/技巧是,在每次迭代结束时,我将获得的向量放入黑盒函数中,它仅返回几个向量,例如 v12、v13 和 v34。现在,我想将这些向量中的每一个添加到之前未添加过的 v1、v2、v3、v4 中的一个向量。例如,v3和v4还没有添加到v12中,所以我想创建v123和v124。同样,对于所有向量,例如
v12 should become:
v123 = v12+v3
v124 = v12+v4
v13 should become:
v132 // This should not occur because I already have v123
v134 = v13+v4;
不能考虑v14、v23和v24 因为它被黑了 盒子功能,所以我们拥有的一切 可以使用的手是 v12、v13 和 v34。
v34 should become:
v341 // Cannot occur because we have 134
v342 = v34+v2
重要的是我不要一开始就一步完成所有事情。例如,我可以执行 (4 选择 3) 4C3 并完成它,但我想在每次迭代中一步一步地完成。
如果包含黑匣子功能怎么办?
I'm working on a research problem out of curiosity, and I don't know how to program the logic that I've in mind. Let me explain it to you:
I've four vectors, say for example,
v1 = 1 1 1 1
v2 = 2 2 2 2
v3 = 3 3 3 3
v4 = 4 4 4 4
I want to add them combination-wise. That is,
v12 = v1+v2
v13 = v1+v3
v14 = v1+v4
v23 = v2+v3
v24 = v2+v4
v34 = v3+v4
Till this step it is just fine. The problem/trick is now, at the end of each iteration I give the obtained vectors into a black box function, and it returns only a few of the vectors, say v12, v13 and v34. Now, I want to add each of these vectors one vector from v1, v2, v3, v4 which it hasn't added before. For example, v3 and v4 hasn't been added to v12, so I want to create v123 and v124. Similarly for all the vectors like,
v12 should become:
v123 = v12+v3
v124 = v12+v4
v13 should become:
v132 // This should not occur because I already have v123
v134 = v13+v4;
v14,v23 and v24 cannot be considered
because it was deleted in the black
box function so all we have in our
hands to work with is v12,v13 and v34.
v34 should become:
v341 // Cannot occur because we have 134
v342 = v34+v2
It is important that I do not do it all in one step at the start. Like for example, I can do (4 choose 3) 4C3 and finish it off, but I want to do it step by step at each iteration.
How do do it when the black box function is included?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,这可能会变得更有效率,但我认为这满足了您的需要。
注意:
trim
函数对你的黑匣子进行建模,它使用给定的密钥大小(与最近生成的组合大小相同)从主映射中删除一些条目编辑:
好吧,现在
base
是一个向量,其中包含一个用于键<->向量关系的pair
- 这是常数。最初它被添加到地图中,并且在初始状态下跳过gen_comb
函数,仍然调用trim
来删除一些条目。下一次迭代使用相同的搜索算法,但组合是使用base
的常量集。Okay, here goes, this probably could be made more efficient, but I think this does what you need.
NOTES:
trim
function models your black box which removes some entries from the main map with a given key size (same size as the most recently generated combinations)EDIT:
Okay now
base
is a vector which contains apair
for the key<->vector relationship - this is constant. Initially it is added to the map, and thegen_comb
function is skipped for the initial state,trim
is still called to remove some entries. Next iteration uses the same search algorithm, but the combination is with the constant set ofbase
s.