Logical issue

  • Follow


Hi there,
I am getting hard time because of this logical error. There is no syntax error in the code but I am not getting right output. Can some one give the idea whats going on in the following code?


program  likelihood
IMPLICIT NONE
REAL :: ALPHA, BETA, DIST1,DIST2, PROB1,PROB2,dist11, dist22
REAL:: LOGLIKE, RHO,u1,u2
INTEGER ::p,q, T, i,j,k,l, INFPERIOD, POPULATION, NOSAMPLE, J1,k1, count, my_cnt
REAL, DIMENSION(1:625):: X 
REAL, DIMENSION(1:625):: Y 
INTEGER, DIMENSION(1:625):: INFTIME

!!!!!!!!!!!!!change of random seed!!!!!!!!!!!!

  INTEGER,ALLOCATABLE,DIMENSION(:) :: seed
  INTEGER,DIMENSION(8) :: time1
  INTEGER :: size

  CALL RANDOM_SEED(size=size)
  ALLOCATE (seed(size))
  CALL DATE_AND_TIME(values=time1)
  seed = 60*time1(6)+60*time1(7)+time1(8)
  CALL RANDOM_SEED(put=seed)


!!!!!!!!!!!!!!!!!!!!!!!!!required initial values !!!!!!!!!!!!!!!

ALPHA = 0.5
BETA = 2.0
INFPERIOD = 3
POPULATION = 625
RHO = 0.1
NOSAMPLE = int(RHO*POPULATION) 

!print *, NOSAMPLE



OPEN(10, FILE = 'epidemicSIR.txt', FORM = 'FORMATTED')
DO l = 1,625
   READ(10,*,END = 200) X(l), Y(l), INFTIME(l)
   !WRITE(*,*)X(l),Y(l), INFTIME(l)
ENDDO
close(10)
200 CONTINUE

open(10, file = 'epidatasamp.txt')

LOGLIKE = 0.0

!!!!!!!!!! time loop!!!!!

DO T=1,10
 
 count = 0
  my_cnt = 0
 
!!!!!!!! total number of infected individuals at each time point!!!!!!!!  

 DO i=1,POPULATION 
 
     ! if(inftime(i)/=0 .and. inftime(i)==T)then
       if(inftime(i)==T)then
         count = count+1
      endif
     ! print *, count
   
      IF(INFTIME(i)==0 .OR. T < (INFTIME(i)-1)) THEN
         DIST1 = 0.0
         do j = 1, NOSAMPLE

            if(my_cnt .le. rho*count)then       !!!!!! random sampling from the infected population in the given proportion!!!!
            
               call random_number(u1)
               J1 = 1+int(population*u1)
               if(inftime(J1)/=0)then
             
                  IF(T >= INFTIME(J1) .AND. INFTIME(J1)+infperiod >T)THEN 
                     DIST1 = DIST1 + sqrt((X(i) - X(J1))**2 + (Y(i) - Y(J1))**2)**(-BETA)
                     write(10,*) X(J1),Y(J1), INFTIME(J1)
                     my_cnt = my_cnt+1
                       
                  ENDIF
             
               endif
            endif
         enddo
         dist11 = (dist1*count)/my_cnt       !!!!(inverse weighting by the weighting factors )!!!!!
        ! print *, count, my_cnt
         PROB1 = 1 - exp(-ALPHA * dist11)
         LOGLIKE = LOGLIKE + log(1 - PROB1)
           
       
      ENDIF
   
      
       IF(INFTIME(i) .EQ. (T+1)) THEN
          DIST2 = 0.0
          do k = 1, NOSAMPLE
             
          if(my_cnt .le.rho*count)then !!!!!! random sampling from the infected population in the given proportion!!!!
            
                call random_number(u2)
                k1 = 1+int(population*u2)         
         
                if(inftime(k1)/=0)then
                   
                   IF(T >= INFTIME(k1) .AND.INFTIME(k1)+infperiod > T) THEN
                      DIST2 = DIST2 + sqrt((X(i) - X(k1))**2 + (Y(i) - Y(k1))**2)**(-BETA)
                      write(10,*) X(k1),Y(k1), INFTIME(k1)
                      my_cnt = my_cnt+1
                           
                    ENDIF
                 
                 endif
              endif
           enddo
           dist22 = (dist2*count)/my_cnt      !!!!(inverse weighting by the weighting factors )!!!!!
                 
           PROB2 = 1 - exp(-ALPHA* dist22)
           LOGLIKE = LOGLIKE + log(PROB2)
            
               
   
        ENDIF
     
     enddo
      
      write(*,*)dist1,dist11, dist2, dist22, prob1, prob2,count, my_cnt
  
   ENDDO
   

   close(10)
 end program likelihood



