## Special distances for `adoption`

### Description

Distance function given here are defined for the sole use within the model definition for `adoption`. These functions increase the processing speed in `adoption`.

THESE FUNCTIONS SHOULD NEVER BE USED OUTSIDE THE MODEL DEFINITION FOR `adoption`. THEY SHOULD BE USED ONLY IN THE SAME WAY AS GIVEN IN THE EXAMPLES OF `adoption`, WITHOUT ANY MODIFICATIONS!

### Usage

```  GoldenbergDistance(param, dist, W, Goldenberg_C)
VarDistance(param, dist, W)
```

### Arguments

 `param` the weight parameter. For the Goldenberg distance it has (at least) two parameters; for the VAR distance it has one parameter. `dist` the matrix for Euclidean distances between the coordinates that are given by the function `coord` in the model definition. `W` A square matrix of size `m`, where `m` is the market size. Because of this argument, (nearly) any arbitrary use of the distance function will crash the whole system! Within adoption the correct size of the matrix will be passed. `Goldenberg_C` Some large constant, e.g. 1e6

### Details

DO NOT USE THESE FUNCTIONS OUTSIDE THE MODEL DEFINITIONS FOR `adoption`.

`NULL`

### Note

Since these distance function modify the values of the argument `W` by reference, the use of these distance functions will nearly always lead to a system crash if these functions are used wrongly. However, it is save to use them in the model definition for defining the weight function, e.g.,

`weight = function(param, dist, W)`
` GoldenbergDistance(param, dist, W, Goldenberg_C)`

which equivalent to (but much faster than)

`weight = function(param, dist) { `
` neighbour <- dist <= param[1] `
` diag(neighbour) <- 0 `
` neighbour / Goldenberg_C `
`}`

Note that the weight is, in the first piece of code, defined with an additional argument `W` more, which refers to a matrix of correct size in `adoption`.

### Author(s)

Martin Schlather, schlather@math.uni-mannheim.de, http://ms.math.uni-mannheim.de

### References

• N.N., Schlather, M., N.N., (2019) Toward a Generalized Adoption Modeling Framework. Manuscript.

• Schlather, M. (2018) Introduction to the Gui of the R package 'adoption'. Technical Report. Attached with the package.

### Examples

```
Goldenberg <- list( ## model by Goldenberg, Libai, Muller (2010)
m = 1000L,
repetitions=10L,
dt = 1,
relative.instance = 0.2,
SOCIAL = c(1, 5, 5),
PRIVATE = c(5, 1, 5),
Ic.start = function(param, m, rep, ...) {
m * rnorm(m * rep, param[1], prod(param[1:2]))
},
Ic = function(param, Nt, m, start) {
Inf * (2 * (Nt > start) - 1) ## start has size m * rep, i.e. Nt is
##                                   recycled
},
Ic.param = c("mean h" = 0.02,
"sigma" = 0.4),
Ic.param.min = c(0.005, 0.08),
Ic.param.max = c(0.1, 1.5),

coord = function(param, m) {
if (param[1] == 1) as.matrix(1:m)
else {
m2 <- ceiling(sqrt(m))
m3 <- ceiling(m / m2)
as.matrix(expand.grid(1:m2, 1:m3))[1:m, ]
}},
coord.param = c(dim = 2),
weight =  function(param, dist, W) {
GoldenbergDistance(param, dist, W, 1e6)
},

weight.param.min = 1.5,
weight.param.max = 1.5,
weight.param = c("max distance d"=1.5),

Utrafo = function(U, threshold, ...) 1e6 * as.double(U>=threshold),

Uthreshold = 0, ## here: constant for any people; we might
Uthreshold.min = 0,
Uthreshold.max = 0,
Up.start = function(param, m, rep) rep(-1, m * rep),
Up = function(param, m, nT, rep, ...) {
pmax(-1e6 + 1,
-log(runif(nT * rep * m)/(1-param[1])) / log(1-param[2]))
},
Up.param = c(prob_a=0.1, prob_b=0.1),
Up.param.min = c(0.005, 0.05),
Up.param.max = c(0.99, 0.99),

"MAX/PLUS OPERATORS" = rep(5, 3),
alpha = c("alpha_1"=0, "alpha_2"=1),
alpha.min = c(0, 1),
alpha.max = c(0, 1),
beta = c("beta_1"=1, "beta_2"=1),
beta.min = c(1, 1),
beta.max = c(1, 1),
gamma = c("gamma_1"=0.5, "gamma_2"=0.5),
gamma.min = c(0.5, 0.5),
gamma.max = c(0.5, 0.5)
)

RFoptions(cores=2)  ## see package RandomFieldsUtils