# This function looks for a lambda between 0 and 1 such that fbar + lambda*(fq-fbar) has a larger likelihood than that #of fbar in order to ensure the monotonicity of the algorithm. #Cbar is the vector weights of fbar (outside the quadratic approximation). # Cq is the vector weights of fq the minimizer of the quadratic approximation of -loglikelihood. #likbar is -loglikelihood of fbar. # we need to make some arrangements in order to be able use the function "LoglikFunc" as it is coded. Armijo <- function(Cq,Cbar,valfbar,valfq,likbar,K=K,X=X){ lambda <- 1 sumfq <- sum(Cq) sumfbar <- sum(Cbar) likq <- LoglikFunc(valfq,Cq) likfnew <- likq #if(likfnew == likbar) #lambda <- 1 count <- 0 while( likfnew >= likbar & count <= 2000){ count <- count +1 lambda <- lambda/2 valfnew <- valfbar + lambda *(valfq - valfbar) Cfnew <- Cbar + lambda *(Cq - Cbar) likfnew <- LoglikFunc(valfnew,Cfnew) } lambda }