1
関数から最小/最大値を吐出した座標を取得するにはどうすればよいですか?Rの関数からmin/max値を吐出した座標を取得するには?
私の機能コードは次のとおりです。
myfunct <- function(theta){
for (h in 1:nrow(temp)){
theta_i <- theta[temp[h,1]] #i-th position
theta_j <- theta[temp[h,2]] #j-th position
L1 <- -y[temp[h,2],temp[h,1]] * (theta_i - theta_j) + log(1+exp(theta_i -
theta_j))
}
L2 <- L1 + 0.5 * lambda * norm(theta, "2")^2
return(L2)
}
私の座標は以下のとおりです。
e1 <- c(1,0,0,0,0,0,0,0,0,0)
e2 <- c(0,1,0,0,0,0,0,0,0,0)
e3 <- c(0,0,1,0,0,0,0,0,0,0)
e4 <- c(0,0,0,1,0,0,0,0,0,0)
e5 <- c(0,0,0,0,1,0,0,0,0,0)
e6 <- c(0,0,0,0,0,1,0,0,0,0)
e7 <- c(0,0,0,0,0,0,1,0,0,0)
e8 <- c(0,0,0,0,0,0,0,1,0,0)
e9 <- c(0,0,0,0,0,0,0,0,1,0)
e10 <- c(0,0,0,0,0,0,0,0,0,1)
unitvect <- c(1,1,1,1,1,1,1,1,1,1)
points <- list(e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,unitvect)
私のような "どの" 機能何かを試してみました:
for (i in 1:10){
min <- which(points[[i]] == min(myfunct(points[[i]])
}
が、私は知りませんどの関数を使うかについての構文、関数の最小値を与える座標を変数cに格納したいalled "min" 助けていただければ幸いです。
'result = sapply(points、myfunct)'のすべてのポイントに関数を適用します。そして、 'min_point = points [[which.min(result)]]'となります。 – Gregor
@ Gregorありがとうございます、なぜあなたは1つではなく2つの角括弧を入れているのか教えてください。 – kys92
https://stackoverflow.com/questions/1169456/the-difference-between-and-notations-for-accessing-the-elements-of-a-lis –