Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup python modular graphical examples #3045

Merged
merged 1 commit into from
Mar 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
from PyQt4.QtGui import *

import matplotlib
from matplotlib import mpl
from matplotlib.colorbar import make_axes, Colorbar
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gives import error so removing this.

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NavigationToolbar2QTAgg replaced by NavigationToolbar2QT as the former gives import error.


from modshogun import *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
from numpy import *

import matplotlib
from matplotlib import mpl
from matplotlib.colorbar import make_axes, Colorbar
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure

from modshogun import *
Expand Down Expand Up @@ -409,4 +408,3 @@ def main():

if __name__ == "__main__":
main()

Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
from PyQt4.QtGui import *

import matplotlib
from matplotlib import mpl
from matplotlib.colorbar import make_axes, Colorbar
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure

from modshogun import *
from modshogun import KernelMeanMatching
from modshogun import *
from modshogun import Math
import util

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@
from PyQt4.QtGui import *

import matplotlib
from matplotlib import mpl
from matplotlib.colorbar import make_axes, Colorbar
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure

from modshogun import *
from modshogun import *
from modshogun import *
import util

Expand Down Expand Up @@ -132,7 +129,7 @@ def train_svm(self):
svm.set_epsilon(1e-2)

x, y, z = util.compute_output_plot_isolines(svm, gk, train)
plt=self.axes.pcolor(x, y, z, shading='interp')
plt=self.axes.pcolor(x, y, z)
CS=self.axes.contour(x, y, z, [-1,0,1], linewidths=1, colors='black', hold=True)
#CS=self.axes.contour(x, y, z, linewidths=1, colors='black', hold=True)
#CS=self.axes.contour(x, y, z, 5, linewidths=1, colors='black', hold=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shading is deprecated in matplotlib so removing this parameter. No visual changes in the plots.

/usr/local/lib/python2.7/dist-packages/matplotlib/cbook.py:137: MatplotlibDeprecationWarning: The shading option was deprecated in version 1.2. Use edgecolors instead.
  warnings.warn(message, mplDeprecation, stacklevel=1)

Expand All @@ -142,7 +139,7 @@ def train_svm(self):
self.axes.set_ylim((-5,5))

