margins <- list() garch_models <- list() for (i in 1:ncol(returns)) { garch_fit <- ugarchspec(mean.model = list(armaOrder = c(1, 1)), var.model = list(garchOrder = c(1, 1)), data = returns[, i], fit.control = list(stationarity = 1)) garch_model <- ugarchfit(spec = garch_fit, data = returns[, i]) garch_models[[i]] <- garch_model dist_fit <- fitdistr(as.numeric(returns[, i]), densfun = "lognormal") margins[[i]] <- list(distr = "lnorm", params = dist_fit$estimate) } r代码报错: Error in .local(variance.model, mean.model, distribution.model, start.pars, : unused arguments (var.model = list(c(1, 1)), data = c(-0.0273787289305405, -0.00601957893571292, 0.00376652523108056, -0.0258963489968176, 0.00921661448593447, 0.0293806919632189, -0.00521027200022228, 0.0111318258629431, 0.0468554021261953, 0, 0.00211047123602093, 0.0338546918582274, 0.00542006470595524, -0.0246250672002226, 0.0144382351254055, -0.000682834605118643, -0.0305155611202679, -0.0106195551544515, -0.0223110889101186, -0.00657177027901046, 0.028882859189129, -0.00142451769916985, 0.00142451769916985, 0.0349685964573228, -0.0385337027921766, -0.0802808283485552, -0.029852930055962, -0.0701897731960841, 0.00256303750108344, 0.0185972945076474, 0.00501251976461248, 0.0376169028282138, 0.0119666212313421, 0.00158480422246754, -0.0281030277747965, -0.0189072435209265, -0.000830229392394521, -0.00750316751799751, -0.00755989091406928, 0.0200340492008868, -0.00414076137642549, 0.00496687564700782, -0.00165291157025038, -0.00497511271516782, -0.000831610247014503, -0.0083
时间: 2023-10-02 11:03:34 浏览: 92
这段代码的错误信息提示是“未使用的参数”,具体来说是在调用 `ugarchspec()` 函数时,该函数没有使用 `var.model` 和 `data` 这两个参数。这可能是因为 `ugarchspec()` 函数没有定义这两个参数,或者是因为参数名称写错了。你可以检查一下 `ugarchspec()` 函数的参数列表,看看是否有这两个参数,并且检查一下参数名称是否正确。同时,你也可以检查一下输入的数据是否正确,是否符合 `ugarchspec()` 函数的要求。
相关问题
pairs(data, lower.panel = function(x, y) { points(x, y, pch = 19, cex = 0.5, col = "#3C9668") abline(lm(y ~ x), col = "red") }, diag.panel = function(x) { hist(x,col = "#D8EAF6",probability = TRUE,axes = FALSE,main = "",breaks = "FD") }, upper.panel = function(x, y) { corr_text <- round(cor(x, y), 2) symbol_size <- abs(corr_text) * 5 color_scale <- colorRampPalette(c("#F09576","white","#175A9E")) # 颜色比例尺 symbol_color <- color_scale(5 + corr_text * 5) #symbol_color <- ifelse(corr_text >= 0, "#F09576","#175A9E") symbols(1, 1, circles = symbol_size, inches = FALSE, bg = symbol_color) text(mean(x), mean(y), corr_text, cex = symbol_size*0.7, font = 1) }, labels = c("FBD", "VC", "EO","OF","DP","VC-FBD","EO-VC","OF-EO","DP-OF","DP-EO"), font.labels = list(cex = 1.5))又出现Error in plot.new() : figure margins too large的问题。怎么解决
这个错误通常是由于图形边距设置过大导致的。你可以尝试调整 `mar` 参数的值,来缩小图形边距。例如将 `mar` 设置为 `c(5, 4, 4, 2) + 0.1`,如果还是不行,可以进一步调整参数值。另外,你也可以将 `oma` 参数设置为较小的值,来进一步缩小图形的边距。例如:
```
pairs(data,
lower.panel = function(x, y) {
points(x, y, pch = 19, cex = 0.5, col = "#3C9668")
abline(lm(y ~ x), col = "red")
},
diag.panel = function(x) {
hist(x,col = "#D8EAF6",probability = TRUE,axes = FALSE,main = "",breaks = "FD")
},
upper.panel = function(x, y) {
corr_text <- round(cor(x, y), 2)
symbol_size <- abs(corr_text) * 5
color_scale <- colorRampPalette(c("#F09576","white","#175A9E")) # 颜色比例尺
symbol_color <- color_scale(5 + corr_text * 5) #symbol_color <- ifelse(corr_text >= 0, "#F09576","#175A9E")
symbols(1, 1, circles = symbol_size, inches = FALSE, bg = symbol_color)
text(mean(x), mean(y), corr_text, cex = symbol_size*0.7, font = 1)
},
labels = c("FBD", "VC", "EO","OF","DP","VC-FBD","EO-VC","OF-EO","DP-OF","DP-EO"),
font.labels = list(cex = 1.5),
mar = c(5, 4, 4, 2) + 0.1,
oma = c(0.5, 0.5, 0.5, 0.5)
)
```
你可以根据实际情况适当调整参数值。
def svm_loss(x, y): N = x.shape[0] correct_class_scores = x[np.arange(N), y] margins = np.maximum(0, x - correct_class_scores[:, np.newaxis] + 1.0) margins[np.arange(N), y] = 0 loss = np.sum(margins) / N num_pos = np.sum(margins > 0, axis=1) dx = np.zeros_like(x) dx[margins > 0] = 1 dx[np.arange(N), y] -= num_pos dx /= N return loss, dx def softmax_loss(x, y): probs = np.exp(x - np.max(x, axis=1, keepdims=True)) probs /= np.sum(probs, axis=1, keepdims=True) N = x.shape[0] loss = -np.sum(np.log(probs[np.arange(N), y])) / N dx = probs.copy() dx[np.arange(N), y] -= 1 dx /= N return loss, dx
这是两个常用的损失函数,SVM损失和Softmax损失。它们通常用于多分类问题中,其中$x$是一个矩阵,每一行代表一个样本的得分,$y$是一个向量,表示每个样本的真实标签。
SVM损失函数的实现中,首先计算出正确标签的得分(correct_class_scores),然后计算出每个样本的margin(间隔),$margins = max(0, x - correct_class_scores[:, np.newaxis] + 1.0)$。如果margin大于0,则样本被分类错误,贡献到损失函数中。将正确标签的margin设为0,然后将所有margin求和并除以样本个数,得到平均SVM损失。同时,还需要计算出输入$x$的梯度$dx$,$dx$的值为1或0,如果margin>0,则为1,否则为0。对于正确分类的那个类,需要将所有贡献给该类的梯度和减去$dx$中正值的个数,因为每个正值都对该类的梯度有贡献。
Softmax损失函数的实现中,首先将每个样本的得分减去该行得分的最大值,以防止指数爆炸,然后将得分转换成概率。计算交叉熵损失,$loss = -sum(log(probs[range(N), y])) / N$,其中probs是概率矩阵,$probs[i, j]$表示第$i$个样本被分为第$j$个类的概率。最后,计算输入$x$的梯度$dx$,$dx$的值为每个样本的概率减去1,然后除以样本个数。对于正确分类的那个类,由于$y$只有一个元素,因此只需要将对应位置的概率减去1即可。
需要注意的是,这里的实现是针对单个样本的输入$x$和输出$dout$,如果使用批量输入,则需要对每个样本进行计算。
阅读全文