FLXMCLnnet: Mixtures of Neural Networks

Description Usage Arguments Value See Also Examples

View source: R/FLXMCLnnet.R

Description

This is a model driver for flexmix implementing mixtures of Neural Netowrks.

Usage

1
2
3
4
5
6
FLXMCLnnet(formula = . ~ ., size, reps = 1, skip = FALSE, Wts = NULL,
  ...)

## S4 method for signature 'FLXMCLnnet'
FLXgetModelmatrix(model, data, formula, lhs = TRUE,
  ...)

Arguments

formula

A formula which is interpreted relative to the formula specified in the call to flexmix using update.formula. Only the left-hand side (response) of the formula is used. Default is to use the original flexmix model formula.

size

Size of hidden layer, see nnet.

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.)

skip

Logical. Should the neural net include skip layer connections? Defaults to FALSE, see also nnet.

Wts

Initial parameter vector. For convenience and since number of nodes in networks can vary, Wts does not need to be of correct length. Wts should be a rather long vector. Depending on the number of nodes and connections in the network it is recycled or only a subset is used.

...

Further arguments to and from other methods, especially to nnet.

Value

Returns an object of class FLXMCLnnet inheriting from FLXMCL.

See Also

Other mixtures nnet: FLXMCL-class

Other mixtures nnet: FLXMCL-class

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
library(benchData)
data <- flashData(1000)
data$x <- scale(data$x)
grid <- expand.grid(x.1=seq(-6,6,0.2), x.2=seq(-4,4,0.2))

cluster <- kmeans(data$x, center = 2)$cluster
model <- FLXMCLnnet(size = 1, trace = TRUE, reps = 5, decay = 0.1)
fit <- flexmix(y ~ ., data = as.data.frame(data), concomitant = FLXPmultinom(~ x.1 + x.2), model = model, cluster = cluster)

## prediction for single component models without aggregation
pred.grid <- predict(fit, newdata = grid)
image(seq(-6,6,0.2), seq(-4,4,0.2), matrix(pred.grid[[1]][,1], length(seq(-6,6,0.2))))
contour(seq(-6,6,0.2), seq(-4,4,0.2), matrix(pred.grid[[1]][,1], length(seq(-6,6,0.2))), add = TRUE)
points(data$x, pch = as.character(data$y))

image(seq(-6,6,0.2), seq(-4,4,0.2), matrix(pred.grid[[2]][,1], length(seq(-6,6,0.2))))
contour(seq(-6,6,0.2), seq(-4,4,0.2), matrix(pred.grid[[2]][,1], length(seq(-6,6,0.2))), add = TRUE)
points(data$x, pch = as.character(data$y))

## prediction with aggregation depending on membership in mixture components
pred.grid <- mypredict(fit, newdata = grid, aggregate = TRUE)
image(seq(-6,6,0.2), seq(-4,4,0.2), matrix(pred.grid[[1]][,1], length(seq(-6,6,0.2))))
contour(seq(-6,6,0.2), seq(-4,4,0.2), matrix(pred.grid[[1]][,1], length(seq(-6,6,0.2))), add  = TRUE)
points(data$x, pch = as.character(data$y))

## local membership
loc.grid <- prior(fit, newdata = grid)
contour(seq(-6,6,0.2), seq(-4,4,0.2), matrix(loc.grid[,1], length(seq(-6,6,0.2))), add  = TRUE)

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