Reputation: 57
I am just giving part of the MATLAB code that gives me a headaches.
function [hm,sm] = SKSClab(filename,data_type,maxk,true_labels,plot_flag)
%Inputs:
% filename: .txt file (or .jpg for images) with the data (instances as rows, features as columns)
% data_type:
% 1) net_unw = unweighted network (filename represents the adjacency list)
% 2) net_w = weighted network (filename represents the adjacency list)
% 3) vector = generic data points
% 4) ts = time-series
% 5) img = image
% maxk: maximum number of clusters to look for
% true_labels: labels if present
% plot_flag: 1 -> plot results, 0-> do not plot anything
Then
switch data_type
case 'vector'
THR_dim = 100;
if(size(X,2)<THR_dim)
kernel_type = 'RBF_kernel';
else
kernel_type = 'cosine_kernel'; %use cosine kernel when enough features are present
end
case 'ts'
kernel_type = 'corrrbf_kernel';
case 'net_w'
kernel_type = 'cosine_kernel';
case 'net_unw'
kernel_type = 'cosine_kernel';
case 'img'
kernel_type = 'chisquared_kernel';
end
%Tuning
tunestruct = {samplefunc,numreps,data_type,MS_criterion};
[Xtrain,optk,optsig2,tuningExtras] = tuneSKSC(data,kernel_type,maxk,tunestruct);
When I invoke code like this
SKSClab('proba',3,6,1)
I got
Loading data...
Undefined function or variable "kernel_type".
Error in SKSClab (line 179)
[Xtrain,optk,optsig2,tuningExtras] = tuneSKSC(data,kernel_type,maxk,tunestruct);
There is also other function defined like this
function [Xtrain,optk,optsig2,extras] = tuneSKSC(datastruct,kernel,maxk,tunestruct)
What is the problem?Should I define kernel_type
?I do not have too much experiance with MATLAB.
Upvotes: 0
Views: 163
Reputation:
The problem is that kernel_type
will be defined only if the data_type
argument is one of the strings 'vector'
, 'ts'
, 'new_w'
, 'new_unw'
and 'img'
. But you pass the argument 3
that doesn't match any of these cases, so kernel_type
goes undefined, because there is no assignation to it.
To fix this add to the switch
statement an otherwise
branch:
switch data_type
case 'vector'
THR_dim = 100;
if(size(X,2)<THR_dim)
kernel_type = 'RBF_kernel';
else
kernel_type = 'cosine_kernel';
end
case 'ts'
kernel_type = 'corrrbf_kernel';
case 'net_w'
kernel_type = 'cosine_kernel';
case 'net_unw'
kernel_type = 'cosine_kernel';
case 'img'
kernel_type = 'chisquared_kernel';
otherwise
kernel_type = 'some_default_kernel_that_makes_sense';
end;
The alternative is to pass the correct arguments:
SKSClab('proba','vector',6,1)
Upvotes: 2
Reputation: 137
I think it can have one of two causes: 1) There is already a function in matlab that is named kernel_type 2) You didn't define kernel_type and you should just type kerneltype = ""; to declare an empty string
Upvotes: 0