dot product of multiple vectors in R to optimize pokemon teams

核能气质少年 提交于 2019-12-11 06:37:49

问题


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:

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

(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)

Test data:

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

回答1:


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.



来源:https://stackoverflow.com/questions/23156549/dot-product-of-multiple-vectors-in-r-to-optimize-pokemon-teams

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!