Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. ! _________________________________________________________________________________ !
  2. ! _________________CODE SEEKS BEST FIT FOR Gamma MAXIMUM LIKELIHOOD _____________ !
  3. ! _________________________________________________________________________________ !
  4. ! _________________Correct solution k=19.288624285110700, Thetha=4.4650184____________ !
  5. program Best_Fit
  6. implicit none
  7. integer, parameter :: ikind=selected_real_kind(p=15)
  8. ! ________________Number of specimens_______________________________________________!
  9. integer :: nospec=26
  10. real (kind=ikind):: x1, TOL
  11. real (kind=ikind)::Ak, Bk, Ck, Dk, k1, k2
  12. real (kind=ikind)::AThe, BThe, CThe, DThe, Thet1, Thet2
  13. real, PARAMETER :: R=1.61803399
  14. integer :: i, j, jm, iio, n=50 ! n iteration number
  15. real (kind=ikind) :: gres1
  16. real, dimension(26) :: ulist1
  17. real (kind=ikind), dimension(4) :: klist,Thelist
  18. real (kind=8), dimension(4,4) :: LLL
  19. real (kind=ikind) :: pdfx, mpdf
  20. ulist1 = (/45, 58, 59, 60, 65, 67, 68, 71, 72, 82, 85, 87, 88, 90, 91, 92, 94, 97, 102, 103, 104, 104, 104, 113, 120, 126/)
  21. !______Those above are specimens ulist1___________________!
  22. ! __________Thet1, Thet2 ___Range for Theta___
  23. Thet1=1.
  24. Thet2=12.
  25. ! __________k1, k2 ___range for k___
  26. k1=1.
  27. k2=60.
  28. !__________________________________________
  29. TOL=1.d-6
  30.  
  31. !____________________________inital searching range _________________!
  32. !At any given time we will keep trace of 4 k points: Ak, Bk, Ck, Dk
  33. Ak=MIN(k1,k2)
  34. Dk=MAX(k1,k2)
  35. Bk=Dk-(Dk-Ak)/R
  36. Ck=Ak+(Dk-Ak)/R
  37. klist =(/Ak, Bk, Ck, Dk/)
  38. print *,' klist= ',klist
  39. !!!______________________________________________________________-!
  40. !At any given time we will keep trace of 4 The points: AThe, BThe, CThe, DThe
  41. AThe=MIN(Thet1,Thet2)
  42. DThe=MAX(Thet1,Thet2)
  43. BThe=DThe-(DThe-AThe)/R
  44. CThe=AThe+(DThe-AThe)/R
  45. Thelist=(/AThe, BThe, CThe, DThe/)
  46. print *,' Thelist= ',Thelist
  47. !!!______________________________________________________________-!
  48. mpdf=0._ikind
  49. do jm=1,4,1 !____Thelist
  50. do j=1, 4,1 !____klist
  51. do i=1, nospec,1
  52. x1=ulist1(i)
  53. call gammapdf(x1, Thelist(jm), klist(j), gres1)
  54. pdfx=gres1
  55. mpdf=mpdf+log10(pdfx)
  56. print *, 'x=', x1, 'Log10(Gamma_pdf)=', mpdf, 'pdf:',pdfx
  57. end do
  58.  
  59. LLL(jm,j)=mpdf
  60. print *, 'Log10(Gamma_pdf)=', mpdf, 'LLL(jm,j)=',LLL(jm,j)
  61. mpdf=0._ikind
  62. end do
  63. end do
  64. !______________________________________________________________
  65. !____________________________iterations start here _________________!
  66.  
  67. !____________________________iterations start here _________________!
  68. do iio=1,n,1
  69. !______________________________________________________________
  70.  
  71. !______________________________________________________________
  72. IF(LLL(2,2)<LLL(2,3)) THEN
  73. print *,' LLL= ',LLL
  74. klist(1)=klist(2)
  75. klist(2)=klist(4)-(klist(4)-klist(1))/R
  76. klist(3)=klist(1)+(klist(4)-klist(1))/R
  77. print *,'klist= ',klist
  78. ELSE
  79. klist(4)=klist(3)
  80. klist(2)=klist(4)-(klist(4)-klist(1))/R
  81. klist(3)=klist(1)+(klist(4)-klist(1))/R
  82. print *,'klist= ',klist
  83. ENDIF
  84. !______________________________________________________________
  85. IF(LLL(2,2)<LLL(3,2)) THEN
  86. print *,' LLL= ',LLL
  87. Thelist(1)=Thelist(2)
  88. Thelist(2)=Thelist(4)-(Thelist(4)-Thelist(1))/R
  89. Thelist(3)=Thelist(1)+(Thelist(4)-Thelist(1))/R
  90. print *,'Thelist= ',Thelist
  91. ELSE
  92. Thelist(4)=Thelist(3)
  93. Thelist(2)=Thelist(4)-(Thelist(4)-Thelist(1))/R
  94. Thelist(3)=Thelist(1)+(Thelist(4)-Thelist(1))/R
  95. print *,'Thelist= ',Thelist
  96. ENDIF
  97. !______________________________________________________________
  98.  
  99. mpdf=0._ikind
  100. do jm=1,4,1 !____Thelist
  101. do j=1, 4,1 !____klist
  102. do i=1, nospec,1
  103. x1=ulist1(i)
  104. call gammapdf(x1, Thelist(jm), klist(j), gres1)
  105. pdfx=gres1
  106. mpdf=mpdf+log10(pdfx)
  107. print *, 'x=', x1, 'Log10(Gamma_pdf)=', mpdf, 'pdf:',pdfx
  108. end do
  109. LLL(jm,j)=mpdf
  110. print *, 'Log10(Gamma_pdf)=', mpdf, 'LLL(jm,j)=',LLL(jm,j)
  111. mpdf=0._ikind
  112. end do
  113. end do
  114. !_______ print LLL matrix_____________________________________
  115.  
  116. do jm=1,4
  117. print *,(LLL(jm,j),j=1,4)
  118. end do
  119. !______LLL matrix printed
  120. !_______ iterations n continues here_________________________
  121. write(*,*) "iteration iio=",iio
  122. print *,' klist= ',klist
  123. print *,' Thelist= ',Thelist
  124. enddo
  125. stop
  126. !_____________________________________________
  127. !_____________________________________________
  128. contains
  129. subroutine gammapdf (a, b, c, gam1)
  130. integer, parameter :: ikind=selected_real_kind(p=15)
  131. real (kind=ikind), intent(in) :: a, b, c
  132. real (kind=ikind), intent(out):: gam1
  133. gam1 = 1/(Gamma_mb(c)*b**c)*a**(c-1._ikind)*exp(-1._ikind*(a/b))
  134. return
  135. end subroutine gammapdf
  136.  
  137.  
  138. !_____________________________________________
  139. real(kind=8) Function Gamma_mb(xx)
  140. real(kind=8):: xx,cof(6),stp,half,one,fpf,x2,tmp,ser
  141. integer::j2
  142. DATA cof,stp /76.18009173d0,-86.50532033d0,24.01409822d0,-1.231739516d0,0.120858003d-2,-0.536382d-5,2.50662827465d0/
  143. DATA half,one,fpf /0.5d0,1.0d0,5.5d0/
  144. x2=xx-one
  145. tmp=x2+fpf
  146. tmp=(x2+half)*DLOG(tmp)-tmp
  147. ser=one
  148. do j2=1,6
  149. x2=x2+one
  150. ser=ser+cof(j2)/x2
  151. end do
  152. Gamma_mb = DEXP(tmp+DLOG(stp*ser))
  153. return
  154. end Function Gamma_mb
  155. !_____________________________________________
  156. end program Best_Fit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement