如何估计两个函数之间具有未知变量的两个函数之间的相关性?

发布于 2025-02-05 15:23:27 字数 517 浏览 1 评论 0 原文

我需要解决此优化问题以估算lambda:

“最小化问题”

我需要找到这两个相关性函数:

f1 <- function(lambda, tau){slope = (1-exp(-lambda*tau))/(lambda*tau)            
      return(slope)}

f2 <- function(lambda, tau){curve = ((1-exp(-lambda*tau))/(lambda*tau))-exp(-lambda*tau) 
 return(curve)}

我知道tau的不同值。假设例如tau = 0.25:现在F1和F2只有一个缺少参数lambda,应估算。但是,当我尝试实现要最小化的 optim()函数时,它不起作用,因为F1和F2不是数字。如何将这种优化问题构建为f1和f2的功能?

非常感谢

I need to solve this optimization problem in order to estimate lambda:

minimization problem

Basically, I need to find the correlation between these two functions:

f1 <- function(lambda, tau){slope = (1-exp(-lambda*tau))/(lambda*tau)            
      return(slope)}

f2 <- function(lambda, tau){curve = ((1-exp(-lambda*tau))/(lambda*tau))-exp(-lambda*tau) 
 return(curve)}

I know the different values of tau. Suppose for example tau = 0.25: now f1 and f2 have only one missing parameter, lambda, which should be estimated. However, when I try to implement the optim() function to be minimized, it does not work since f1 and f2 are not numeric. How can I build this kind of optimization problem mantaining f1 and f2 as functions?

Many thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦醒灬来后我 2025-02-12 15:23:27

如果我正确理解,您正在尝试最大程度地减少lambda值以不同值的F1和F2输出之间的平方相关性。这意味着,对于您要评估的lambda的每个值,您需要以tau值的完整向量进行馈送。这将为lambda的每个值提供一个向量输出,以便可以在lambda的任何单个值下计算两个函数的输出之间的相关性。

为此,我们创建了一个矢量化函数,该函数在lambda 的所有值中,在lambda 的所有值下计算F1和F2之间的平方

f3 <- function(lambda) {
  sapply(lambda, function(l) {
      cor(f1(l, seq(1/12, 10, 1/12)), f2(l, seq(1/12, 10, 1/12)))^2
  })
}

相关相关性,我们只使用优化

optimize(f3, c(0, 100))$minimum
#> [1] 0.6678021

If I am understanding correctly, you are trying to minimise the squared correlation between the output of f1 and f2 at different values of lambda. This means that for each value of lambda you are assessing, you need to feed in the complete vector of tau values. This will give a vector output for each value of lambda so that a correlation between the output from the two functions can be calculated at any single value of lambda.

To do this, we create a vectorized function that takes lambda values and calculates the squared correlation between f1 and f2 at those values of lambda across all values of tau

f3 <- function(lambda) {
  sapply(lambda, function(l) {
      cor(f1(l, seq(1/12, 10, 1/12)), f2(l, seq(1/12, 10, 1/12)))^2
  })
}

To get the optimal value of lambda that minimizes the squared correlation, we just use optimize:

optimize(f3, c(0, 100))$minimum
#> [1] 0.6678021
与他有关 2025-02-12 15:23:27

也许页面底部的示例可以帮助:

他们将时间的向量输入到功能中(这是为给定的屈服曲线固定的),因此您可以计算计算给定lambda的相关性。为了最大程度地减少相关性,请在Lambdas上进行网格搜索。
例如,在您的情况下,

lambda <- 2
cor(f1(lambda, 1:10), f2(lambda, 1:10))

请注意,我假设在1至10年中测量了成熟度。您需要填写适当的值。
要找到导致低相关性的lambda,您可以进行网格搜索。

lambdas <- seq(0.00001, 25, length.out = 1000)
squared.corr <- rep(NA_real_, length(lambdas))

for (i in seq_along(lambdas)) {
    c <- cor(f1(lambdas[i], 1:10),
             f2(lambdas[i], 1:10))
    squared.corr[i] <- c*c
}
lambdas[which.min(c2)]
## [1] 0.490

(我是Gilli,Grosse和Schumann(2010)的作者之一,以最大程度地减少相关性的建议。)

Perhaps the examples at the bottom of the page help: https://search.r-project.org/CRAN/refmans/NMOF/html/NSf.html

They input a vector of times into the functions (which is fixed for a given yield-curve), so you can compute the correlation for a given lambda. To minimize the correlation, do a grid search over the lambdas.
In your case, for instance,

lambda <- 2
cor(f1(lambda, 1:10), f2(lambda, 1:10))

Note that I have assumed maturity measured in years, 1 to 10. You will need to fill in appropriate values.
To find a lambda that leads to a low correlation, you could run a grid search.

lambdas <- seq(0.00001, 25, length.out = 1000)
squared.corr <- rep(NA_real_, length(lambdas))

for (i in seq_along(lambdas)) {
    c <- cor(f1(lambdas[i], 1:10),
             f2(lambdas[i], 1:10))
    squared.corr[i] <- c*c
}
lambdas[which.min(c2)]
## [1] 0.490

(I am one of the authors of Gilli, Grosse and Schumann (2010), on which the suggestion to minimize the correlation is based.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文