Skip to content

FuzzyFishHS provides functions to develop and inspect zero-order presence-absence Takagi–Sugeno–Kang fuzzy rule-based systems for fish habitat evaluation within environmental flow assessemnt studies.

License

Notifications You must be signed in to change notification settings

RafaMMas/FuzzyFishHS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FuzzyFishHS

FuzzyFishHS provides functions to develop and inspect zero-order presence-absence Takagi–Sugeno–Kang fuzzy rule-based systems for fish habitat evaluation within environmental flow assessemnt studies.

Installation

You can install the development version of FuzzyFishHS from GitHub with:

# install.packages("devtools")
devtools::install_github("RafaMMas/FuzzyFishHS")

Example

Model development

library(FuzzyFishHS)

Create the Fuzzy Rule-Based System (FRBS) using the function FRBS. This function simply lists the following five arguments:

  • ImpVariables the names of the input variables in vector format
  • Range a matrix with as many columns as input variables with the minimum and maximum expected values for each variable
  • MFfunction the selected membership function
  • MFparameters the parameters of the membership functions. It should be a matrix with as many columns as fuzzy sets. The columns for each variable must include the variable name as indicated in ImpVariables.
  • Consequents the zero-order TSK fuzzy rule consequents.

You can choose among the 10 different membership functions implemented in the packages. The package includes a function (HILL.CLIMB.FRBS.Super.Fast.TSS) to train (optimise) the fuzzy rules’ consequents. At this point you can add a random vector with as many consequents as fuzzy rules.

Example.FRBS <- Create.FRBS.R(ImpVariables = c("Velocity", "Depth", "Substrate.index", "Cover.index"),
                       Range = matrix(c(0, 1.164, 0, 2.67, 0, 8, 0, 1), ncol = 4, dimnames = list(NULL, c("Velocity", "Depth", "Substrate.index", "Cover.index")
                                                                                                  )),
                       MFfunction = PIMF,
                       MFparameters = matrix(c(0, 0, 0.0377, 0.4, 0.0377, 0.4, 1.164, 1.164, 0, 
                                               0, 0.46, 0.8767, 0.46, 0.8767, 1.3067, 2.67, 1.3067, 2.67, 2.67, 
                                               2.67, 0, 0, 0, 0.5333, 0, 0.5333, 3.8667, 6, 3.8667, 6, 8, 8, 
                                               0, 0, 0, 1, 0, 1, 1, 1), ncol = 10, 
                                           dimnames = list(NULL, c("VelocityL", "VelocityH", "DepthL", 
                                                                   "DepthM", "DepthH", "Substrate.indexL", "Substrate.indexM", "Substrate.indexH", 
                                                                   "Cover.indexL", "Cover.indexH"))),
                       Consequents = c(0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0.5, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0)
                       )


Once the FRBS has been created it is recommended to plot the membership functions and check whether they are correct.

PlotMF(FRBS = Example.FRBS, n.pt = 9999,
       data = NULL,
       Title = "Lepomis gibbosus")



The function *PlotMF* allows including the training dataset to compare the membership functions with the distribution of the input variables per output class (*i.e.,* presence or absence). Pink corresponds to presence data and grey to absence.
PlotMF(FRBS = Example.FRBS, n.pt = 9999,
      data = Lepomis.gibbosus.dataset,
      Title = "Lepomis gibbosus")

Fuzzy rules training

In order to boost rules’ training the membership of each datum to each fuzzy rule is calculated beforehand. It can be done employing the function FUZZIFY.FRBS.Fast.

Memberships <- FUZZIFY.FRBS.Fast(Data = Lepomis.gibbosus.dataset[,Example.FRBS$ImpVariables],
                                 FRBS = Example.FRBS)


Once the membership is calculated it it fed to the function HILL.CLIMB.FRBS.Super.Fast.TSS. The hill climbing algorithm starts from a random set of consequents and modifies one consequance at a time retaining those changes tha improve model performance (i.e., the True Skill Statistic). Threfore, we recommend repeating the optimisation multiple times to avoid getting traped in local minima.

Optimised.consequents <- HILL.CLIMB.FRBS.Super.Fast.TSS(Membership = Memberships,
                                                        Training.dataset = Lepomis.gibbosus.dataset,
                                                        Trials = 9)
print(Optimised.consequents)
#> $TSS
#> [1] 0.6671805
#> 
#> $Consequents
#>  [1] 0 0 0 1 0 1 0 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 1 1 0 0 1 1 0 0 1 0 0 0 0 0

After the hill climbing algorithm finished, the random consequents can be substitutted by those optimal and predictions can be done as follow:

Predict <- PREDICT.FRBS.Fast(Data = Lepomis.gibbosus.dataset[,Lepomis.gibbosus.FRBS$ImpVariables],
                             FRBS = Example.FRBS)

plot(Lepomis.gibbosus.dataset$Species, Predict[2,],
                              bty = "n", las = 1, col = "orangered", xlab = "Observed", ylab = "Predicted")
abline(lm(Predict[2,] ~ Lepomis.gibbosus.dataset$Species), col = "dodgerblue")


About

FuzzyFishHS provides functions to develop and inspect zero-order presence-absence Takagi–Sugeno–Kang fuzzy rule-based systems for fish habitat evaluation within environmental flow assessemnt studies.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages