R中多个向量的点积以优化宠物小精灵团队 [英] dot product of multiple vectors in R to optimize pokemon teams

查看:140
本文介绍了R中多个向量的点积以优化宠物小精灵团队的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的计划是创建一种选择最佳口袋妖怪队伍的方法.我不确定如何从16个防御向量与12个向量的点积中创建12个向量的所有可能组合的列表,然后对atk向量执行相同的操作.我的另一个问题是找到一种方法来汇总每个团队中宠物小精灵的总价值.我希望我的结果看起来像这样的矩阵:

My plan is to create a way to pick the best pokemon team. Im not sure how to create a list of all possible combinations of 12 vectors from the 16 defense vectors with the dot product of the 12 vectors and then do the same thing for the atk vectors. My other problem is finding a way to sum the Total value for the pokemon in each team. I want my results to look something like this matrix:

团队........总统计数据...... Atk得分..... .....................国防得分

Team............TotalStats..............Atk Score...............................................Def Score

(6个宠物小精灵)(6个宠物小精灵的统计总和)(每个atk矢量的点积)(每个def矢量的点积)

(6 pokemon) (sum of stats of 6 pokemon) (dot product of each atk vector) (dot product of each def vector)

这些向量代表每种口袋妖怪之间的攻击和防御互动

These vectors represent attack and defense interactions between each pokemon type

Normal.def=c(1,2,1,1,1,1,1,0,1,1,1,1,1,1,1)
Fire.def=c(1,1,1,1,2,2,.5,1,.5,2,.5,1,1,1,1)
Water.def=c(1,1,1,1,1,1,1,1,.5,.5,2,2,1,.5,1)
Electric.def=c(1,1,.5,1,2,1,1,1,1,1,1,.5,1,1,1)
Grass.def=c(1,1,2,2,.5,1,2,1,2,.5,.5,.5,1,2,1)
Ice.def=c(1,2,1,1,1,2,1,1,2,1,1,1,1,.5,1)
Fighting.def=c(1,1,2,1,1,.5,.5,1,1,1,1,1,2,1,1)
Poison.def=c(1,.5,1,.5,2,1,2,1,1,1,.5,1,2,1,1)
Ground.def=c(1,1,1,.5,1,.5,1,1,1,2,2,0,1,2,1)
Flying.def=c(1,.5,1,1,0,2,.5,1,1,1,.5,2,1,2,1)
Pyschic.def=c(1,.5,1,1,1,1,2,0,1,1,1,1,.5,1,1)
Bug.def=c(1,.5,2,2,.5,2,1,1,2,1,.5,1,1,1,1)
Rock.def=c(.5,2,.5,.5,2,1,1,1,.5,2,2,1,1,1,1)
Ghost.def=c(0,0,1,.5,1,1,.5,2,1,1,1,1,1,1,1)
Dragon.def=c(1,1,1,1,1,1,1,1,.5,.5,.5,.5,1,2,2)
Null.def=c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)

Normal.atk=c(1,1,1,1,1,.5,1,0,1,1,1,1,1,1,1)
Fire.atk=c(1,1,1,1,1,.5,2,1,.5,.5,2,1,1,2,.5)
Water.atk=c(1,1,1,1,2,2,1,1,2,.5,.5,1,1,1,.5)
Electric.atk=c(1,1,2,1,0,1,1,1,1,2,.5,.5,1,1,.5)
Grass.atk=c(1,1,.5,.5,2,2,.5,1,.5,2,.5,1,1,1,.5)
Ice.atk=c(1,1,2,1,2,1,1,1,1,.5,2,1,1,.5,2)
Fighting.atk=c(2,1,.5,.5,1,2,.5,0,1,1,1,1,.5,2,1)
Poison.atk=c(1,1,1,.5,.5,.5,2,.5,1,1,2,1,1,1,1)
Ground.atk=c(1,1,0,2,1,2,.5,1,2,1,.5,2,1,1,1)
Flying.atk=c(1,2,1,1,1,.5,2,1,1,1,2,.5,1,1,1)
Pyschic.atk=c(1,2,1,2,1,1,1,1,1,1,1,1,.5,1,1)
Bug.atk=c(1,.5,.5,2,1,1,1,.5,.5,1,2,1,2,1,1)
Rock.atk=c(1,.5,2,1,.5,1,2,1,2,1,1,1,1,2,1)
Ghost.atk=c(0,1,1,1,1,1,1,2,1,1,1,1,0,1,1)
Dragon.atk=c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,2)
Null.atk=c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)

测试数据:

Number  Pokemon     Type_1   Type_2   Total
3       Venusaur    Grass    Poison   425
6       Charizard   Fire     Flying   425
9       Blastoise   Water    Null     425
12      Butterfree  Bug      Flying   305
15      Beedrill    Bug      Poison   305
18      Pidgeot     Normal   Flying   399
20      Raticate    Normal   Null     343
22      Fearow      Normal   Flying   381

推荐答案

也许是吗? 通过使用defmat<-cbind(all_your_vectors)

Maybe this? Make your defense vectors into a matrix by using defmat<-cbind(all_your_vectors)

library(pracma)

defcomb <- combs(1:16,12) # there are 1820 such combinations

defdot <- vector()
for (j in 1:1820) defdot[j]<- defmat[,c(defcomb[j,])] %*%  defmat[,c(defcomb[j,])]

由于不清楚要做什么,我在其中用自己的点缀了子集.

Where I dotted the subset with itself since it isn't clear what you want to do.

这篇关于R中多个向量的点积以优化宠物小精灵团队的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