The mrfi
S4 class is a representation of the interaction
structure for a spatially-stationary Markov Random Field.
The function mrfi()
provides an interface for creation
mrfi
objects. A plot
method is also available for visualization, as
well as conversion methods like as.list
and operators like +
.
mrfi()
creates an object of class mrfi
based on a distance
rule and optionally a list of relative positions. The argument max_norm
and
norm_type
can be used to automatically include all positions within a
"range" defined by the norm type chosen and distance using that norm.
A list of relative positions may also be included to specify sparse
interaction structures, for example. Alternatively, rpositions()
can be used to create a based exclusively on a list of relative positions.
Simple operations are provided to include (set union)
new interacting positions to a mrfi
object with the '+'
operator and
remove positions (set difference) with -
. Individual positions can be
included/excluded using length-2 vectors in the right hand side. Union and
set difference of complete structures can also be computed by adding or
subtracting two mrfi
objects.
These operations deal with opposite directions filtering to avoid redundancy in the interaction structure.
mrfi(max_norm = 1, norm_type = "1", positions = NULL)
rpositions(positions)
# S3 method for mrfi
as.list(x, ...)
# S4 method for mrfi
length(x)
# S4 method for mrfi,numeric,missing
[[(x, i)
# S4 method for mrfi,numeric,missing
[(x, i)
# S4 method for mrfi,numeric
+(e1, e2)
# S4 method for mrfi,numeric
-(e1, e2)
# S4 method for mrfi,mrfi
+(e1, e2)
# S4 method for mrfi,mrfi
-(e1, e2)
mrfi_to_string(mrfi)
a numeric
value. All points with norm \(\le\) max_dist
are included.
a character
indicating the norm type used. Possible values
are "m", "1", "2", etc. See norm
for details.
a list
of numeric
vectors of length 2. Each vector
corresponds to a relative position included.
mrfi
object.
other arguments not used by this method.
vector of indexes to extract interacting positions.
A mrfi
object.
Either a second mrfi
object or a length 2 numeric
with the new
relative position to include (+
) or remove (-
).
A mrfi
object.
as.list()
: converts the mrfi
object to a list of interacting
positions (list of length-2 vectors).
[[
: converts to list and subsets it.
[
: subsets the mrfi
object and returns another mrfi
object.
+
: computes the union of the interaction structure in a mrfi
object with
a numeric
representing an additional position to include or another mrfi
object.
The interaction structure is defined by the list of relative positions in it. For a specific pixel, conditional to the values of pixels in these relative positions from it, its value is independent of any other pixel in the image.
The relative positions are indentified by two integers rx
and ry
representing the "shift" in the x
-axis and y
-axis respectively. As an
example: The relative position (1,0)
representes the pixel in the immediate
right position, while (-1,0)
the left one.
Note that the inclusion of a relative position to the dependence also implies
its opposite direction is not conditionally independent (commutativeness of
dependence), but only one is included in the mrfi
object.
To illustrate that, a nearest neighbor dependence structure can be specified by:
mrfi(1)
Note that it only includes the positions (1,0)
and (0,1)
, but when
visualizing it, for example, mrf2d
understands the opposite directions
are also conditionally dependent, as in
plot(mrfi(1))
.
Rmat
A 2-column matrix
where each row represents a relative position
of interaction.
If a position in positions
is already included due to the
max_norm
and norm_type
specification, the second ocurrence is ignored.
The same is valid for repeated or opposite positions in positions
.
A paper with detailed description of the package can be found at doi: 10.18637/jss.v101.i08 .
plot(mrfi(max_norm = 2, norm_type = "1"))
plot(mrfi(max_norm = 2, norm_type = "m"))
plot(mrfi(max_norm = 2, norm_type = "1", positions = list(c(4,4))))
as.list(mrfi(1))
#> [[1]]
#> [1] 1 0
#>
#> [[2]]
#> [1] 0 1
#>
mrfi(1)[[1]]
#> [[1]]
#> [1] 1 0
#>
mrfi(2)[[1:3]]
#> [[1]]
#> [1] 1 0
#>
#> [[2]]
#> [1] 2 0
#>
#> [[3]]
#> [1] -1 1
#>
mrfi(1)
#> 2 interacting positions.
#> rx ry
#> 1 0
#> 0 1
rpositions(list(c(1,0), c(0,1)))
#> 2 interacting positions.
#> rx ry
#> 1 0
#> 0 1
mrfi(2)
#> 6 interacting positions.
#> rx ry
#> 1 0
#> 2 0
#> -1 1
#> 0 1
#> 1 1 ... and 1 more.
mrfi(2, norm_type = "m")
#> 12 interacting positions.
#> rx ry
#> 1 0
#> 2 0
#> -2 1
#> -1 1
#> 0 1 ... and 7 more.
mrfi(1, positions = list(c(4,4), c(-4,4)))
#> 4 interacting positions.
#> rx ry
#> 1 0
#> 0 1
#> 4 4
#> -4 4
#Repeated positions are handled automatically
mrfi(1, positions = list(c(1,0), c(2,0)))
#> 3 interacting positions.
#> rx ry
#> 1 0
#> 0 1
#> 2 0
mrfi(1) + c(2,0)
#> 3 interacting positions.
#> rx ry
#> 1 0
#> 0 1
#> 2 0
mrfi(1) - c(1,0)
#> 1 interacting positions.
#> rx ry
#> 0 1
mrfi(1) + mrfi(0, positions = list(c(2,0)))
#> 3 interacting positions.
#> rx ry
#> 1 0
#> 0 1
#> 2 0
mrfi(2) - mrfi(1)
#> 4 interacting positions.
#> rx ry
#> 2 0
#> -1 1
#> 1 1
#> 0 2