Learn R Programming

SemiSupervised (version 1.0)

AnchorGraph: Generate an Anchor Graph from an n x p data matrix

Description

The AnchorGraph function is designed for:

1) Graph generation: creates an ‘anchor’ graph object.

2) Graph modification: modify an existing ‘anchor’ graph using the fit.g argument, which is used primarily for predicting new observations.

The getAnchor function is a wrapper to kmeans clustering.

Usage

AnchorGraph(x,metric="cosine",anchor=NULL,fit.g=NULL,control=SemiSupervised.control())
getAnchor(x,control)

Arguments

x

the n x p ‘vector’, ‘matrix’ or ‘data.frame’.

fit.g

an existing ‘anchor’ object to be updated with new observations given by argument x.

anchor

an optional matrix of user provided anchor points. If NULL then link{kmeans} is used to generate the anchors.

metric

the metric either cosine or sqDist for graph construction.

control

the SemiSupervised.control is used to initialize various LAE settings. This control should also be used when executing the agraph function but is not enforced.

Value

Z

the n x k Z-matrix where each row has at most sfrac (refer to SemiSupervised.control) non-zero entries.

rL

reduced Laplacian matrix.

g.scaling

the scaling used to scale the x data prior to graph construction.

anchor

the anchor points.

metric

the metric.

Details

The AnchorGraph function creates an informal S3-object of class ‘anchor’. This is required as input to the S4 generic function agraph when using the ‘anchor’ version or agraph.default version.

This call is performed in the ‘formula’, ‘data.frame’, ‘matrix’, or ‘vector’ S4 generic instances of agraph.

See Also

agraph, aG

Examples

Run this code
# NOT RUN {
## Set up Sonar data with 20% labeled
library(mlbench)
data(Sonar)

n=dim(Sonar)[1]
p=dim(Sonar)[2]

nu=0.2
set.seed(100)
L=sort(sample(1:n,ceiling(nu*n)))
U=setdiff(1:n,L)

y.true<-Sonar$Class
Sonar$Class[U]=NA

g.agraph1<-agraph(Class~.,data=Sonar) 

##The following gives an equivalent output to the g.agraph1<-agraph(Class~.,data=Sonar) call.
# }
# NOT RUN {
ctrl<-SemiSupervised.control()
g<-AnchorGraph(x.scaleL(Sonar[,-p],L),control=ctrl)
g.agraph2<-agraph(Class~.+aG(g),data=Sonar,control=ctrl) 

## For performance comparison check against agraph with graph only
tab=table(fitted(g.agraph2)[U],y.true[U])
1-sum(diag(tab))/sum(tab)

## Fit agraph to Sonar but graph only 
g.agraph3<-agraph(Class~aG(g),data=Sonar,control=ctrl) 
g.agraph3
tab=table(fitted(g.agraph3)[U],y.true[U])
1-sum(diag(tab))/sum(tab)
# }

Run the code above in your browser using DataLab