Filter löschen
Filter löschen

how to declarate variables to solve this problem

1 Ansicht (letzte 30 Tage)
muhammad ismat
muhammad ismat am 20 Feb. 2017
Beantwortet: Walter Roberson am 21 Feb. 2017
if i have two function first
function [label,s] = LSC(data,k,opts)
% Set and parse parameters
if (~exist('opts','var'))
opts = [];
end
***%[how to define variables p and r to take values from loop]***
maxIter = 100;
numRep = 10;
mode = 'kmeans';
nSmp=size(data,1);
% Landmark selection
if strcmp(mode,'kmeans')
kmMaxIter = 5;
if isfield(opts,'kmMaxIter')
kmMaxIter = opts.kmMaxIter;
end
kmNumRep = 1;
if isfield(opts,'kmNumRep')
kmNumRep = opts.kmNumRep;
end
[dump,marks]=litekmeans(data,p,'MaxIter',kmMaxIter,'Replicates',kmNumRep);
[label,s] = kmedo(U',k);
end
second function
function Accuracy=yarbb(data,x)
%for i=1:100
rng('default')
n = size(data,1);
data_rand = data(randperm(n),:);
m = ceil(n/10);
k = 1:m:n-m;
test = data_rand(k:k+m-1,:);
train = [data_rand(1:k-1,:); data_rand(k+m:end,:)];
adj=ed(train,data);
for i=1:100
rng('default')
***for p=3:5
for r=2:5
[p,r]
[cluster_labels,s] = LSC(adj,x);***
auc= (ndash + 0.5 * nddash)/(ndash+nddash+nn);
end
Accuracy = mean(auc)
end
end
in second function i used for loop to pass variables "p" and "r" to first function to calculate "s" and return again to second function , but when i used for loop for variables "p" and "r" this caused errors that are [undefined variables "p" and adj(0,0) not found).

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 21 Feb. 2017
function Accuracy = yarbb(data, x)
rng('default')
n = size(data,1);
data_rand = data(randperm(n),:);
m = ceil(n/10);
k = 1:m:n-m;
test = data_rand(k:k+m-1, :);
train = [data_rand(1:k-1, :); data_rand(k+m:end, :)];
adj = ed(train,data);
p_vals = 3:5;
r_vals = 2:5;
for i = 1:100
rng('default')
for pidx = 1 : length(p_vals)
p = pvals(pidx);
for ridx = 1 : length(r_vals)
r = r_vals(ridx);
[p,r]
[cluster_labels, s] = LSC(adj, x, p, r);
auc(ridx) = (ndash + 0.5 * nddash) / (ndash + nddash + nn);
end
Accuracy(pidx) = mean(auc)
end
end
function [label,s] = LSC(data, k, p, r, opts)
% Set and parse parameters
if (~exist('opts','var'))
opts = [];
end
maxIter = 100;
numRep = 10;
mode = 'kmeans';
nSmp = size(data,1);
% Landmark selection
if strcmp(mode,'kmeans')
kmMaxIter = 5;
if isfield(opts,'kmMaxIter')
kmMaxIter = opts.kmMaxIter;
end
kmNumRep = 1;
if isfield(opts,'kmNumRep')
kmNumRep = opts.kmNumRep;
end
[dump, marks] = litekmeans(data, p, 'MaxIter', kmMaxIter, 'Replicates', kmNumRep);
[label, s] = kmedo(U',k);
end
It is not clear why you want to pass r to LSC, as LSC does not use it, but I put it in because you asked for it.
We must presume in the line
auc(ridx) = (ndash + 0.5 * nddash) / (ndash + nddash + nn);
that ndash and nddash and nn are all functions that take no parameters, as none of those are parameters to the functions and none of them are initialized in the functions.
It is not clear why you bother running LSC, as the Accuracy you calculate does not depend upon anything output from LSC.

Weitere Antworten (0)

Kategorien

Mehr zu Test Model Components finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by