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

MKL hangs with Chi2 kernels #2854

Closed
iarroyof opened this issue Jun 12, 2015 · 1 comment
Closed

MKL hangs with Chi2 kernels #2854

iarroyof opened this issue Jun 12, 2015 · 1 comment
Labels

Comments

@iarroyof
Copy link

Hi all. I need your help. I'm trying to setup an evaluation framework for MKL by using different types of kernels. However while I try to train MKL weights for multiple Chi2 basis, the program hung at the weight learning stage [1] (See at the bottom). This is my code:

from modshogun import *
from tools.load import LoadMatrix

# Loading toy data from files
def load_Toy(dataRoute, fileTrain, fileLabels):
    lm = LoadMatrix()
    dataSet = lm.load_numbers(dataRoute + fileTrain)
    labels = lm.load_labels(dataRoute + fileLabels)

return (dataSet.T[0:3*len(dataSet.T)/4].T,  # Return the training set, 3/4 * dataSet
           dataSet.T[(3*len(dataSet.T)/4):].T,  # Return the test set, 1/4 * dataSet
           labels[0:3*len(labels)/4],               # Return corresponding train and test labels
           labels[(3*len(labels)/4):])

# Data importation
[traindata, testdata, trainlab, testlab] = load_Toy('../shogun-data/toy/',  # Data rute
               'fm_train_multiclass_digits500.dat',     # Multiclass dataSet examples file name
               'label_train_multiclass_digits500.dat')          # Multiclass Labels file name
feats_train = RealFeatures(traindata)   # train examples
labelsTr = MulticlassLabels(trainlab)   # train multiclass labels
feats_test = RealFeatures(testdata)     # test examples
labelsTs = MulticlassLabels(testlab)    # test multiclass labels

# Parameters
weightNorm = 2
regParam = 2
epsilon = 1e-5
threads = 2
mkl_epsilon = 0.001

# Setting up the MKL machine
mkl = MKLMulticlass()                   # MKL object 
mkl.set_C(regParam)                     # Setting multiclass regularization parameter
mkl.set_mkl_norm(weightNorm)        # Setting the weight vector norm
mkl.set_epsilon(epsilon)                # setting the transducer epsilon
mkl.set_mkl_epsilon(mkl_epsilon)
kernels = []
kernels.append(Chi2Kernel(l = feats_train, r = feats_train, width = 5))
kernels.append(Chi2Kernel(l = feats_train, r = feats_train, width = 25))
kernels.append(Chi2Kernel(l = feats_train, r = feats_train, width = 105))

combKer = CombinedKernel()
for k in kernels:
    combKer.append_kernel(k)

combKer.init(feats_train, feats_train)
print '[0] Kernel fitted...'
mkl.set_kernel(combKer)
mkl.set_labels(labelsTr)
print '[1] Going to train the mkl machine...'
# Train the weights to return the learnt kernel
mkl.train()
print '[2] Kernel trained... Weights: ', combKer.get_subkernel_weights()
# Now with test samples. 
combKer.init(feats_train, feats_test)       # The inner product between training
mkl.set_kernel(combKer)                 # and test examples generates the corresponding Gramm Matrix.
out = mkl.apply()                       # Applying the obtained Gramm Matrix
# Evaluating the test performance
evalua = MulticlassAccuracy()
testerr = evalua.evaluate(out, labelsTs)

print '[3] Kernel evaluation ready. The precision was: ', testerr*100, '%'

Any help would be very appreciated. Thank you in advance.

@stale
Copy link

stale bot commented Feb 26, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant