【问题标题】:How to get the value of `t` so that my function `h(t)=epsilon` for a fixed `epsilon`?如何获取 `t` 的值,以便我的函数 `h(t)=epsilon` 获得固定的 `epsilon`?
【发布时间】:2022-11-29 04:35:37
【问题描述】:

在这个问题之后:

如果我生成了m=10随机向量x_0均匀分布在随机矩阵GOE的球体和特征向量上:

#make this example reproducible
set.seed(101)
n <- 100
#Sample GOE random matrix
A <- matrix(rnorm(n*n, mean=0, sd=1), n, n) 
G <- (A + t(A))/sqrt(2*n)
ev <- eigen(G)
l <- ev$values
v <- ev$vectors

#size of multivariate distribution
mean <- rep(0, n) 
var <- diag(n)
#simulate bivariate normal distribution
initial <- MASS::mvrnorm(n=10, mu=mean, Sigma=var)
#normalized the first possible initial value, the initial data uniformly distributed on the sphere
x_01 <- initial[1, ]/norm(initial[1, ], type="2")
x_02 <- initial[2, ]/norm(initial[2, ], type="2")
x_03 <- initial[3, ]/norm(initial[3, ], type="2")
x_04 <- initial[4, ]/norm(initial[4, ], type="2")
x_05 <- initial[5, ]/norm(initial[5, ], type="2")

(有没有更好的方法直接得到十个归一化随机向量x_0?)

定义一个函数h_1(t)

这个函数的代码是

h1t_modefied <- function(t, x_0) {
  h10 <- c(x_0 %*% v[, n])
  numer <- abs(h10) * exp(-2*l[n] * t)
  denom <- vapply(t, function(.t) {
    sum((x_0 %*% v)^2 * exp(-4*l * .t))
  }, numeric(1L))
  numer/sqrt(denom)
}


#> h1t_modefied(1,x_01)
[1] 0.5734668

> h1t_modefied(1,x_02)
[1] 0.1673308

修复epsilon=0.01,我想计算t(由t_epsilon表示)的值,以便h_1(t)= epsilon 用于不同初始值随机向量x_01x_02等。

我尝试使用 uniroot 函数,但它不起作用:

#set epsilon=0.01
ep<-0.01
uniroot(h1t_modefied-ep, c(0,10))

我最不想做的就是对x_0的100个不同的初始值得到100个不同的初始值t_epsilon,然后绘制t_epsilon的直方图。

【问题讨论】:

    标签: r


    【解决方案1】:

    uniroot 找到你的函数等于 0 的地方,所以你需要一个包装函数来从你的函数输出中减去 epsilon:

    find_t <- function(x, epsilon = 0.01, range = c(-50, 50)) {
      uniroot(function(t) h1t_modefied(t, x) - epsilon, range)$root
    }
    
    xmats <- list(x_01 = x_01, x_02 = x_02, x_03 = x_03, x_04 = x_04, x_05 = x_05)
    
    lapply(xmats, find_t)
    #> $x_01
    #> [1] -0.5149958
    #> 
    #> $x_02
    #> [1] -0.2521651
    #> 
    #> $x_03
    #> [1] -0.02756984
    #> 
    #> $x_04
    #> [1] -0.4903251
    #> 
    #> $x_05
    #> [1] -0.3473337
    

    我们可以看到,这给出了函数输出低于 epsilon 的点的近似值:

    h1t_modefied(-0.5149958, x_01)
    #> [1] 0.009999542
    

    【讨论】:

      猜你喜欢
      • 2011-02-06
      • 2012-06-08
      • 2012-03-20
      • 1970-01-01
      • 2012-03-11
      • 1970-01-01
      • 2017-03-07
      • 1970-01-01
      • 2010-10-09
      相关资源
      最近更新 更多