Description Usage Arguments Details Value Note Author(s) See Also Examples
View source: R/SemiSupervised-external.R
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.
1 2 | AnchorGraph(x,metric="cosine",anchor=NULL,fit.g=NULL,control=SemiSupervised.control())
getAnchor(x,control)
|
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 |
metric |
the metric either cosine or sqDist for graph construction. |
control |
the |
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
.
Z |
the n x k Z-matrix where each row has at most sfrac (refer to |
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. |
An S3-object was sufficient for our purposes. There is no need for the overhead or flexibility of a S4-class which is why it is programmed this way.
Mark Vere Culp
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 | ## 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.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.