osnnet: Observation Specific Neural Networks

Description Usage Arguments Details Value References See Also Examples

View source: R/osnnet.R

Description

A localized version of single-hidden-layer neural networks, possibly with skip-layer connections.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
osnnet(x, ...)

## S3 method for class 'formula'
osnnet(formula, data, ..., subset, na.action,
  contrasts = NULL)

## Default S3 method:
osnnet(x, y, wf = c("biweight", "cauchy", "cosine",
  "epanechnikov", "exponential", "gaussian", "optcosine", "rectangular",
  "triangular"), bw, k, nn.only = TRUE, size, Wts, mask = rep(TRUE,
  length(wts)), linout = FALSE, entropy = FALSE, softmax = FALSE,
  censored = FALSE, skip = FALSE, rang = 0.7, decay = 0, maxit = 100,
  trace = TRUE, MaxNWts = 1000, abstol = 1e-04, reltol = 1e-08,
  reps = 1, ...)

Arguments

x

(Required if no formula is given as principal argument.) A matrix or data.frame or Matrix containing the explanatory variables.

formula

A formula of the form response ~ x1 + x2 + ....

data

A data.frame from which variables specified in formula are to be taken.

subset

An index vector specifying the cases to be used in the training sample. (NOTE: If given, this argument must be named.)

na.action

A function to specify the action to be taken if NAs are found. The default action is for the procedure to fail. An alternative is na.omit, which leads to rejection of cases with missing values on any required variable. (NOTE: If given, this argument must be named.)

contrasts

A list of contrasts to be used for some or all of the factors appearing as variables in the model formula.

y

(Required if no formula is given as principal argument.) A matrix or data.frame of target values for examples.

wf

A window function which is used to calculate weights that are introduced into the fitting process. Either a character string or a function, e.g. wf = function(x) exp(-x). For details see the documentation for wfs.

bw

(Required only if wf is a string.) The bandwidth parameter of the window function. (See wfs.)

k

(Required only if wf is a string.) The number of nearest neighbors of the decision boundary to be used in the fitting process. (See wfs.)

nn.only

(Required only if wf is a string indicating a window function with infinite support and if k is specified.) Should only the k nearest neighbors or all observations receive positive weights? (See wfs.)

size

Number of units in the hidden layer. Can be zero if there are skip-layer units.

Wts

Initial parameter vector. If missing chosen at random.

mask

Logical vector indicating which parameters should be optimized (default all).

linout

Switch for linear output units. Default logistic output units.

entropy

Switch for entropy (= maximum conditional likelihood) fitting. Default by least-squares.

softmax

Switch for softmax (log-linear model) and maximum conditional likelihood fitting. linout, entropy, softmax and censored are mutually exclusive.

censored

A variant on softmax, in which non-zero targets mean possible classes. Thus for softmax a row of (0, 1, 1) means one example each of classes 2 and 3, but for censored it means one example whose class is only known to be 2 or 3.

skip

Switch to add skip-layer connections from input to output.

rang

Initial random weights on [-rang, rang]. Value about 0.5 unless the inputs are large, in which case it should be chosen so that rang * max(|x|) is about 1.

decay

Parameter for weight decay. Default 0.

maxit

Maximum number of iterations. Default 100.

trace

Switch for tracing optimization. Default TRUE.

MaxNWts

The maximum allowable number of weights. There is no intrinsic limit in the code, but increasing MaxNWts will probably allow fits that are very slow and time-consuming.

abstol

Stop if the fit criterion falls below abstol, indicating an essentially perfect fit.

reltol

Stop if the optimizer is unable to reduce the fit criterion by a factor of at least 1 - reltol.

reps

Neural networks are fitted repeatedly (reps times) for different initial values and the solution with largest likelihood value is kept. Defaults to 1. (reps larger one does not make sense if Wts is specified.)

...

Arguments passed to or from other methods.

Details

This is a localized version of neural networks where a neural network is fitted for each test observation based on the training data near the trial point. It is based on the function nnet from package nnet.

The name of the window function (wf) can be specified as a character string. In this case the window function is generated internally in predict.osnnet. Currently supported are "biweight", "cauchy", "cosine", "epanechnikov", "exponential", "gaussian", "optcosine", "rectangular" and "triangular".

Moreover, it is possible to generate the window functions mentioned above in advance (see wfs) and pass them to osnnet.

Any other function implementing a window function can also be used as wf argument. This allows the user to try own window functions. See help on wfs for details.

If the predictor variables include factors, the formula interface must be used in order to get a correct model matrix.

Value

An object of class "osnnet.formula" or "osnnet", a list containing the following components:

x

A matrix containing the explanatory variables.

y

If argument y was a factor a class inicator matrix, otherwise a matrix that contains y unchanged.

...
mask

The mask vector used.

maxit

The maxit argument used.

trace

The trace argument used.

abstol

The abstol argument used.

reltol

The reltol argument used.

lev

If y is a factor the class labels (levels of y).

wf

The window function used. Always a function, even if the input was a string.

bw

(Only if wf is a string or was generated by means of one of the functions documented in wfs.) The bandwidth used, NULL if bw was not specified.

k

(Only if wf is a string or was generated by means of one of the functions documented in wfs.) The number of nearest neighbors used, NULL if k was not specified.

nn.only

(Logical. Only if wf is a string or was generated by means of one of the functions documented in wfs and if k was specified.) TRUE if only the k nearest neighbors recieve a positive weight, FALSE otherwise.

adaptive

(Logical.) TRUE if the bandwidth of wf is adaptive to the local density of data points, FALSE if the bandwidth is fixed.

variant

(Only if wf is a string or one of the window functions documented in wfs is used, for internal use only). An integer indicating which weighting scheme is implied by bw, k and nn.only.

call

The (matched) function call.

References

Czogiel, I., Luebke, K., Zentgraf, M. and Weihs, C. (2007), Localized linear discriminant analysis. In Decker, R. and Lenz, H.-J., editors, Advances in Data Analysis, volume 33 of Studies in Classification, Data Analysis, and Knowledge Organization, pages 133–140, Springer, Berlin Heidelberg.

Ripley, B. D. (1996) Pattern Recognition and Neural Networks. Cambridge.

Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.

See Also

predict.osnnet, nnet.

Other observation_specific nnet: predict.osnnet

Other observation_specific nnet: predict.osnnet

Other observation_specific nnet: predict.osnnet

Examples

1
2
3
4
samp <- c(sample(1:50,25), sample(51:100,25), sample(101:150,25))
fit <- osnnet(Species ~ ., data = iris, subset = samp, size = 2, 
               rang = 0.1, maxit = 200, bw = 0.5, reps = 2)
pred <- predict(fit)

schiffner/locClass documentation built on May 29, 2019, 3:39 p.m.