53105e502254f1b8c0197b4b4ee0d45ce28959ec
[unres.git] / source / maxlik / src_CSA / minsumsl.f
1       subroutine minsumsl(nvar,x,minval)
2       implicit real*8 (a-h,o-z)
3       include 'DIMENSIONS'
4       parameter (maxvar=maxene+3*nnbase)
5       parameter (liv=60,lv=(77+maxvar*(maxvar+17)/2)) 
6 *********************************************************************
7 * OPTIMIZE sets up SUMSL or DFP and provides a simple interface for *
8 * the calling subprogram.                                           *     
9 * when d(i)=1.0, then v(35) is the length of the initial step,      *     
10 * calculated in the usual pythagorean way.                          *     
11 * absolute convergence occurs when the function is within v(31) of  *     
12 * zero. unless you know the minimum value in advance, abs convg     *     
13 * is probably not useful.                                           *     
14 * relative convergence is when the model predicts that the function *   
15 * will decrease by less than v(32)*abs(fun).                        *   
16 *********************************************************************
17       dimension iv(liv)                                               
18       real*8 minval,x(nvar),d(maxvar),v(1:lv)                     
19       external funclik,grad,fdum
20       integer idum(1)
21       double precision rdum(1)
22       double precision urparm(maxT)
23       double precision g(maxvar)
24       call deflt(2,iv,liv,lv,v)                                         
25 * 12 means fresh start, dont call deflt                                 
26       iv(1)=12                                                          
27 * max num of fun calls                                                  
28       maxfun=1000
29       iv(17)=maxfun
30 * max num of iterations                                                 
31       maxit=50
32       iv(18)=maxit
33 * controls output                                                       
34       iv(19)=1                                                          
35 * selects output unit                                                   
36       iv(21)=2
37 * 1 means to print out result                                           
38       iv(22)=1                                                          
39 * 1 means to print out summary stats                                    
40       iv(23)=1                                                          
41 * 1 means to print initial x and d                                      
42       iv(24)=1                                                          
43 * min val for v(radfac) default is 0.1                                  
44       v(24)=0.01D0                                                       
45 * max val for v(radfac) default is 4.0                                  
46       v(25)=2.0D0                                                       
47 c     v(25)=4.0D0                                                       
48 * check false conv if (act fnctn decrease) .lt. v(26)*(exp decrease)    
49 * the sumsl default is 0.1                                              
50       v(26)=0.001D0
51 * false conv if (act fnctn decrease) .lt. v(34)                         
52 * the sumsl default is 100*machep                                       
53       v(34)=v(34)/100.0D0                                               
54 * absolute convergence                                                  
55       tolf=1.0D-4
56       v(31)=tolf
57 * relative convergence                                                  
58       rtolf=1.0D-12
59       v(32)=rtolf
60 * controls initial step size                                            
61        v(35)=1.0D-6                                                    
62 * large vals of d correspond to small components of step                
63       do 20 i=1,nvar
64          d(i)=1.0D0                                                     
65 20    continue
66
67       nf=0
68       call funclik(nvar,x,nf,f,idum,urparm,fdum)  
69       write (2,'(a,1pe17.10)') 'Initial function value:',f
70       call grad(nvar,x,nf,g,idum,urparm,fdum)
71       write (2,*) "Initial gradient"
72       do i=1,nvar
73         write (2,'(i5,e15.5)') i,g(i)
74       enddo
75 c minimize the log-likelihood function
76       print *,"iv1",iv(1)
77       call sumsl(nvar,d,x,funclik,grad,iv,liv,lv,v,idum,urparm,fdum)
78       minval=v(10)                                                      
79       write (2,*)
80       write (2,'(a,i4)') 'SUMSL return code:',iv(1)
81       write (2,'(a,1pe17.10)') 'Final function value:',minval
82 c      print *,"exiting minsumsl"
83       return  
84       end  
85 c---------------------------------------------------------------------
86