Skip to content

Commit

Permalink
Updates to v2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Christos Theodoropoulos committed Jan 18, 2020
1 parent 59bbbd0 commit e0779b3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 72 deletions.
35 changes: 4 additions & 31 deletions habfuzz/fdeclarations.f95
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module fdeclarations
integer, dimension(:), allocatable :: a, bins, iimatrix, a1
real, dimension(:), allocatable :: icci
integer :: z,zz,ff,i,n,k,j,jj,e,ee,f,nn,ii,col1,col2,col3,col4,l,o,v,ik
real, dimension(:,:), allocatable :: matrix, cmatrix, rmatrix, amatrix, pmatrix, p1matrix, &
real, dimension(:,:), allocatable :: bayh, bayg, baym, bayp, bayb, &
c1matrix, c2matrix, matrix, cmatrix, rmatrix, amatrix, pmatrix, p1matrix, &
p2matrix, p22matrix, uf, df, tf, sf, imatrix, dmatrix, ematrix, suitability, testmat, s, &
co1matrix, aa, cer
real, dimension(:,:,:), allocatable :: bmatrix, fmatrix, mmatrix, p11matrix, comatrix
Expand All @@ -15,35 +16,7 @@ module fdeclarations
tla,tlb,tlc,tld,tma,tmb,tmc,tmd,tha,thb,thc,thd,tvha,tvhb

!The maximum array size - this should be re-defined if the elements of the input arrays exceed 3000
integer, parameter :: rsize = 5170, w = 5

!Trapezoidal-shaped fuzzy sets for flow velocity (V), water depth (D), temperature (T)
!FLOW VELOCITY (or PREDICTOR 1)
!real, parameter :: uvla = 0.05, uvlb = 0.10 !VERY LOW V class
!real, parameter :: ula = 0.05, ulb = 0.10, ulc = 0.15, uld = 0.20 !LOW V class
!real, parameter :: uma = 0.15, umb = 0.20, umc = 0.40, umd = 0.50 !MODERATE V class
!real, parameter :: uha = 0.40, uhb = 0.50, uhc = 0.70, uhd = 0.80 !HIGH V class
!real, parameter :: uvha = 0.7, uvhb = 0.80 !VERY HIGH V class

!WATER DEPTH (or PREDICTOR 2)
!real, parameter :: dvla = 0.10, dvlb = 0.15 !The VERY SHALLOW D class
!real, parameter :: dla = 0.10, dlb = 0.15, dlc = 0.30, dld = 0.35 !The SHALLOW D class
!real, parameter :: dma = 0.30, dmb = 0.35, dmc = 0.55, dmd = 0.60 !The MODERATE D class
!real, parameter :: dda = 0.55, ddb = 0.60, ddc = 0.70, ddd = 0.75 !The DEEP D class
!real, parameter :: dvda = 0.70, dvdb = 0.75 !The VERY DEEP D class

!SUBSTRATE (or PREDICTOR 3)
!real, parameter :: boulders = 0.070, large_stones = 0.050, small_stones = 0.040
!real, parameter :: large_gravel = 0.030, medium_gravel = 0.026, fine_gravel = 0.024
!real, parameter :: sand = 0.022, silt = 0.020 !

!TEMPERATURE (or PREDICTOR 4)
!real, parameter :: tvla = 9, tvlb = 10 !The VERY LOW T class
!real, parameter :: tla = 9, tlb = 10, tlc = 13, tld = 15 !The LOW T class
!real, parameter :: tma = 13, tmb = 15, tmc = 17, tmd = 19 !The MODERATE T class
!real, parameter :: tha = 17, thb = 19, thc = 23, thd = 25 !The HIGH T class
!real, parameter :: tvha = 25, tvhb = 27 !The VERY HIGH T class

integer, parameter :: rsize = 50000, w = 5
!RESPONSE VARIABLE 5-CLASS VALUES
real, parameter :: ka = 0.2, kb = 0.4, kc = 0.6, kd = 0.8
!EXPECTED UTILITY VALUES FOR RULES2.F95
Expand All @@ -60,7 +33,7 @@ module fdeclarations
real, dimension(rsize) :: bayh1, bayg1, baym1, bayp1, bayb1
real, dimension(rsize) :: bayh2, bayg2, baym2, bayp2, bayb2
real, dimension(rsize) :: ab, ap, am, ag, ah, cb, cp, cm, cg, ch
real, dimension(:,:), allocatable :: bayh, bayg, baym, bayp, bayb
real, dimension(:), allocatable :: tbayh, tbayg, tbaym, tbayp, tbayb
real, dimension(:), allocatable :: high, good, moderate, poor, bad, cs, habcon, gwet, wet

