2

nlsLMパッケージの R 関数を使用してminpack.LM いますが、次のエラーが発生します。

私はノイズを含む独自の信号を生成するため、信号の生成に使用したのと同じ関数を使用して回帰分析を実行しようとしているすべてのパラメーターを知っています。

問題は、そのnlsLM関数が正常に実行され、正しいパラメーター値を見つけることさえできますが、最終的にそれらを見つけると、エラーが次のように表示されることです。

これ。23、RSS = 14.4698、Par. = 42.6727 0.78112 1 65.2211 15.6065 1

これ。24、RSS = 14.4698、Par. = 42.671 0.781102 1 65.2212 15.6069 1

stats:::nlsModel(formula, mf, start, wts) のエラー: 初期パラメータ推定値での特異勾配行列

そして、私は何をすべきかわかりません。それが何であるか、そしてどのように解決できるかを説明してください!

追加情報:

#This is how i generate my signal (it is convolution of gaussian with exp(-kt)

set.seed(100)

Yexp=sim_str_exp(error=10)

time=Yexp[[1]]

y=Yexp[[2]]

dataset_nls=data.frame(time,y)

start=c(tau1=.5,beta1=.5,exp_A1=.5,gaus_pos=.5,gaus_width=.5,gaus_A=0.5)

lower=c(tau1=0.01,beta1=0.01,exp_A1=0.01,gaus_pos=0.01,gaus_width=0.01,gaus_A=0.01)

upper=c(tau1=100,beta1=1,exp_A1=1,gaus_pos=100,gaus_width=850,gaus_A=1)

#here i do fitting

FIT=nlsLM(y ~ str_exp_model(time,tau1,beta1,exp_A1,gaus_pos,gaus_width,gaus_A),data=dataset_nls,start=start,lower=lower,upper=upper,trace=TRUE,algorithm="LM",na.action=na.pass,control=nls.lm.control(maxiter=200,nprint=1))

#Model_function

str_exp_model<-function(time, tau1,beta1,exp_A1,gaus_pos,gaus_width,gaus_A){
F_gen_V<-vector(length=length(time))

F_gaus_V=vector(length=length(time))
F_exp_V=vector(length=length(time))
for (i in 1:length(time)) {
F_gaus_V[i]=gaus_A*exp(-2.77*((i-gaus_pos)/gaus_width)^2)
F_exp_V[i]=exp_A1*exp(-1*(i/tau1)^beta1)
}

convolve(F_gaus_V, F_exp_V,FALSE)
}

信号生成機能

sim_str_exp<- function(num_points=512,time_scale=512,tau1=45,beta1=.80,exp_A1=1,gaus_pos=65, 

gaus_width=15, gaus_A=1,Y0=0, error=2.0, show_graph=TRUE, norm="False"){

F_gen_V<-vector(length=num_points)
time_gen_V<-vector(length=num_points)
F_gaus_V=vector(length=num_points)
F_exp_V=vector(length=num_points)
ts=time_scale/num_points
sigma=vector(length=num_points)


for (i in 1:num_points) {
F_gaus_V[i]=gaus_A*exp(-2.77*((i*ts-gaus_pos)/gaus_width)^2)
F_exp_V[i]=exp_A1*exp(-1*(i*ts/tau1)^beta1)
time_gen_V[i]=i*ts
}

F_gen_V<-(convolve(F_gaus_V, F_exp_V,FALSE))+Y0

if(norm==TRUE){
F_gen_V=F_gen_V/max(F_gen_V)}
else{;}

error_V=runif(512,-1*error, error)

for(i in 1:num_points){
F_gen_V[i]=error_V[i]/100*F_gen_V[i]+F_gen_V[i]
sigma[i]=(error_V[i]/100*F_gen_V[i])
}

RETURN=list(time=time_gen_V,y=F_gen_V,sigma=sigma)

if (show_graph==TRUE){
plot(RETURN[[1]],RETURN[[2]], type="l", main="Generated signal with noise",xlab="time,        pixel",ylab="Intensity");}
else {;}

return(RETURN)

}
4

1 に答える 1

2

あなたは私たちsim_str_expを見せていないので、この例は完全に再現可能ではありませんが、ここで推測します. 「ノイズで独自の信号を生成する」と言っていますがYexp=sim_str_exp(error=0)、データを生成するために使用しているため、実際にはノイズを追加していないように見えます。(また、最後のステップで報告された RSS は1.37e-28...)

私の推測では、あなたは に記載されている問題に直面していると思います。?nlsこれは、nls()ノイズがゼロの場合にはうまく機能しないということです。これはに文書化されていませ?nlsLMんが、そこに保持されていても驚かないでしょう。

便宜上、参照しているセクションを次に示します?nls

人工的な「ゼロ残差」データに「nls」を使用しないでください。

 The ‘nls’ function uses a relative-offset convergence criterion
 that compares the numerical imprecision at the current parameter
 estimates to the residual sum-of-squares.  This performs well on
 data of the form

                        y = f(x, theta) + eps                       

 (with ‘var(eps) > 0’).  It fails to indicate convergence on data
 of the form

                           y = f(x, theta)                          

 because the criterion amounts to comparing two components of the
 round-off error.  If you wish to test ‘nls’ on artificial data
 please add a noise component, as shown in the example below.

私の仮説が正しければ、ノイズの振幅を 0 よりも大きく設定すると、エラーなしで近似を得ることができるはずです。

于 2013-02-04T15:51:53.930 に答える