cmap = matplotlib.cm.jet
norm = mpl.colors.Normalize(numpy.min(z), numpy.max(z))
norm = matplotlib.colors.Normalize(numpy.min(z), numpy.max(z))
print CS.get_clim()
if not self.cax:
self.cax, kw = make_axes(self.axes)
Expand All @@ -152,7 +149,7 @@ def train_svm(self):
# standalone colorbar. There are many more kwargs, but the
# following gives a basic continuous colorbar with ticks
# and labels.
cb1 = mpl.colorbar.ColorbarBase(self.cax, cmap=cmap,
cb1 = matplotlib.colorbar.ColorbarBase(self.cax, cmap=cmap,
norm=norm)
self.canvas.draw()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@
from PyQt4.QtGui import *

import matplotlib
from matplotlib import mpl
from matplotlib.colorbar import make_axes, Colorbar
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure

from modshogun import *
from modshogun import *
from modshogun import *

class Form(QMainWindow):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from numpy import array,meshgrid,reshape,linspace,min,max
from numpy import concatenate,transpose,ravel
from modshogun import *
from modshogun import *
from modshogun import *
import util

util.set_title('KernelRidgeRegression')
Expand All @@ -18,10 +16,10 @@
neg=util.get_realdata(False)
plot(neg[0,:], neg[1,:], "b.")

# train svm
# train krr
labels = util.get_labels(type='regression')
train = util.get_realfeatures(pos, neg)
gk=GaussianKernel(train, train, width)
gk = GaussianKernel(train, train, width)
krr = KernelRidgeRegression()
krr.set_labels(labels)
krr.set_kernel(gk)
Expand All @@ -31,9 +29,8 @@
# compute output plot iso-lines
x, y, z=util.compute_output_plot_isolines(krr, gk, train, regression=True)

pcolor(x, y, z, shading='interp')
pcolor(x, y, z)
contour(x, y, z, linewidths=1, colors='black', hold=True)

connect('key_press_event', util.quit)
show()

Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from pylab import figure,pcolor,scatter,contour,colorbar,show,subplot,plot,legend,connect
from modshogun import *
from modshogun import *
from modshogun import *
import util

util.set_title('KernelRidgeRegression on Sine')
Expand Down
4 changes: 1 addition & 3 deletions examples/undocumented/python_modular/graphical/lda.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from pylab import figure,pcolor,scatter,contour,colorbar,show,subplot,plot,connect
from modshogun import *
from modshogun import *
import util

util.set_title('LDA')
Expand All @@ -25,10 +24,9 @@
# compute output plot iso-lines
x, y, z=util.compute_output_plot_isolines(lda)

c=pcolor(x, y, z, shading='interp')
c=pcolor(x, y, z)
contour(x, y, z, linewidths=1, colors='black', hold=True)
colorbar(c)

connect('key_press_event', util.quit)
show()

2 changes: 1 addition & 1 deletion examples/undocumented/python_modular/graphical/mclda.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

z = dense_labels.reshape((size, size))

pcolor(x, y, z, shading = 'interp')
pcolor(x, y, z)
contour(x, y, z, linewidths = 1, colors = 'black', hold = True)

axis([x1_min, x1_max, x2_min, x2_max])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from numpy import concatenate
from numpy.random import randn
from modshogun import *
from modshogun import *
from modshogun import *
import util

util.set_title('Multiple SVMS')
Expand Down Expand Up @@ -40,7 +38,7 @@
x, y, z=util.compute_output_plot_isolines(
currentSVM, kernelList[i], trainfeatList[i])
subplot(num_svms/2, 2, i+1)
pcolor(x, y, z, shading='interp')
pcolor(x, y, z)
contour(x, y, z, linewidths=1, colors='black', hold=True)
scatter(traindatList[i][0,:],traindatList[i][1,:], s=20, marker='o', c=trainlabsList[i], hold=True)
axis('tight')
Expand Down
2 changes: 1 addition & 1 deletion examples/undocumented/python_modular/graphical/qda.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

z = dense_labels.reshape((size, size))

pcolor(x, y, z, shading = 'interp')
pcolor(x, y, z)
contour(x, y, z, linewidths = 1, colors = 'black', hold = True)

axis([x1_min, x1_max, x2_min, x2_max])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
from numpy import *
from numpy.random import randn
from modshogun import *
from modshogun import *
from modshogun import *
from modshogun import *
import pylab as PL
import matplotlib
import logging as LG
Expand All @@ -18,8 +15,6 @@
from modshogun import ModelSelectionParameters, R_EXP, R_LINEAR
from modshogun import ParameterCombination



def plot_training_data(x, y,
shift=None,
replicate_indices=None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import numpy as np
import matplotlib.pyplot as plt

from modshogun import RealFeatures
from modshogun import MulticlassModel, MulticlassSOLabels, RealNumber, DualLibQPBMSOSVM
from modshogun import BMRM, PPBMRM, P3BMRM
from modshogun import StructuredAccuracy
from modshogun import RealFeatures
from modshogun import MulticlassModel, MulticlassSOLabels, RealNumber, DualLibQPBMSOSVM
from modshogun import BMRM, PPBMRM, P3BMRM
from modshogun import StructuredAccuracy

def fill_data(cnt, minv, maxv):
x1 = np.linspace(minv, maxv, cnt)
Expand Down Expand Up @@ -96,7 +96,7 @@ def get_so_labels(out):
z = Z.reshape(cnt, cnt)

plt.subplot(223)
plt.pcolor(x, y, z, shading='interp')
plt.pcolor(x, y, z)
plt.contour(x, y, z, linewidths=1, colors='black', hold=True)
plt.plot(X[:,0], X[:,1], 'yo')
plt.axis('tight')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import numpy as np
import matplotlib.pyplot as plt

from modshogun import RealFeatures
from modshogun import MulticlassModel, MulticlassSOLabels, RealNumber, DualLibQPBMSOSVM, DirectorStructuredModel
from modshogun import BMRM, PPBMRM, P3BMRM, ResultSet, RealVector
from modshogun import StructuredAccuracy
from modshogun import RealFeatures
from modshogun import MulticlassModel, MulticlassSOLabels, RealNumber, DualLibQPBMSOSVM, DirectorStructuredModel
from modshogun import BMRM, PPBMRM, P3BMRM, ResultSet, RealVector
from modshogun import StructuredAccuracy

class MulticlassStructuredModel(DirectorStructuredModel):
def __init__(self,features,labels):
Expand Down Expand Up @@ -142,7 +142,7 @@ def get_so_labels(out):
z = Z.reshape(cnt, cnt)

plt.subplot(223)
plt.pcolor(x, y, z, shading='interp')
plt.pcolor(x, y, z)
plt.contour(x, y, z, linewidths=1, colors='black', hold=True)
plt.plot(X[:,0], X[:,1], 'yo')
plt.axis('tight')
Expand Down
5 changes: 1 addition & 4 deletions examples/undocumented/python_modular/graphical/svm.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from pylab import figure,pcolor,scatter,contour,colorbar,show,subplot,plot,connect,axis
from numpy.random import randn
from modshogun import *
from modshogun import *
from modshogun import *
import util

util.set_title('SVM')
Expand All @@ -26,10 +24,9 @@
svm.train()

x, y, z=util.compute_output_plot_isolines(svm, gk, train)
pcolor(x, y, z, shading='interp')
pcolor(x, y, z)
contour(x, y, z, linewidths=1, colors='black', hold=True)
axis('tight')

connect('key_press_event', util.quit)
show()

7 changes: 2 additions & 5 deletions examples/undocumented/python_modular/graphical/svmlin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from pylab import figure,pcolor,scatter,contour,colorbar,show,subplot,plot,axis, connect
from modshogun import *
from modshogun import *
from modshogun import *
import util

util.set_title('SVM Linear 1')
Expand Down Expand Up @@ -33,7 +31,7 @@
x, y, z=util.compute_output_plot_isolines(svm, None, None, True, pos, neg)
x, y, zlight=util.compute_output_plot_isolines(svmlight, lk, dense, False, pos, neg)

c=pcolor(x, y, z, shading='interp')
c=pcolor(x, y, z)
contour(x, y, z, linewidths=1, colors='black', hold=True)
colorbar(c)
scatter(pos[0,:], pos[1,:],s=20, c='r')
Expand All @@ -43,7 +41,7 @@

figure()
util.set_title('SVM Linear 2')
c=pcolor(x, y, zlight, shading='interp')
c=pcolor(x, y, zlight)
contour(x, y, zlight, linewidths=1, colors='black', hold=True)
colorbar(c)

Expand All @@ -53,4 +51,3 @@
connect('key_press_event', util.quit)

show()

2 changes: 0 additions & 2 deletions examples/undocumented/python_modular/graphical/svr_sinc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from pylab import figure,pcolor,scatter,contour,colorbar,show,subplot,plot,legend, connect
from modshogun import *
from modshogun import *
from modshogun import *
import util

util.set_title('SVR on Sinus')
Expand Down