!Variables of the defuzzification process
Expand Down
Binary file modified habfuzz/habfuzz.exe
Binary file not shown.
75 changes: 34 additions & 41 deletions habfuzz/tester.f95
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ subroutine tester
!do i=1,n
!write(*,10) (dmatrix(i,j), j=1,w)
!end do
write(*,*) 'Developing rules database...'
write(*,*) 'Developing rules database ...'
call classifier

open(49, file='log.txt', action='write', status='replace')
Expand Down Expand Up @@ -70,73 +70,64 @@ subroutine tester
write(*,*) ' '
call sleep(2)

write(*,*) 'Fuzzifying inputs...'
write(*,*) 'Fuzzifying inputs ...'

ematrix=testmat
z=ee
call fuzzifier
write(*,*) 'Fuzzification successful!'
write(*,*) ' '

write(*,*) 'Applying Bayesian joint probability rules...'
write(*,*) 'Applying the fuzzy rule-based Bayesian algorithm ...'
write(*,*) ' '
call sleep(2)

allocate(bmatrix(e**(w-1),w-1,ee))
allocate(bayh(nn,ee))
allocate(bayg(nn,ee))
allocate(baym(nn,ee))
allocate(bayp(nn,ee))
allocate(bayb(nn,ee))
allocate(fmatrix(nn,w-1,ee))

do i=1,ee
open(29, file='bmatrix.txt', action='write', status='replace')
allocate(c1matrix(e**(w-1),w-1))
allocate(tbayh(nn))
allocate(tbayg(nn))
allocate(tbaym(nn))
allocate(tbayp(nn))
allocate(tbayb(nn))
allocate(c2matrix(nn,w-1))

open(29, file='dmatrix.txt', action='write', status='replace')
write(29,*) nn
call permutator
close(29, status='keep')

open (unit=39, file='bmatrix.txt', status='old', action='read')
open (unit=39, file='dmatrix.txt', status='old', action='read')
read (39,*) nn
do jj=1,nn
read(39,*) (fmatrix(jj,j,i), j=1,w-1)
read(39,*) (c2matrix(jj,j), j=1,w-1)
end do
close(39, status='keep')

do j=1,nn
bayh(j,i)=product(fmatrix(j,:,i))*p2matrix(j,1)
bayg(j,i)=product(fmatrix(j,:,i))*p2matrix(j,2)
baym(j,i)=product(fmatrix(j,:,i))*p2matrix(j,3)
bayp(j,i)=product(fmatrix(j,:,i))*p2matrix(j,4)
bayb(j,i)=product(fmatrix(j,:,i))*p2matrix(j,5)
end do
write(*,*) 'Rules application for observation', i, 'successful'
tbayh(j)=product(c2matrix(j,:))*p2matrix(j,1)
tbayg(j)=product(c2matrix(j,:))*p2matrix(j,2)
tbaym(j)=product(c2matrix(j,:))*p2matrix(j,3)
tbayp(j)=product(c2matrix(j,:))*p2matrix(j,4)
tbayb(j)=product(c2matrix(j,:))*p2matrix(j,5)
end do
write(*,*) ' '
write(*,*) 'Rules application successful!'
write(*,*) ' '
write(*,*) 'Calculating Bayesian joint probabilities...'
call sleep(2)
!write(49,*) ' '
!write(49,*) 'fmatrix'
!do i=1,nn
!write(49,10) (fmatrix(i,j,jj), j=1,w-1)
!end do
write(*,*) 'Joint probability calculation succesful!'
write(*,*) ' '
print *, 'Calculating response variable...'
call sleep(2)
write(*,*) ' '
do i=1,ee
write(*,*) 'Response variable calculation for test observation', i, 'successful'
bayg1(i)=sum(bayg(1:nn,i))
baym1(i)=sum(baym(1:nn,i))
bayh1(i)=sum(bayh(1:nn,i))
bayp1(i)=sum(bayp(1:nn,i))
bayb1(i)=sum(bayb(1:nn,i))
write(*,*) 'Output calculation for observation', i, 'successful'
bayg1(i)=sum(tbayg(1:nn))
baym1(i)=sum(tbaym(1:nn))
bayh1(i)=sum(tbayh(1:nn))
bayp1(i)=sum(tbayp(1:nn))
bayb1(i)=sum(tbayb(1:nn))
deallocate(c1matrix)
deallocate(c2matrix)
deallocate(tbayh)
deallocate(tbayg)
deallocate(tbaym)
deallocate(tbayp)
deallocate(tbayb)
end do
write(*,*) ' '
write(*,*) 'Response variable calculation successful!'
z=ee
call rules2
!write(49,*) ' '
Expand Down Expand Up @@ -217,4 +208,6 @@ subroutine tester
end if
10 format (8f7.3)

open (unit=39, file='dmatrix.txt', status='old', action='read')
close (39, status='delete')
end subroutine tester

0 comments on commit e0779b3

Please sign in to comment.