I guess this could be the logical issue of using the do and if loop several times.

Thanks 
0
Reply gyanendra.pokharel (31) 7/31/2012 6:02:04 PM

On Aug 1, 4:02=A0am, gyanendra.pokharel <gyanendra.pokha...@gmail.com>
wrote:
> Hi there,
> I am getting hard time because of this logical error. There is no syntax =
error in the code but I am not getting right output. Can some one give the =
idea whats going on in the following code?
>
> program =A0likelihood
> IMPLICIT NONE
> REAL :: ALPHA, BETA, DIST1,DIST2, PROB1,PROB2,dist11, dist22
> REAL:: LOGLIKE, RHO,u1,u2
> INTEGER ::p,q, T, i,j,k,l, INFPERIOD, POPULATION, NOSAMPLE, J1,k1, count,=
 my_cnt
> REAL, DIMENSION(1:625):: X
> REAL, DIMENSION(1:625):: Y
> INTEGER, DIMENSION(1:625):: INFTIME
>
> !!!!!!!!!!!!!change of random seed!!!!!!!!!!!!
>
> =A0 INTEGER,ALLOCATABLE,DIMENSION(:) :: seed
> =A0 INTEGER,DIMENSION(8) :: time1
> =A0 INTEGER :: size
>
> =A0 CALL RANDOM_SEED(size=3Dsize)
> =A0 ALLOCATE (seed(size))
> =A0 CALL DATE_AND_TIME(values=3Dtime1)
> =A0 seed =3D 60*time1(6)+60*time1(7)+time1(8)
> =A0 CALL RANDOM_SEED(put=3Dseed)
>
> !!!!!!!!!!!!!!!!!!!!!!!!!required initial values !!!!!!!!!!!!!!!
>
> ALPHA =3D 0.5
> BETA =3D 2.0
> INFPERIOD =3D 3
> POPULATION =3D 625
> RHO =3D 0.1
> NOSAMPLE =3D int(RHO*POPULATION)
>
> !print *, NOSAMPLE
>
> OPEN(10, FILE =3D 'epidemicSIR.txt', FORM =3D 'FORMATTED')
> DO l =3D 1,625
> =A0 =A0READ(10,*,END =3D 200) X(l), Y(l), INFTIME(l)
> =A0 =A0!WRITE(*,*)X(l),Y(l), INFTIME(l)
> ENDDO
> close(10)
> 200 CONTINUE

