generate.grf.object: Create object used for approximate computations with a...

Description Usage Arguments Details Value Author(s) Examples

View source: R/generate-grf-object.R

Description

Creates a list containing the elements necessary for doing essential computations with the stationary GRF approximation.

Usage

1
2
3
4
5
generate.grf.object(x.lower = -1, x.upper = 1, y.lower = -1,
  y.upper = 1, resolution.x = 100, resolution.y = 100,
  range.parameter = 1, scale.parameter = 1, strength.parameter = 0,
  direction.parameter = 0, initial.seed = 0, params = NULL,
  num.functions = NULL, function.names = NULL)

Arguments

x.lower, x.upper, y.lower, y.upper

Specifies the boundaries of the rectangular region that the GRF is defined on.

resolution.x, resolution.y

The number of grid cells used for the regular grid, in the x- and y-direction, respectively.

range.parameter

The range is a positive number. A small range gives functions that tend to have more variation over shorter distances, while a long range leads to functions where the value changes more gradually. The reciprocal 1/range.parameter has a similar interpretation as the frequency parameter in Perlin/simplex noise. In technical terms: The range is the distance at which the correlation between two locations is approximately 0.14.

scale.parameter

The scale is a positive number that controls the scale of the functions. Setting scale.parameter = a is equivalent to setting scale.parameter = 1 and then multiplying the functions by a. If you plan on using evaluate.grf with rescale = TRUE or uniform.transform = TRUE, this parameter can be ignored. In more technical terms, this is the marginal standard deviation of the GRF.

strength.parameter, direction.parameter

These parameters are used to specify a range that depends on direction. If range.parameter = r, strength.parameter = p and direction.parameter = theta, then the range is r*(1+p) along the direction given by theta, and r along the direction perpendicular to theta. direction.parameter is the angle formed with the x-axis measured in radians.

initial.seed

The initial seed value used when generating functions.

params

Optional, a list containing all of the above parameters.

num.functions

The number of functions to initialize the object with.

function.names

The names of the functions to initialize the object with.

Details

If the object is to be initialized with functions, either num.functions or function.names must be specified.

Value

An object (technically, a list) containing:

model.components

A list containing the components defining the GRF: The precision matrix Q, and the Cholesky decomposition of Q, chol.object. The latter is computed and added when a function is added to the GRF object.

grid

A (resolution.x*resolution.y) x 2 matrix containing the center coordinates of the regular grid that the approximation is defined on.

initial.seed

The initial seed value used when generating functions.

params

A list of the remaining input parameters listed above (except num.functions and function.names).

Author(s)

Mathias Isaksen mathiasleanderi@gmail.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
library(GRFics)
# Prepare GRF object on the square [-1, 1]^2 on a 25 x 25 grid
grf.object = generate.grf.object(-1, 1, -1, 1, 25, 25,
                                 strength.parameter = 1,
                                 direction.parameter = pi/4,
                                 function.names = "Original",
                                 initial.seed = 1000)
# Extract data frame containing the 25 x 25 grid coordinates and
# the value of the GRF in each grid cell.
original.df = get.function.df(grf.object)
# Interpolate GRF on finer grid for comparison
interp.locations = generate.grid.centers(-1, 1, -1, 1, 500, 500)
interp.df = evaluate.grf(interp.locations, grf.object, rescale.method = "none", return.df = TRUE)
interp.df$name = "Interpolation"

library(ggplot2)
ggplot()+
  geom_raster(data = rbind(original.df, interp.df),
              aes(x = x, y = y, fill = z))+
  coord_fixed()+
  facet_grid(cols = vars(name))

# Create and plot vector field, using the GRF to specify direction
vector.df = generate.grid.centers(-1, 1, -1, 1, 25, 25)
# Getting an angle that is between 0 and 2*pi. Using rescale.method = "uniform" ensures that every direction is equally represented.
vector.df$theta = 2*pi*evaluate.grf(vector.df, grf.object, rescale.method = "uniform")
vector.df$vx = 0.06*cos(vector.df$theta)
vector.df$vy = 0.06*sin(vector.df$theta)
# Plot of random vector field (should be viewed in a large window)
ggplot()+
  geom_segment(data = vector.df, aes(x = x-vx/2, xend = x+vx/2,
                                     y = y-vy/2, yend = y+vy/2),
               arrow = arrow(length = unit(0.012, "npc")))+
  coord_fixed()

mathiasisaksen/GRFics documentation built on May 20, 2021, 5:55 a.m.