Skip to contents

fsi_qw_eval() implements two methods for evaluating region inference (RI) queries: (i) Linguistic value-based RI query, and (ii) Optimal RI query. The objective of these queries is to capture all points that intersect a search object (e.g., a query window) and whose inferred values fulfill some specific user requirements (e.g., the points with the maximum or minimum inferred values).

Usage

fsi_qw_eval(fsi, qw, approach = "discretization", ...)

Arguments

fsi

An FSI model built with the fsi_create() function and populated by the functions fsi_add_fsa(), fsi_add_cs(), and fsi_add_rules().

qw

An sfg object representing the search object (e.g., a query window). It has to be an axis-aligned rectangle represented by a simple polygon object of 5 points (since the last coordinate pair closes the external ring of the rectangle).

approach

Defines which approach is employed to perform the region inference: "discretization" or "pso". Default value is "discretization".

...

<dynamic-dots> Different set of parameters required depending on the chosen approach (see more in details below).

Value

A tibble in the format (points, inferred_values), where points is an sfc object and inferred_values are inferred values in the domain of the consequent of the FSI model.

Details

The fsi_qw_eval() function evaluates two types of RI queries:

  • Linguistic value-based RI query, which answers the following type of question: what are the points that intersect a given search object and have inferred values that belong to a target linguistic value?

  • Optimal RI query, which answers the following type of question: what are the points that intersect a given search object and have the maximum (or minimum) inferred values?

fsi_qw_eval() offers two different methods to answer these questions: (i) discretization method, and (ii) optimization method. Comparative analyses (see reference below) indicate that the discretization method should be employed to process linguistic value-based RI queries, while the optimization method is more adequate for processing optimal RI queries. The details below describe how to use these methods.

For the discretization method, two additional parameters are needed and must be informed by using the three-dots parameter ...:

  • target_lval: A character value that indicates the target linguistic value from the linguistic variable of the consequent.

  • k: A numeric value that defines the number of points that will be captured from the query window and evaluated by fsi_eval(). Its square root has to an integer value. Alternatively, you can inform the number of columns and rows of the regular grid to be created on the query window by informing numeric values for n_col and n_row, respectively. Thus, these parameters can be given instead of the number k.

The optimization method employs the particle swarm optimization (PSO) algorithm. Thus, the parameter approach = "pso" must be set together with the following parameters:

  • what: A character value that defines the user's goal, which can be either maximize or minimize inferred values. Thus, this parameter can be either "max" or "min". The default value is "max".

  • max_depth: A numeric value that refers to the number of times that the query window is divided into subquadrants. The default value is equal to 2. For instance, a max_depth = 2 means that the query window will be split into four subquadrants, where the PSO will be applied to each one as its search space.

In addition, the PSO algorithm has its own set of parameters:

  • maxit: A numeric value that defines the maximum number of iterations. Default value is 50.

  • population: A numeric value that defines the number of particles. Default value is 10.

Examples

library(sf)

# Creating the FSI model from an example
fsi <- visitation()

# Creating a vector of fuzzy rules
## note that we make use of the linguistic variables and linguistic values previously defined
rules <- c(
 "IF accommodation review is reasonable AND 
    food safety is low 
  THEN visiting experience is awful",
 "IF accommodation price is expensive AND 
    accommodation review is reasonable 
  THEN visiting experience is awful",
 "IF accommodation price is affordable AND 
    accommodation review is good AND 
    food safety is medium 
  THEN visiting experience is average",
 "IF accommodation price is affordable AND 
    accommodation review is excellent AND 
    food safety is high 
  THEN visiting experience is great",
 "IF accommodation price is cut-rate AND 
    accommodation review is excellent AND 
    food safety is high 
  THEN visiting experience is great")

# Adding these rules to the FSI model previously instantiated
fsi <- fsi_add_rules(fsi, rules)

# Defining the query window
pts_qw1 <- rbind(c(-73.92, 40.68527), c(-73.75, 40.68527), 
                 c(-73.75, 40.75), c(-73.92, 40.75), c(-73.92, 40.68527))
qw1 <- st_polygon(list(pts_qw1))

# Recall that our running example is based on a small set of point datasets
# This means that inferred values will likely be the same

# \dontrun{
# Example using the discretization method
fsi_qw_eval(fsi, qw1, approach = "discretization", target_lval = "great", k = 25)
#> # A tibble: 20 × 2
#>                points inferred_values
#>               <POINT>           <dbl>
#>  1 (-73.903 40.69174)              50
#>  2 (-73.869 40.69174)              50
#>  3 (-73.835 40.69174)              50
#>  4 (-73.801 40.69174)              50
#>  5 (-73.903 40.70469)              50
#>  6 (-73.869 40.70469)              50
#>  7 (-73.835 40.70469)              50
#>  8 (-73.801 40.70469)              50
#>  9 (-73.903 40.71764)              50
#> 10 (-73.869 40.71764)              50
#> 11 (-73.835 40.71764)              50
#> 12 (-73.801 40.71764)              50
#> 13 (-73.903 40.73058)              50
#> 14 (-73.869 40.73058)              50
#> 15 (-73.835 40.73058)              50
#> 16 (-73.801 40.73058)              50
#> 17 (-73.903 40.74353)              50
#> 18 (-73.869 40.74353)              50
#> 19 (-73.835 40.74353)              50
#> 20 (-73.801 40.74353)              50

# Example using the optimization method
fsi_qw_eval(fsi, qw1, approach = "pso", max_depth = 2)
#> # A tibble: 16 × 2
#>                  points inferred_values
#>                 <POINT>           <dbl>
#>  1 (-73.87168 40.70297)              50
#>  2  (-73.9092 40.69906)              50
#>  3 (-73.86649 40.68684)              50
#>  4 (-73.88427 40.71438)              50
#>  5 (-73.85718 40.71335)              50
#>  6 (-73.80324 40.69522)              50
#>  7  (-73.8291 40.68649)              50
#>  8 (-73.82052 40.71571)              50
#>  9 (-73.90343 40.72079)              50
#> 10 (-73.90133 40.72763)              50
#> 11 (-73.86219 40.72049)              50
#> 12 (-73.88931 40.74836)              50
#> 13 (-73.85862 40.73843)              50
#> 14 (-73.81023 40.72272)              50
#> 15  (-73.8016 40.73175)              50
#> 16  (-73.8303 40.74647)              50
# }