Comment:
You don't know how many data have actually been read in.
(Although I notice that you have a

> open(10, file =3D 'epidatasamp.txt')
>
> LOGLIKE =3D 0.0
>
> !!!!!!!!!! time loop!!!!!
>
> DO T=3D1,10
>
> =A0count =3D 0
> =A0 my_cnt =3D 0
>
> !!!!!!!! total number of infected individuals at each time point!!!!!!!!
>
> =A0DO i=3D1,POPULATION
>
> =A0 =A0 =A0! if(inftime(i)/=3D0 .and. inftime(i)=3D=3DT)then
> =A0 =A0 =A0 =A0if(inftime(i)=3D=3DT)then
> =A0 =A0 =A0 =A0 =A0count =3D count+1
> =A0 =A0 =A0 endif
> =A0 =A0 =A0! print *, count
>
> =A0 =A0 =A0 IF(INFTIME(i)=3D=3D0 .OR. T < (INFTIME(i)-1)) THEN
> =A0 =A0 =A0 =A0 =A0DIST1 =3D 0.0
> =A0 =A0 =A0 =A0 =A0do j =3D 1, NOSAMPLE
>
> =A0 =A0 =A0 =A0 =A0 =A0 if(my_cnt .le. rho*count)then =A0 =A0 =A0 !!!!!! =
random sampling from the infected population in the given proportion!!!!
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0call random_number(u1)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0J1 =3D 1+int(population*u1)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if(inftime(J1)/=3D0)then
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 IF(T >=3D INFTIME(J1) .AND. INFTIME(J=
1)+infperiod >T)THEN
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0DIST1 =3D DIST1 + sqrt((X(i) -=
 X(J1))**2 + (Y(i) - Y(J1))**2)**(-BETA)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0write(10,*) X(J1),Y(J1), INFTI=
ME(J1)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0my_cnt =3D my_cnt+1
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ENDIF
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0endif
> =A0 =A0 =A0 =A0 =A0 =A0 endif
> =A0 =A0 =A0 =A0 =A0enddo
> =A0 =A0 =A0 =A0 =A0dist11 =3D (dist1*count)/my_cnt =A0 =A0 =A0 !!!!(inver=
se weighting by the weighting factors )!!!!!
> =A0 =A0 =A0 =A0 ! print *, count, my_cnt
> =A0 =A0 =A0 =A0 =A0PROB1 =3D 1 - exp(-ALPHA * dist11)
> =A0 =A0 =A0 =A0 =A0LOGLIKE =3D LOGLIKE + log(1 - PROB1)
>
> =A0 =A0 =A0 ENDIF
>
> =A0 =A0 =A0 =A0IF(INFTIME(i) .EQ. (T+1)) THEN
> =A0 =A0 =A0 =A0 =A0 DIST2 =3D 0.0
> =A0 =A0 =A0 =A0 =A0 do k =3D 1, NOSAMPLE
>
> =A0 =A0 =A0 =A0 =A0 if(my_cnt .le.rho*count)then !!!!!! random sampling f=
rom the infected population in the given proportion!!!!
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 call random_number(u2)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 k1 =3D 1+int(population*u2)
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if(inftime(k1)/=3D0)then
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0IF(T >=3D INFTIME(k1) .AND.INFTIME=
(k1)+infperiod > T) THEN
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 DIST2 =3D DIST2 + sqrt((X(i) =
- X(k1))**2 + (Y(i) - Y(k1))**2)**(-BETA)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 write(10,*) X(k1),Y(k1), INFT=
IME(k1)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 my_cnt =3D my_cnt+1
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ENDIF
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0endif
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 endif
> =A0 =A0 =A0 =A0 =A0 =A0enddo
> =A0 =A0 =A0 =A0 =A0 =A0dist22 =3D (dist2*count)/my_cnt =A0 =A0 =A0!!!!(in=
verse weighting by the weighting factors )!!!!!
>
> =A0 =A0 =A0 =A0 =A0 =A0PROB2 =3D 1 - exp(-ALPHA* dist22)
> =A0 =A0 =A0 =A0 =A0 =A0LOGLIKE =3D LOGLIKE + log(PROB2)
>
> =A0 =A0 =A0 =A0 ENDIF
>
> =A0 =A0 =A0enddo
>
> =A0 =A0 =A0 write(*,*)dist1,dist11, dist2, dist22, prob1, prob2,count, my=
_cnt
>
> =A0 =A0ENDDO
>
> =A0 =A0close(10)
> =A0end program likelihood
>
> I guess this could be the logical issue of using the do and if loop sever=
al times.
0
Reply robin.vowels (428) 8/1/2012 12:21:56 AM


On Aug 1, 4:02=A0am, gyanendra.pokharel <gyanendra.pokha...@gmail.com>
wrote:
> Hi there,
> I am getting hard time because of this logical error. There is no syntax =
error in the code but I am not getting right output. Can some one give the =
idea whats going on in the following code?
>
> program =A0likelihood
> IMPLICIT NONE
> REAL :: ALPHA, BETA, DIST1,DIST2, PROB1,PROB2,dist11, dist22
> REAL:: LOGLIKE, RHO,u1,u2
> INTEGER ::p,q, T, i,j,k,l, INFPERIOD, POPULATION, NOSAMPLE, J1,k1, count,=
 my_cnt
> REAL, DIMENSION(1:625):: X
> REAL, DIMENSION(1:625):: Y
> INTEGER, DIMENSION(1:625):: INFTIME
>
> !!!!!!!!!!!!!change of random seed!!!!!!!!!!!!
>
> =A0 INTEGER,ALLOCATABLE,DIMENSION(:) :: seed
> =A0 INTEGER,DIMENSION(8) :: time1
> =A0 INTEGER :: size
>
> =A0 CALL RANDOM_SEED(size=3Dsize)
> =A0 ALLOCATE (seed(size))
> =A0 CALL DATE_AND_TIME(values=3Dtime1)
> =A0 seed =3D 60*time1(6)+60*time1(7)+time1(8)
> =A0 CALL RANDOM_SEED(put=3Dseed)
>
> !!!!!!!!!!!!!!!!!!!!!!!!!required initial values !!!!!!!!!!!!!!!
>
> ALPHA =3D 0.5
> BETA =3D 2.0
> INFPERIOD =3D 3
> POPULATION =3D 625
> RHO =3D 0.1
> NOSAMPLE =3D int(RHO*POPULATION)
>
> !print *, NOSAMPLE
>
> OPEN(10, FILE =3D 'epidemicSIR.txt', FORM =3D 'FORMATTED')
> DO l =3D 1,625
> =A0 =A0READ(10,*,END =3D 200) X(l), Y(l), INFTIME(l)
> =A0 =A0!WRITE(*,*)X(l),Y(l), INFTIME(l)
> ENDDO
> close(10)
> 200 CONTINUE

Comment:
You don't know how many data have been read in.
(Although I note that there is a WRITE commented out.)


> open(10, file =3D 'epidatasamp.txt')
>
> LOGLIKE =3D 0.0
>
> !!!!!!!!!! time loop!!!!!
>
> DO T=3D1,10
>
> =A0count =3D 0
> =A0 my_cnt =3D 0
>
> !!!!!!!! total number of infected individuals at each time point!!!!!!!!
>
> =A0DO i=3D1,POPULATION
>
> =A0 =A0 =A0! if(inftime(i)/=3D0 .and. inftime(i)=3D=3DT)then
> =A0 =A0 =A0 =A0if(inftime(i)=3D=3DT)then
> =A0 =A0 =A0 =A0 =A0count =3D count+1
> =A0 =A0 =A0 endif
> =A0 =A0 =A0! print *, count
>
> =A0 =A0 =A0 IF(INFTIME(i)=3D=3D0 .OR. T < (INFTIME(i)-1)) THEN
> =A0 =A0 =A0 =A0 =A0DIST1 =3D 0.0
> =A0 =A0 =A0 =A0 =A0do j =3D 1, NOSAMPLE
>
> =A0 =A0 =A0 =A0 =A0 =A0 if(my_cnt .le. rho*count)then =A0 =A0 =A0 !!!!!! =
random sampling from the infected population in the given proportion!!!!
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0call random_number(u1)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0J1 =3D 1+int(population*u1)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if(inftime(J1)/=3D0)then
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 IF(T >=3D INFTIME(J1) .AND. INFTIME(J=
1)+infperiod >T)THEN
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0DIST1 =3D DIST1 + sqrt((X(i) -=
 X(J1))**2 + (Y(i) - Y(J1))**2)**(-BETA)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0write(10,*) X(J1),Y(J1), INFTI=
ME(J1)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0my_cnt =3D my_cnt+1
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ENDIF
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0endif
> =A0 =A0 =A0 =A0 =A0 =A0 endif
> =A0 =A0 =A0 =A0 =A0enddo
> =A0 =A0 =A0 =A0 =A0dist11 =3D (dist1*count)/my_cnt =A0 =A0 =A0 !!!!(inver=
se weighting by the weighting factors )!!!!!
> =A0 =A0 =A0 =A0 ! print *, count, my_cnt
> =A0 =A0 =A0 =A0 =A0PROB1 =3D 1 - exp(-ALPHA * dist11)
> =A0 =A0 =A0 =A0 =A0LOGLIKE =3D LOGLIKE + log(1 - PROB1)
>
> =A0 =A0 =A0 ENDIF
>
> =A0 =A0 =A0 =A0IF(INFTIME(i) .EQ. (T+1)) THEN
> =A0 =A0 =A0 =A0 =A0 DIST2 =3D 0.0
> =A0 =A0 =A0 =A0 =A0 do k =3D 1, NOSAMPLE
>
> =A0 =A0 =A0 =A0 =A0 if(my_cnt .le.rho*count)then !!!!!! random sampling f=
rom the infected population in the given proportion!!!!
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 call random_number(u2)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 k1 =3D 1+int(population*u2)
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if(inftime(k1)/=3D0)then
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0IF(T >=3D INFTIME(k1) .AND.INFTIME=
(k1)+infperiod > T) THEN
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 DIST2 =3D DIST2 + sqrt((X(i) =
- X(k1))**2 + (Y(i) - Y(k1))**2)**(-BETA)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 write(10,*) X(k1),Y(k1), INFT=
IME(k1)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 my_cnt =3D my_cnt+1
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ENDIF
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0endif
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 endif
> =A0 =A0 =A0 =A0 =A0 =A0enddo
> =A0 =A0 =A0 =A0 =A0 =A0dist22 =3D (dist2*count)/my_cnt =A0 =A0 =A0!!!!(in=
verse weighting by the weighting factors )!!!!!
>
> =A0 =A0 =A0 =A0 =A0 =A0PROB2 =3D 1 - exp(-ALPHA* dist22)
> =A0 =A0 =A0 =A0 =A0 =A0LOGLIKE =3D LOGLIKE + log(PROB2)
>
> =A0 =A0 =A0 =A0 ENDIF
>
> =A0 =A0 =A0enddo
>
> =A0 =A0 =A0 write(*,*)dist1,dist11, dist2, dist22, prob1, prob2,count, my=
_cnt
>
> =A0 =A0ENDDO
>
> =A0 =A0close(10)
> =A0end program likelihood

Comments:
1.  You don't show either a sample input data,
nor the wrong results.
2.  In what way are the results wrong?
0
Reply robin.vowels (428) 8/1/2012 12:25:10 AM

Here are my sample input data and result

    X               Y                   INFTIME
   1.000000       1.000000              10
   1.000000       2.000000               8
   1.000000       3.000000               8
   1.000000       4.000000               9
   1.000000       5.000000              10
   1.000000       6.000000               8
   1.000000       7.000000               7
   1.000000       8.000000               8
   1.000000       9.000000               7
   1.000000       10.00000               6
   1.000000       11.00000               7
   1.000000       12.00000               7
   1.000000       13.00000               8
   1.000000       14.00000               8
   1.000000       15.00000               8
   1.000000       16.00000               9
   1.000000       17.00000               7
   1.000000       18.00000               8
   1.000000       19.00000               5
   1.000000       20.00000               7
   1.000000       21.00000               6
   1.000000       22.00000               7
   1.000000       23.00000               8
   1.000000       24.00000               9
   1.000000       25.00000               8
   2.000000       1.000000               9
   2.000000       2.000000              10
   2.000000       3.000000               9
   2.000000       4.000000               8
   2.000000       5.000000               9
   2.000000       6.000000              10
   2.000000       7.000000               8
   2.000000       8.000000               9
   2.000000       9.000000               7
   2.000000       10.00000               9
   2.000000       11.00000               6
   2.000000       12.00000               6
   2.000000       13.00000               7
   2.000000       14.00000               8
   2.000000       15.00000               7
   2.000000       16.00000               8
   2.000000       17.00000               6
   2.000000       18.00000               8
   2.000000       19.00000               4
   2.000000       20.00000               3
   2.000000       21.00000               5
   2.000000       22.00000               7
   2.000000       23.00000               6
   2.000000       24.00000               8
   2.000000       25.00000               9
   3.000000       1.000000              11
   3.000000       2.000000              10
   3.000000       3.000000               8
   3.000000       4.000000               9
   3.000000       5.000000               7
   3.000000       6.000000               7
   3.000000       7.000000               9
   3.000000       8.000000               7
   3.000000       9.000000               7
   3.000000       10.00000               7
   3.000000       11.00000               7
   3.000000       12.00000               8
   3.000000       13.00000               8
   3.000000       14.00000               8
   3.000000       15.00000               7
   3.000000       16.00000               7
   3.000000       17.00000               5
   3.000000       18.00000               6
   3.000000       19.00000               6
   3.000000       20.00000               4
   3.000000       21.00000               6
   3.000000       22.00000               7
   3.000000       23.00000               7
   3.000000       24.00000              10
   3.000000       25.00000               8
   4.000000       1.000000              11
   4.000000       2.000000               9
   4.000000       3.000000               7
   4.000000       4.000000               7
   4.000000       5.000000               8
   4.000000       6.000000               7
   4.000000       7.000000               9
   4.000000       8.000000               7
   4.000000       9.000000               8
   4.000000       10.00000               5
   4.000000       11.00000               6
   4.000000       12.00000               7
   4.000000       13.00000               6
   4.000000       14.00000               7
   4.000000       15.00000               6
   4.000000       16.00000               7
   4.000000       17.00000               4
   4.000000       18.00000               5
   4.000000       19.00000               6
   4.000000       20.00000               6
   4.000000       21.00000               5
   4.000000       22.00000               7
   4.000000       23.00000               8
   4.000000       24.00000              10
   4.000000       25.00000               9
   5.000000       1.000000              10
   5.000000       2.000000              10
   5.000000       3.000000               9
   5.000000       4.000000               9
   5.000000       5.000000               9
   5.000000       6.000000               9
   5.000000       7.000000               8
   5.000000       8.000000               9
   5.000000       9.000000               8
   5.000000       10.00000               6
   5.000000       11.00000               7
   5.000000       12.00000               8
   5.000000       13.00000               7
   5.000000       14.00000               8
   5.000000       15.00000               5
   5.000000       16.00000               5
   5.000000       17.00000               5
   5.000000       18.00000               7
   5.000000       19.00000               6
   5.000000       20.00000               7
   5.000000       21.00000               7
   5.000000       22.00000               6
   5.000000       23.00000               6
   5.000000       24.00000              10
   5.000000       25.00000               7
   6.000000       1.000000               8
   6.000000       2.000000              11
   6.000000       3.000000              10
   6.000000       4.000000               9
   6.000000       5.000000              10
   6.000000       6.000000               9
   6.000000       7.000000               8
   6.000000       8.000000               6
   6.000000       9.000000               7
   6.000000       10.00000               6
   6.000000       11.00000               8
   6.000000       12.00000               8
   6.000000       13.00000               7
   6.000000       14.00000               4
   6.000000       15.00000               4
   6.000000       16.00000               2
   6.000000       17.00000               6
   6.000000       18.00000               7
   6.000000       19.00000               5
   6.000000       20.00000               6
   6.000000       21.00000               5
   6.000000       22.00000               4
   6.000000       23.00000               6
   6.000000       24.00000              11
   6.000000       25.00000               7
   7.000000       1.000000              10
   7.000000       2.000000              10
   7.000000       3.000000               9
   7.000000       4.000000              10
   7.000000       5.000000               9
   7.000000       6.000000               9
   7.000000       7.000000               7
   7.000000       8.000000               7
   7.000000       9.000000               6
   7.000000       10.00000               7
   7.000000       11.00000               7
   7.000000       12.00000               8
   7.000000       13.00000               6
   7.000000       14.00000               7
   7.000000       15.00000               3
   7.000000       16.00000               3
   7.000000       17.00000               4
   7.000000       18.00000               6
   7.000000       19.00000               5
   7.000000       20.00000               6
   7.000000       21.00000               5
   7.000000       22.00000               3
   7.000000       23.00000               7
   7.000000       24.00000               8
   7.000000       25.00000               9
   8.000000       1.000000              10
   8.000000       2.000000              10
   8.000000       3.000000               9
   8.000000       4.000000               9
   8.000000       5.000000               8
   8.000000       6.000000               8
   8.000000       7.000000               7
   8.000000       8.000000               7
   8.000000       9.000000               6
   
     
Here the data is only a part. The full data includes 625 individuals in a grid of 25 by 25
Result:

dist1         dist11      dist2     dist22    prob1    prob2     count       my_cnt
 0.000       0.000       0.000      0.000     0.000    0.000        1            1
 0.000       0.000        0.000      0.000     0.000    0.000       3            1
 0.000       0.000       0.000      0.000      0.000      0.000     10           2
 0.000       0.000       0.000      0.000      0.000      0.000     23           3
 0.000       0.000       0.000      0.000      0.000      0.000     55           6
 0.000       0.000       0.000      0.000      0.000      0.000     99           10
 0.000       0.000       0.000      0.000      0.000      0.000     136          14
 0.000       0.000       0.000      0.000      0.000      0.000     145          15
 0.000       0.000  2.5380710E-03 2.2842638E-020.000  1.1356354E-02 90           10
 0.000       0.000       0.000      0.000      0.000     0.000      45           5

I expect all dist1, dist11, dist2, dist22, brob1 and prob2 must be non-zero or at least most of them should be non-zero. count and my_cnt are ok.

Thanks



--
0
Reply gyanendra.pokharel (31) 8/1/2012 6:46:31 PM

On 8/1/2012 1:46 PM, gyanendra.pokharel wrote:
> Here are my sample input data and result
>
>      X               Y                   INFTIME
>     1.000000       1.000000              10
....

> Here the data is only a part. The full data includes 625 individuals in a grid of 25 by 25
> Result:
>
> dist1         dist11      dist2     dist22    prob1    prob2     count       my_cnt
>   0.000       0.000       0.000      0.000     0.000    0.000        1            1
>   0.000       0.000        0.000      0.000     0.000    0.000       3            1
>   0.000       0.000       0.000      0.000      0.000      0.000     10           2
>   0.000       0.000       0.000      0.000      0.000      0.000     23           3
....

>
> I expect all dist1, dist11, dist2, dist22, brob1 and prob2 must be
> non-zero or at least most of them should be non-zero. count and
> my_cnt  are ok.
>
....

Well, if the counts are correct that's  indicative that the logical 
tests in the IF are apparently doing what you think they should.  Ergo, 
then the terms like DIST1=....

J1 = 1+int(population*u1)
if(inftime(J1)/=0)then
   IF(T >= INFTIME(J1) .AND. INFTIME(J1)+infperiod >T)THEN
     DIST1 = DIST1 + sqrt((X(i) - X(J1))**2 + (Y(i) - Y(J1))**2)**(-BETA)

and so on aren't what you think.

Debug those terms inside it and see why they're zero.

One peculiarity I note is the initialization of the RNG -- I don't see 
any testing that the particular size of the seed array is specifically 
that of the number of elements used even though you do retrieve what 
that is.  That may or may not have any bearing on the results.

For debugging I'd use the fixed compiler-supplied seed so could see the 
same results each run and work my way through the computations that I 
was expecting manually and compare to the intermediate results of the 
code until I found where they depart from the expected.  Once you find 
that, it will probably be clear as to what the fix is.

--
0
Reply none1568 (6816) 8/1/2012 8:19:03 PM

On 2/08/2012 6:46 a.m., gyanendra.pokharel wrote:
> Here are my sample input data and result
....

All the help you need is provided by: write(*,*)
Write out intermediate results, follow the computation steps and see 
where the intermediate result does not concur with what you expect. 
Either your expectation or the code will be shown to be wrong.

0
Reply g.bogle6025 (28) 8/1/2012 9:04:20 PM

"gyanendra.pokharel" <gyanendra.pokharel@gmail.com> wrote in message 
news:45ednU5Ux5o5gIXNnZ2dnUVZ_tednZ2d@giganews.com...

> I am getting hard time because of this logical error. There is no syntax 
> error in the code but I am not getting right output. Can some one give the 
> idea whats going on in the following code?

In your code, you recompute either DIST1 or DIST2 10*625 = 6250
times, but only print out 10*2 = 20 of these results.  My suspicion
is that your loop keeps running after my_cnt .GT. rho*count and
then the effect is to reset DIST1 or DIST2 to zero on each iteration
of the DO i = 1, POPULATION loop.  So it's just a fluke if either
of these variables is nonzero at the point you print them out.

-- 
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


0
Reply not_valid (1681) 8/2/2012 12:53:13 AM

Yes g.bogle6025, I tried varies ways. I guess, I am not putting the command 

> if(my_cnt .le. rho*count)then 

in right position. When I remove this from the program it returns some thing but I can't use my_cnt any more, my idea is the command 

> if(my_cnt .le. rho*count)then  

samples in the proportion of "rho" from the whole population for each value of T. 

If there is any other ways of doing this, it would be great for me.

Thanks
0
Reply gyanendra.pokharel (31) 8/2/2012 1:00:44 AM

On 08/01/2012 07:00 PM, gyanendra.pokharel wrote:
> Yes g.bogle6025, I tried varies ways. I guess, I am not putting the command
>
>> if(my_cnt .le. rho*count)then
>
> in right position. When I remove this from the program it returns some thing but I can't use my_cnt any more, my idea is the command
>
>> if(my_cnt .le. rho*count)then
>
> samples in the proportion of "rho" from the whole population for each value of T.
>
> If there is any other ways of doing this, it would be great for me.
>
> Thanks
>
>

Use print statements; lots of them.  Show yourself then us the output.
-- 
Cal
0
Reply cal819 (188) 8/2/2012 3:15:19 AM

On 08/01/2012 03:04 PM, Gib Bogle wrote:
> On 2/08/2012 6:46 a.m., gyanendra.pokharel wrote:
>> Here are my sample input data and result
> ...
>
> All the help you need is provided by: write(*,*)
> Write out intermediate results, follow the computation steps and see
> where the intermediate result does not concur with what you expect.
> Either your expectation or the code will be shown to be wrong.
>

Hey Gib, that's exactly what I said, so let me add that (*,*) is the 
friendliest apparition in the computing world.
-- 
Cal
0
Reply cal819 (188) 8/2/2012 3:18:39 AM

On 2/08/2012 1:00 p.m., gyanendra.pokharel wrote:
> Yes g.bogle6025, I tried varies ways. I guess, I am not putting the command
>
>> if(my_cnt .le. rho*count)then
>
> in right position. When I remove this from the program it returns some thing but I can't use my_cnt any more, my idea is the command
>
>> if(my_cnt .le. rho*count)then
>
> samples in the proportion of "rho" from the whole population for each value of T.
>
> If there is any other ways of doing this, it would be great for me.
>
> Thanks

What would be great for you would be to figure out the logic and code it 
yourself.  That's how we learn.

0
Reply g.bogle6025 (28) 8/2/2012 8:40:55 AM

Thanks to all for your valuable comments. The code works well inside the command 

> if(my_cnt .le. rho*count)then

but when I exit from that condition it stops working. I still did not understand why it is happening.
 
0
Reply gyanendra.pokharel (31) 8/2/2012 4:24:00 PM

12 Replies
479 Views

(page loaded in 0.492 seconds)


Reply: