Skip to content

Commit

Permalink
docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
jumutc committed Sep 28, 2015
1 parent 3f24137 commit 8f5c0f6
Showing 1 changed file with 46 additions and 46 deletions.
92 changes: 46 additions & 46 deletions docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Examples & notebooks
Prerequisites
~~~~~~~~~~~~~~

Please refer to `Julia downloads <http://julialang.org/downloads>`_ page for installing **Julia** language and all dependencies. The instructions for installing the **SALSA** package can be found :ref:`here <installation>`. Some additional plotting and data management packages might be required to run examples below (like ``Winston``, ``Gadfly`` or ``DataFrames``). If you prefer Python-style notebooks please refer to `Project Jupyter <http://jupyter.org>`_ and `IJulia <http://github.com/JuliaLang/IJulia.jl>`_ package for instructions. In this section we provide code snippets which can be easily copied into the **Julia** console or **Jupyter** notebook.
Please refer to `Julia downloads <http://julialang.org/downloads>`_ page for installing **Julia** language and all dependencies. The instructions for installing the **SALSA** package can be found :ref:`here <installation>`. Some additional plotting and data management packages might be required to run examples below (like ``Winston``, ``Gadfly`` or ``DataFrames``). If you prefer Python-style notebooks please refer to the `Project Jupyter <http://jupyter.org>`_ and `IJulia <http://github.com/JuliaLang/IJulia.jl>`_ package for instructions. In this section we provide code snippets which can be easily copied into the **Julia** console or **Jupyter** notebook.


Advanced Classification
Expand All @@ -14,39 +14,39 @@ This example provides a use-case for nonlinear classification using :doc:`Nystr

.. code-block:: julia
using SALSA, MAT
ripley = matread(joinpath(Pkg.dir("SALSA"), "data", "ripley.mat")); srand(123);
model = SALSAModel(NONLINEAR, PEGASOS(), LOGISTIC, validation_criterion=AUC(100));
model = salsa(ripley["X"], ripley["Y"], model, ripley["Xt"]);
range1 = linspace(-1.5,1.5,200);
range2 = linspace(-0.5,1.5,200);
grid = [[i j] for i in range1, j in range2];
diff1 = range1[2] - range1[1];
diff2 = range2[2] - range2[1];
Xgrid = foldl(vcat, grid);
Xtest = ripley["Xt"];
yhat = model.output.Ytest;
yplot = map_predict_latent(model,Xgrid);
yplot = yplot - minimum(yplot);
yplot = 2*(yplot ./ maximum(yplot)) - 1;
using DataFrames
df = DataFrame();
df[:Xmin] = Xgrid[:,1][:];
df[:Ymin] = Xgrid[:,2][:];
df[:Xmax] = Xgrid[:,1][:] + diff1;
df[:Ymax] = Xgrid[:,2][:] + diff2;
df[:class] = yplot[:];
using Gadfly
set_default_plot_size(20cm, 20cm);
plot(layer(x=Xtest[yhat.>0,1], y=Xtest[yhat.>0,2], Geom.point, Theme(default_color=colorant"orange")),
layer(x=Xtest[yhat.<0,1], y=Xtest[yhat.<0,2], Geom.point, Theme(default_color=colorant"black")),
layer(df, x_min="Xmin", x_max="Xmax", y_min="Ymin", y_max="Ymax", color="class", Geom.rectbin))
using SALSA, MAT

ripley = matread(joinpath(Pkg.dir("SALSA"), "data", "ripley.mat")); srand(123);
model = SALSAModel(NONLINEAR, PEGASOS(), LOGISTIC, validation_criterion=AUC(100));
model = salsa(ripley["X"], ripley["Y"], model, ripley["Xt"]);

range1 = linspace(-1.5,1.5,200);
range2 = linspace(-0.5,1.5,200);
grid = [[i j] for i in range1, j in range2];
diff1 = range1[2] - range1[1];
diff2 = range2[2] - range2[1];

Xgrid = foldl(vcat, grid);
Xtest = ripley["Xt"];

yhat = model.output.Ytest;
yplot = map_predict_latent(model,Xgrid);
yplot = yplot - minimum(yplot);
yplot = 2*(yplot ./ maximum(yplot)) - 1;

using DataFrames
df = DataFrame();
df[:Xmin] = Xgrid[:,1][:];
df[:Ymin] = Xgrid[:,2][:];
df[:Xmax] = Xgrid[:,1][:] + diff1;
df[:Ymax] = Xgrid[:,2][:] + diff2;
df[:class] = yplot[:];

using Gadfly
set_default_plot_size(20cm, 20cm);
plot(layer(x=Xtest[yhat.>0,1], y=Xtest[yhat.>0,2], Geom.point, Theme(default_color=colorant"orange")),
layer(x=Xtest[yhat.<0,1], y=Xtest[yhat.<0,2], Geom.point, Theme(default_color=colorant"black")),
layer(df, x_min="Xmin", x_max="Xmax", y_min="Ymin", y_max="Ymax", color="class", Geom.rectbin))

.. image:: ../ripley.png
:alt: Advanced Classification Example
Expand All @@ -60,23 +60,23 @@ This example provides a use-case for regression using :doc:`Nyström approximati

.. code-block:: julia
using SALSA, MLBase
using SALSA, MLBase

sinc(x) = sin(x)./x;
X = linspace(0.1,20,100)'';
Xtest = linspace(0.1,20,200)'';
Y = sinc(X);
srand(1234);
sinc(x) = sin(x)./x;
X = linspace(0.1,20,100)'';
Xtest = linspace(0.1,20,200)'';
Y = sinc(X);
srand(1234);

model = SALSAModel(NONLINEAR, PEGASOS(), LEAST_SQUARES,
model = SALSAModel(NONLINEAR, PEGASOS(), LEAST_SQUARES,
cv_gen=Nullable{CrossValGenerator}(LOOCV(100)),
validation_criterion=MSE(), process_labels=false, subset_size=5.0);
model = salsa(X, Y, model, Xtest);
model = salsa(X, Y, model, Xtest);

using Gadfly
set_default_plot_size(20cm, 20cm);
plot(layer(x=Xtest[:], y=sinc(Xtest), Geom.point),
layer(x=Xtest[:], y=model.output.Ytest, Geom.line, Theme(default_color=colorant"orange")))
using Gadfly
set_default_plot_size(20cm, 20cm);
plot(layer(x=Xtest[:], y=sinc(Xtest), Geom.point),
layer(x=Xtest[:], y=model.output.Ytest, Geom.line, Theme(default_color=colorant"orange")))


.. image:: ../sinc.png
Expand Down

0 comments on commit 8f5c0f6

Please sign in to comment.