简体   繁体   English

CVXR:solve() 的问题 - as.vector(data) 中的错误:无法将此 s4 class 强制转换为向量

[英]CVXR: Problem with solve() - Error in as.vector(data): no method for coercing this s4 class to a vector

I'm trying to minimize this function:我试图最小化这个 function:

\min_{\mu} \sum_{t=T}^T \| \min_{\mu} \sum_{t=T}^T \| y_t - \mu_t \| y_t - \mu_t \| 2 + \lambda \sum {t=1}^{T-1} \|mu_{t+1}-\mu_{t}\|_2 2 + \lambda \sum {t=1}^{T-1} \|mu_{t+1}-\mu_{t}\|_2

where: y and mu are p*T matraxis.其中: y 和 mu 是 p*T 矩阵。 Everything compiles well until I use the solve() function.在我使用solve() function之前,一切都编译得很好。

Here is what I coded with y being ap*obs matrix这是我用 y 编码的 ap*obs 矩阵

library(CVXR)

mu <- Variable(p, obs)

# group lasso ----
total_var <- lapply(X = seq_len(obs-1), FUN = function(j) mu[,j+1] - mu[,j])
total_var_norm <- lapply(X = total_var, FUN = cvxr_norm, p=2)
group_lasso <- Reduce(f = sum, x = total_var_norm)

# loss function ---- 
col_diff <- lapply( X = seq_len(obs), FUN = function(j) y[,j] - mu[,j])
col_diff_norm <- lapply( X = col_diff, FUN = cvxr_norm, p=2)
loss <- Reduce(f = sum, x = col_diff_norm)

# convex optimization ----
objective_mu <- loss + lambda * group_lasso
problem_mu <- Minimize(objective_mu)
result_mu <- solve(problem_mu)

All executes well until the result_mu <- solve(problem_mu) .result_mu <- solve(problem_mu)之前,一切都执行得很好。 Where I get the following Error message:我在哪里收到以下错误消息:

> result_mu <- solve(problem_mu)
Error in as.vector(data) : 
  no method for coercing this S4 class to a vector

Everything is fine until this point.到目前为止一切都很好。

I also tried with the following formulation:我还尝试了以下公式:

# group lasso ----
group_lasso <- norm(mu[,2] - mu[,1], type = "2")
for (s in 2:obs-1){
  group_lasso <- group_lasso + norm(mu[,s] - mu[,s+1], type = "2")
}

# loss function ---- 
loss <- norm(y[,1] - mu[,1], type = "2")
for (s in 2:obs){
  loss <- group_lasso_2 + norm(y[,s] - mu[,s], type = "2")
}

with the same objective and problem function.具有相同的目标和问题 function。 And here again I get exactly the same error message at the same point.在这里,我再次在同一点收到完全相同的错误消息。

I can't see at what point the code is wrong... Any pointers?我看不出代码在什么时候出错了......任何指针?
Thanks谢谢

Problem is missing in your code:您的代码中缺少Problem

problem_mu <- Problem(Minimize(objective_mu))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 软件包CVXR:as.vector(data)中的错误:没有用于将此S4类强制转换为向量的方法 - Package CVXR: Error in as.vector(data): no method for coercing this S4 class to a vector CVXR:as.vector(数据)中的错误:没有方法将此 S4 class 强制转换为向量 - CVXR: Error in as.vector(data): no method for coercing this S4 class to a vector as.vector(data) 中的错误:没有将此 S4 class 强制为向量的方法 - Error in as.vector(data) : no method for coercing this S4 class to a vector as.vector(x) 中的错误:没有将此 S4 class 强制为向量的方法 - Error in as.vector(x) : no method for coercing this S4 class to a vector as.vector(data) 中的错误:无法将此 S4 class 强制转换为 R 中的向量 - Error in as.vector(data) : no method for coercing this S4 class to a vector in R as.vector中的APCluster错误(数据):没有用于将此S4类强制转换为向量的方法 - APCluster Error in as.vector(data): no method for coercing this S4 class to a vector 没有将这个 S4 类强制为向量以使用 mclust 的方法 - no method for coercing this S4 class to a vector for utilization of mclust 在 SparkR 中运行相关性:没有将此 S4 类强制转换为向量的方法 - Running correlations in SparkR: no method for coercing this S4 class to a vector getMethod导致“ as.vector(…中的错误” - getMethod resulting in “Error in as.vector(…” As.vector不会将data.frame子集转换为vector - As.vector does not convert data.frame subset to vector
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM