Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kudkudak committed Apr 30, 2015
1 parent a255957 commit b28926d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 22 deletions.
54 changes: 37 additions & 17 deletions R/svm.R
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ evalqOnLoad({

}else{
t <- predict(x, X)
true_target <- NULL
}
labels <- levels(as.factor(t))

Expand All @@ -615,8 +616,11 @@ evalqOnLoad({
}
colnames(df) <- c("X1", "X2") # This is even worse
df['prediction'] <- as.factor(t)
levels(true_target) <- x$levels
df['label'] <- true_target

if(!is.null(true_target)){
levels(true_target) <- x$levels
df['label'] <- true_target
}

#4. Prepare data for plotting
if (obj$areExamplesWeighted()) {
Expand Down Expand Up @@ -671,23 +675,39 @@ evalqOnLoad({
grid['prediction'] <- prediction



pl <- ggplot()+
geom_tile(data=grid, aes(x=x,y=y, fill=prediction, alpha=.5)) +
theme(legend.position="none") +
scale_fill_brewer(palette="Set1") +
scale_alpha_identity() +
geom_point(data=df, aes(X1, X2, size=sizes, colour=prediction, shape=label)) +
scale_colour_brewer(palette="Set1") +
scale_size

if(!is.null(true_target)){
pl <- ggplot()+
geom_tile(data=grid, aes(x=x,y=y, fill=prediction, alpha=.5)) +
theme(legend.position="none") +
scale_fill_brewer(palette="Set1") +
scale_alpha_identity() +
geom_point(data=df, aes(X1, X2, size=sizes, colour=prediction, shape=label)) +
scale_colour_brewer(palette="Set1") +
scale_size
}
else{
pl <- ggplot()+
geom_tile(data=grid, aes(x=x,y=y, fill=prediction, alpha=.5)) +
theme(legend.position="none") +
scale_fill_brewer(palette="Set1") +
scale_alpha_identity() +
geom_point(data=df, aes(X1, X2, size=sizes, colour=prediction)) +
scale_colour_brewer(palette="Set1") +
scale_size
}
}else{
warning("Only limited plotting is currently supported for multidimensional data")

pl <- ggplot()+
geom_point(data=df, aes(X1, X2, size=sizes, colour=prediction, shape=label)) +
scale_colour_brewer(palette="Set1") +
scale_size
if(!is.null(true_target)){
pl <- ggplot()+
geom_point(data=df, aes(X1, X2, size=sizes, colour=prediction, shape=label)) +
scale_colour_brewer(palette="Set1") +
scale_size
}else{
pl <- ggplot()+
geom_point(data=df, aes(X1, X2, size=sizes, colour=prediction)) +
scale_colour_brewer(palette="Set1") +
scale_size
}
}

# Add line
Expand Down
7 changes: 7 additions & 0 deletions demo/samples/compile.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ render("gng.wine.R", output_options=c(highlight=highlighting))
render("gng.optimized.R", output_options=c(highlight=highlighting))
render("gng.mouse.R", output_options=c(highlight=highlighting))


render("cec.basic.R", output_options=c(highlight=highlighting))
render("cec.ellipse.R", output_options=c(highlight=highlighting))
render("cec.T.dataset.R", output_options=c(highlight=highlighting))

# THIS IS REALLY TRICKY - we generate not self contained files
# and then link them to gmum.r FTP server

scripts <- list.files(".", pattern = glob2rx("*.R"), full.names = FALSE)
# NOTE: Run once for each script online!

# TO RUN FOR PART REPLACE SCRIPTS WITH LIST OF FILES YOU WISH TO UPDATE
run.cmds <- function(script.name){
file.folder <- paste(substr(script.name, 1, nchar(script.name)-2), "_files", sep="")
Expand Down
9 changes: 4 additions & 5 deletions demo/samples/gng.mouse.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@ library(ggplot2)

# Load our library dataset
data(cec_mouse_1_spherical)
cec.mouse.1.spherical <- input

# Train GNG model and find centroids of the resulting graph
g <- GNG(cec.mouse.1.spherical, max.nodes=50)
g <- GNG(cec.mouse1spherical, max.nodes=50)

# GNG aims at making it easy to work with its graph.
# Here we will predict closest centroid
mouse.centr <- centroids(g)

# Now we can plot results to see decision boundary for assigning node to centroid
m = as.data.frame(cec.mouse.1.spherical)
m = as.data.frame(cec.mouse1spherical)
colnames(m) = c("x", "y")

x_col <- cec.mouse.1.spherical[,1]
y_col <- cec.mouse.1.spherical[,2]
x_col <- cec.mouse1spherical[,1]
y_col <- cec.mouse1spherical[,2]

x_max <- max(x_col)
x_min <- min(x_col)
Expand Down
1 change: 1 addition & 0 deletions demo/samples/gng.online.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ labels <- round(runif(10000)*3)
# Insert dataset with labels
insertExamples(gng, ex, labels)


# Run algorithm in parallel
# (GNG will be running in separate thread!)
run(gng)
Expand Down

0 comments on commit b28926d

Please sign in to comment.