![](/img/trans.png)
[英]How to set constraints for non-negativity in parallel factor analysis using the multiway package in R?
[英]Additional non-negativity constraints in nleqslv
我想解決一個非線性方程組
x1 = f(x1, x2)
x2 = g(x1, x2)
服從x1 >= 0
, x2 >= 0
使用nleqslv,我將函數的返回向量設置為如下優化:
y[1] = x[1] - f(x[1], x[2])
y[2] = x[2] - g(x[1], x[2])
y[3] = -x[1]
y[4] = -x[2]
最后兩個應該反映非負面約束。
調用nleqslv產生:
“ Jacobian是單數(1 / condition = 0.0e + 000)(請參閱allowSingular選項)”
並使用allowSingular = T調用將產生:
“公差在'xtol'內的x值”
這是有道理的,因為y [4]不會隨着x [4]的改變而改變(通過構造,根本不響應)。
如何正確執行此操作?
嘗試這個
f <- function(z) {
x <- z^2 # this will force x to be >= 0; other tranformations are possible
y <- numeric(2)
y[1] <- x[1] - f(x[1], x[2])
y[2] <- x[2] - g(x[1], x[2])
y
}
然后使用nleqslv
求解函數f
並為轉換后的變量指定適當的起始值。 因此,如果您的起始值現在在xstart
使用
zstart <- sqrt(xstart)
對於已轉化的問題。 為了得到正確單位的求解結果,只需對nleqslv
給出的結果使用^2
nleqslv
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.