At my wit's end. This program used to work for me, but now for some reason I keep getting that I cannot open the file. (Was using the same file before and no problem). I tried to just switch to wavread only and it worked but it added all sorts of complications for me to debug throughout the rest of my program, so I'd really like to get wav_to_audio working again.
The error message is
Error using wavread (line 70) Invalid Wave File. Reason: Cannot open file.
Error in wav_to_audio (line 108) [f_audio,fs,nbits] = wavread(strcat(dirAbs,dirRel,wavfilename));
Error in test_TempogramToolbox (line 61) [audio,sideinfo] = wav_to_audio('',dirWav,filename);
Here is the matlab code:
clear close all
dirWav = 'data_wav/';
filename = 'Debussy_SonataViolinPianoGMinor-02_111_20080519-SMD-ss135-189.wav';
% filename = '110-130bpm_click.wav';
% filename = 'Faure_Op015-01_126_20100612-SMD-0-12.wav';
% filename = 'Poulenc_Valse_114_20100518-SMD-0-15.wav';
% filename = 'Schumann_Op015-03_113_20080115-SMD-0-13.wav';
%% load wav file, automatically converted to Fs = 22050 and mono
[audio,sideinfo] = wav_to_audio('',dirWav,filename); Fs = sideinfo.wav.fs;
%% wav_to_audio function
if parameter.message == 1
fprintf('wav_to_audio: processing %s, ',wavfilename);
end
[pathstr,name,ext] = fileparts(wavfilename);
if strcmp(ext,'.wav')
[f_audio,fs,nbits] = wavread(strcat(dirAbs,dirRel,wavfilename));
else
error(['Unknown file format ' ext]);
end
bConverted_to_mono = 0;
if parameter.convertToMono
if size(f_audio,2)>1
bConverted_to_mono = 1;
if parameter.message == 1
fprintf('converting to mono, ');
end
switch parameter.monoConvertMode
case 'leftmost_channel'
f_audio= f_audio(:,1);
case 'rightmost_channel'
f_audio= f_audio(:,size(f_audio,2));
case 'downmix' % pay attention to energy loss due to differences in phase
% when using this method. This is often the case for bad
% stereo mixes
nChannels = size(f_audio,2);
f_audio = sum(f_audio,2);
f_audio = f_audio / nChannels;
otherwise
disp('wav_to_audio: monoConvertMode : Unknown method')
end
end
end
bResampled = 0;
if parameter.useResampling
if (fs ~= parameter.destSamplerate)
bResampled = 1;
if parameter.message == 1
fprintf('Resampling to %d, ', parameter.destSamplerate);
end
f_audio = resample (f_audio,parameter.destSamplerate,fs,100);
fs = parameter.destSamplerate;
end
end
%% Update sideinfo
sideinfo.wav.version = 1;
sideinfo.wav.filename = wavfilename;
sideinfo.wav.dirRel = dirRel;
sideinfo.wav.size = size(f_audio,1);
sideinfo.wav.duration = (sideinfo.wav.size-1)/fs;
sideinfo.wav.energy = sum(f_audio.^2);
sideinfo.wav.fs = fs;
sideinfo.wav.nbits = nbits;
sideinfo.wav.channels = size(f_audio,2);
sideinfo.wav.resampled = bResampled;
sideinfo.wav.monoConverted = bConverted_to_mono;
if bConverted_to_mono
sideinfo.wav.monoConvertMode = parameter.monoConvertMode;
else
sideinfo.wav.monoConvertMode = 'none';
end
%% Saving data
if parameter.save == 1
if parameter.message == 1
fprintf('Saving to file, ');
end
filename = strcat(parameter.saveFilename,'_audio');
save(strcat(parameter.saveDir,filename),'f_audio','sideinfo');
end
if parameter.message == 1
fprintf('Done\n');
end
%% Visualization
if parameter.vis
figure;
for k=1:sideinfo.wav.channels
if sideinfo.wav.channels > 1
subplot(sideinfo.wav.channels,1,k);
end
plot( [0:sideinfo.wav.size-1] / sideinfo.wav.fs , f_audio(:,k));
axis tight;
end
end
end
Related
% thresholds used for g2NN test
dr2 = 0.5;
extract_feat = 1; % by default extract SIFT features using Hess' code
if(exist('filesift','var') && ~strcmp(filesift,'nofile'))
extract_feat = 0;
end
tic; % to calculate proc time
%C:\python36\Disso\sift-forensic-master
if extract_feat
sift_bin = fullfile('lib','sift','bin','siftfeat'); % e.g. 'lib/sift/bin/siftfeat' in linux
[pf,nf,ef] = fileparts(filename);
desc_file = [fullfile(pf,nf) '.txt'];
im1=imread(filename);
if (size(im1,1)<=1000 && size(im1,2)<=1000)
status1 = system([sift_bin ' -x -o ' desc_file ' ' filename]);
else
status1 = system([sift_bin ' -d -x -o ' desc_file ' ' filename]);
end
if status1 ~=0
error('error calling executables');
end
% import sift descriptors
[num, locs, descs] = import_sift(desc_file);
system(['rm ' desc_file]);
else
% import sift descriptors
[num, locs, descs] = import_sift(filesift);
end
if (num==0)
p1=[];
p2=[];
tp=[];
else
p1=[];
p2=[];
num=0;
% load data
loc1 = locs(:,1:2);
%scale1 = locs(:,3);
%ori1 = locs(:,4);
des1 = descs;
% descriptor are normalized with norm-2
if (size(des1,1)<15000)
des1 = des1./repmat(sqrt(diag(des1*des1')),1,size(des1,2));
else
des1_norm = des1;
for j= 1 : size(des1,2)
des1_j = des1_norm(j,:);
des1_norm(j,:) = des1_j/norm(des1_j,2);
end
des1 = des1_norm;
end
% sift matching
des2t = des1'; % precompute matrix transpose
if size(des1,1) > 1 % start the matching procedure iff there are at least 2 points
for i = 1 : size(des1,1)
dotprods = des1(i,:) * des2t; % Computes vector of dot products
[vals,indx] = sort(acos(dotprods)); % Take inverse cosine and sort results
j=2;
while vals(j)<dr2* vals(j+1)
j=j+1;
end
for k = 2 : j-1
match(i) = indx(k);
if pdist([loc1(i,1) loc1(i,2); loc1(match(i),1) loc1(match(i),2)]) >10
p1 = [p1 [loc1(i,2); loc1(i,1); 1]];
p2 = [p2 [loc1(match(i),2); loc1(match(i),1); 1]];
num=num+1;
end
end
end
end
tp = toc; % processing time (features + matching)
if size(p1,1)==0
fprintf('Found %d matches.\n', num);
else
p=[p1(1:2,:)' p2(1:2,:)'];
p=unique(p,'rows');
p1=[p(:,1:2)'; ones(1,size(p,1))];
p2=[p(:,3:4)'; ones(1,size(p,1))];
num=size(p1,2);
fprintf('Found %d matches.\n', num);
end
end
Hi all,
I have uploaded the code above for copy-move forgery detection. While running the code there are several errors which I am getting. I have also uploaded the snippet of the error that I am having trouble to fix with. I have also contacted the guy who wrote this code and he replied to me with following message: "You need to compile the third party library in the folder bin/sift accordingly to your operative system.".
I hope to find the solution here.
A snippet of the error
How is it possible to resolve this error. As this video upload takes too much time. Firstly I am reading a cell. Then creating histogram of a frame extracted from video, then comparing it with any previous frame and uploading only if there is any significant difference between histograms.
global currRowIndex;
global histCell;
if (fname ~= 0)
file_fullpath = strcat(pthname, fname);
[pathstr, name, ext] = fileparts(file_fullpath);
mov=VideoReader(file_fullpath);
data = read(mov, Inf);
nFrames=mov.NumberOfFrames;
parfor k = 1: nFrames
waitbar(k/nFrames);
if(k==1)
index=currRowIndex;
cell=histCell;
currentFrame = read(mov, k);
imgHSV=rgb2hsv(currentFrame);
H = imgHSV(:,:,1);
S = imgHSV(:,:,2);
V = imgHSV(:,:,3);
hHist = hist(H(:),16);
sHist = hist(S(:),16);
vHist = hist(V(:),16);
index=index+1;
cell(index,:,:,:,index)={name;hHist;sHist;vHist;categorySelected};
else
currentFrame = read(mov, k);
imgHSV=rgb2hsv(currentFrame);
H = imgHSV(:,:,1);
S = imgHSV(:,:,2);
V = imgHSV(:,:,3);
hHist = hist(H(:),16);
sHist = hist(S(:),16);
vHist = hist(V(:),16);
[rowCurr,colCurr,depthCurr]=size(cell);
found=0;
if(row==0)
row=1;
end
for x=row:rowCurr
dbRow=cell(x,:,:,:,x);
H_Temp= getDiff(dbRow{2},hHist);
if(H_Temp>2000 && dbRow{5}==categorySelected)
found=1;
break;
end
end
if(found==1)
index=index+1;
cell(index,:,:,:,index)={name;hHist;sHist;vHist;categorySelected};
end
end
end
The error I get is as below
??? Reference to a cleared variable cell.
Error in ==> FrmUploadVideo>(parfor body) at 133
[rowCurr,colCurr,depthCurr]=size(cell);
Hello when l run the code above l got this error . l don't where is the error ,my codes (.m) and training examples are in the same working directory.
Error using fread
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in MNISTParser (line 3)
magic_number = fread(fp,1,'uint32',0,'b');
Error in MNIST_gen (line 2)
train_labels = MNISTParser('./MNIST/train-labels-idx1-ubyte');
MNIST_gen.m
clear
**train_labels = MNISTParser('./MNIST/train-labels-idx1-ubyte');**
train_images = MNISTParser('./MNIST/train-images-idx3-ubyte');
test_labels = MNISTParser('./MNIST/t10k-labels-idx1-ubyte');
test_images = MNISTParser('./MNIST/t10k-images-idx3-ubyte');
test_item_number = length(test_labels);
train_item_number = length(train_labels);
image_scale = size(test_images,2);
test_images_unfold = reshape(test_images,test_item_number,image_scale^2)';
test_labels_unfold = full(ind2vec(test_labels'+1));
train_images_unfold = reshape(train_images,train_item_number,image_scale^2)';
train_labels_unfold = full(ind2vec(train_labels'+1));
save MNIST.mat;
colormap(gray);
axis off
axis image
%show an image of a digit in test samples
for i=1:1
j=randi(length(test_labels),1);
image(reshape(255-test_images(j,:,:),28,28));
title(sprintf('%d',test_labels(j)));
pause(1);
image(reshape(test_images_unfold(:,j),28,28));
title(vec2ind(test_labels_unfold(:,j))-1);
pause(1);
end
%show an image of a digit in train samples
for i=1:1
j=randi(length(train_labels),1);
image(reshape(255-train_images(j,:,:),28,28));
title(sprintf('%d',train_labels(j)));
pause(1);
image(reshape(train_images_unfold(:,j),28,28));
title(vec2ind(train_labels_unfold(:,j))-1);
pause(1);
end
MNISTParser.m
function res = MNISTParser(filename)
fp = fopen(filename,'r');
**magic_number = fread(fp,1,'uint32',0,'b');**
items_number = fread(fp,1,'uint32',0,'b');
if 2049==magic_number
res = fread(fp,items_number,'uint8',0,'b');
else
if 2051==magic_number
img_rows = fread(fp,1,'uint32',0,'b');
img_cols = fread(fp,1,'uint32',0,'b');
res = zeros(items_number,img_rows,img_cols);
for i=1:items_number
res(i,:,:) = fread(fp,[img_cols,img_rows],'uint8',0,'b')';
end
else
error('wrong magic number');
end
end
fclose(fp);
end
Thanks for helps
l find the mistake. it is related to the extension of the files.
here is the instruction that has helped me to find out my mistake [fp,msg] = fopen(filename,'r');
if fp<1, error([msg ' File: ' filename]);
Well i got the problem, that i have to acces the content of a cell in Matlab. But it's not an ordinary cell. There could be a cell in a cell. And i don't know how many levels the first cell has.
All the cells have the dimension (1,x)
so it could be
mycell{cell1{cell11{char1, char2}}, char3, cell2{char4, char5, char6}}
i have to get the char variables, and i have to know where they are.
this type of cell is returned, when i do this
get_param(path_to_busselector, 'Inputsignals')
path_to_busselector is the path to a bus selector in Simulink.
I can hard code it, but then i can only handle a fixed number of cell-levels, and this is a problem.
My ideas are, that i construct something with a while loop and probably something with the eval command.
here i have an example model Matlab example model and a skript which gives the signals names. if you run the command signalnames = get_param(BlockPaths(Cellofbusselector)) then there is a cell like i have. now i want to get acces to the signals in the bus selector, but i don't want to do this by hand. If i want to acces the signal in a skript, i have to know the compleete name of the signal. is this clear or am i just unable to tell what i want. sorry if the second statement is true, i will try again
so after i get the name of the signal i can do something like this
set_param(outporthandle_of_busselector, 'Outport', fullsignalname)
and for this i have to know the exact signal name.
Thanks for your time and your ideas
Well I have found a solution. It's not very nice, but it works.
All the files can be downloded here from dropbox
Sorry, I would have liked to post an image, but I don't have 10 reputations. So you have to donwload it from the link above.
Here ist the main skript and further down is a recursif function.
The skript should also work for all other Simulin models with a bus. But just now it just works, if there ist only one busselector. But it is not much to program for several bus systems and bus selectors.
% Name_Signals_after_Blocknames
format compact, clear all, clc
cd(''); % Directory where the simulink model is safed
Simulink_Model = ('linearGuide_model.slx');
Simulink_Model = ('Verbindung.slx');
Simulink_Model = ('bus_system.slx');
% Simulink_Model = ('singlebus.slx');
[path, Model_name, ext] = fileparts(Simulink_Model);
BlockPaths = find_system(Model_name,'LookUnderMasks', 'all' ,'Type','Block');
length_Model_name = length(Model_name);
Cellofbusselector = [];
jj = 0;
for ii = 1:length(BlockPaths)
disp(BlockPaths{ii})
porthandles = get_param(BlockPaths{ii}, 'PortHandles');
outporthandles = get_param(porthandles.Outport, 'Line');
Block_Name = BlockPaths{ii};
% if length(outporthandles) > 1 % only give names to outputs of a subsystem, they are also listed in the BlockPaths cell
% warning ('more than one signal wants to get the same name, might be a Subsystem')
% else
if strcmp(BlockPaths{ii}(end-7:end), 'Selector') % you can not change the name of a line connecting a Bus Selector
disp('Here we have a Bus selector')
jj = 1+jj;
Cellofbusselector(jj) = ii;
else
if isempty(outporthandles)
warning(['Block ', Block_Name, ' has no Output'] )
elseif length(outporthandles) == 1
if outporthandles == -1 % outporthanldes == 1, when there is no signal attachet to the outport of the block
warning(['Block ', Block_Name, ' has no Output-Signal attached'] )
else
Signal_name = BlockPaths{ii}((length_Model_name+2):end);
set_param(outporthandles, 'Name', Signal_name);
end
elseif length(outporthandles) > 1
for jj = 1:length(outporthandles)
if outporthandles{jj} == -1 % outporthanldes == 1, when there is no signal attachet to the outport of the block
Block_Name = BlockPaths{ii};
warning(['Block ', Block_Name, ' has no Output-Signal attached'] )
else
Signal_name = [BlockPaths{ii}((length_Model_name+2):end), '_out', num2str(jj)];
set_param(outporthandles{jj}, 'Name', Signal_name);
end
end
end
end
% end
end % for ii = 1:length(BlockPaths)
buscell = get_param(BlockPaths{Cellofbusselector}, 'InputSignals');
[signalname, buslevel, numofsig, busname] = f_get_complete_signalnames(buscell)
%%
signalnamesize = size(signalname);
for ii = 1:signalnamesize(1)
for kk = 1:signalnamesize(2)
if isempty(signalname{ii,kk})
else
nrofbusnames = kk-1;
fullbusname = '';
for i = 1:nrofbusnames
fullbusname = [fullbusname '.' busname{i}];
end
fullsignames{ii,1} = [fullbusname(2:end) '.' signalname{ii,kk}]
end
end
end
Here is the code from the recursiv function
function [signalname, buslevel, numofsig, busname] = f_get_complete_signalnames(buscell, buslevel, numofsig, signalname, busname)
%% Description
% This function returns the complete signal names which are stored in a
% bus. The name looks something like bus1.bus2.signal1.
if nargin < 2; buslevel = 1; end
if nargin < 3; numofsig = 0; end
if nargin < 4; signalname = {}; end
if nargin < 5; busname = {}; end
buscellsize = size(buscell);
buscellsize(1); % busvert is the vertical dimension of buscell
for kk = 1:buscellsize(1)
if ischar(buscell{kk,1}) && buscellsize(2) == 1
numofsig = numofsig + 1;
signalname{numofsig, buslevel} = buscell{kk,1};
elseif ischar(buscell{kk,1}) && buscellsize(2) == 2
busname{buslevel-1} = buscell{kk,1};
[signalname, buslevel, numofsig, busname] = f_get_complete_signalnames(buscell{kk,2}, buslevel, numofsig, signalname, busname);
elseif iscell(buscell{kk,1}) && buscellsize(2) == 1
buslevel = buslevel+1;
[signalname, buslevel, numofsig, busname] = f_get_complete_signalnames(buscell{kk,1}, buslevel, numofsig, signalname, busname);
buslevel = buslevel-1;
end
end
end
I hope I made this right. And this helps somebody.
In the first Matlab script below when I run it as shown I get no errors what so ever and the code produces the expected results, however when I take out matlabpool open and matlabpool close as well as changing the parfor loop to a for loop, I get the following error:
Running... ??? Error using ==> mldivide
Matrix is singular to working precision.
Error in ==> NSS_betas at 11
betas = G\data.y2.';
Error in ==> DElambda at 19
betas(:,ii) = NSS_betas(P1(:,ii),data); end
Error in ==> Individual_Lambdas at 46
beta{ii} = DElambda(de,dataList, #OF_NSS);
I will happily send CRM_22_12.mat if required.
Why does the error only trigger when I use a regular for loop instead if a parfor loop?
clear all, clc
load Euro_CRM_22_12.mat
matlabpool open
tic
warnState(1) = warning('error', 'MATLAB:singularMatrix');
warnState(2) = warning('error', 'MATLAB:illConditionedMatrix');
mats = 1:50;
mats2 = [2 5 10 30];
% RO: unloop these
de = struct(...
'min', [0;0],...
'max', [50;50],...
'd' , 2,...
'nP' , 500,...
'nG' , 600,...
'ww' , 0.1,...
'F' , 0.5,...
'CR' , 0.99,...
'R' , 0,...
'oneElementfromPm',1);
% RO: initialize beta
beta = cell(size(rates,1),1);
clc, fprintf('Running... ');
%for ii = 1:size(rates,1)
parfor ii = 1:size(rates,1)
% RO: use status indicator for things that take this long
%fprintf('\b\b\b\b\b\b\b%6.2f%%', ii/size(rates,1)*100);
dataList = struct(...
'yM' , rates(ii,:),...
'mats' , mats,...
'model', #NSS,...
'mats2', mats2,...
'y2' , rates(ii,mats2));
beta{ii} = DElambda(de,dataList, #OF_NSS);
end
toc
matlabpool close
%
function [output] = DElambda(de,data,OF)
% RO: also saves time
% warning off; %#ok
warning on verbose;
P1 = zeros(de.d,de.nP);
Pu = zeros(de.d,de.nP);
for ii = 1:de.d
P1(ii,:) = de.min(ii,1)+(de.max(ii,1)-de.min(ii,1))*rand(de.nP,1); end
P1(:,1:de.d) = diag(de.max);
P1(:,de.d+1:2*de.d) = diag(de.min);
% RO: pre allocate betas
betas = zeros(size(data.y2,2), de.nP);
for ii = 1:de.nP
betas(:,ii) = NSS_betas(P1(:,ii),data); end
Params = vertcat(betas,P1);
Fbv = NaN(de.nG,1);
% must pass OF as #OF
F = zeros(de.nP,1);
P = zeros(de.nP,1);
for ii = 1:de.nP
F(ii) = OF(Params(:,ii)',data);
P(ii) = pen(P1(:,ii),de,F(ii));
F(ii) = F(ii)+P(ii);
end
[Fbest indice] = min(F);
xbest = Params(:,indice);
Col = 1:de.nP;
% RO: pre allocate betasPu
betasPu = zeros(size(data.y2,2), de.nP);
% RO: if Fbest hasn't changed for 25 generations,
% it's not gonna anymore: break off
count = 0;
for g = 1:de.nG
P0 = P1;
rowS = randperm(de.nP).';
colS = randperm(4).';
% RO: replace circshift for JIT accelleration
% RS = circshift(rowS,colS(1));
% R1 = circshift(rowS,colS(2));
% R2 = circshift(rowS,colS(3));
% R3 = circshift(rowS,colS(4));
RS = rowS([end-colS(1)+1:end 1:end-colS(1)]);
R1 = rowS([end-colS(2)+1:end 1:end-colS(2)]);
R2 = rowS([end-colS(3)+1:end 1:end-colS(3)]);
R3 = rowS([end-colS(4)+1:end 1:end-colS(4)]);
% mutate
Pm = P0(:,R1) + de.F*(P0(:,R2)-P0(:,R3));
if de.R>0, Pm = Pm+de.r*randn(de.d,de.nP); end
% crossover
PmElements = rand(de.d,de.nP)<de.CR;
if de.oneElementfromPm
% RO: JIT...
%Row = unidrnd(de.d,1,de.nP);
Row = ceil(de.d .* rand(1,de.nP));
ExtraPmElements = sparse(Row,Col,1,de.d,de.nP);
PmElements = PmElements|ExtraPmElements;
end
P0_Elements = ~PmElements;
Pu(:,RS) = P0(:,RS).*P0_Elements+PmElements.*Pm;
% RO: inline NSS_betas, so that this loop can
% be compiled by the JIT
mats = data.mats2.';
yM = data.y2.';
nObs = size(data.y2,2);
one = ones(nObs,1);
% RO: version below is faster
% for ii = 1:de.nP
% %betasPu(:,ii) = NSS_betas(Pu(:,ii),data);
%
% lambda = Pu(:,ii);
% G = [one,...
% (1-exp(-mats/lambda(1)))./(mats/lambda(1)),...
% ((1-exp(-mats/lambda(1)))./(mats/lambda(1)) - exp(-mats/lambda(1))),...
% ((1-exp(-mats/lambda(2)))./(mats/lambda(2)) - exp(-mats/lambda(2)))];
%
% betasPu(:,ii) = G\yM;
%
% end
aux = bsxfun(#rdivide, mats, Pu(:).');
aux2 = exp(-aux);
aux3 = (1-aux2)./aux;
for ii = 1:2:2*de.nP
% betasPu(:,(ii+1)/2) =[...
% one,...
% aux3(:,ii),...
% aux3(:,ii) - aux2(:,ii),...
% aux3(:,ii+1) - aux2(:,ii+1)] \ yM;
G=[one, aux3(:,ii), aux3(:,ii) - aux2(:,ii),aux3(:,ii+1) - aux2(:,ii+1)];
try
betasPu(:,(ii+1)/2) =G\yM;
catch ME
CondPen(1,(ii+1)/2)=0;
end
end
ParamsPu = [betasPu;Pu];
flag = 0;
mats = data.mats;
yM = data.yM;
for ii = 1:de.nP
% RO: inline OF_NSS.m here for JIT accelleration
%Ftemp = OF(ParamsPu(:,ii).',data);
beta = ParamsPu(:,ii).';
%model = data.model;
yy = zeros(size(yM));
for jj = 1:size(beta,3)
% RO: inline for JIT accelleration
%y(ii,:) = model(beta(:,:,ii),mats);
betai = beta(:,:,jj);
gam1 = mats/betai(5);
gam2 = mats/betai(6);
aux1 = 1-exp(-gam1);
aux2 = 1-exp(-gam2);
% I have a feeling this is the same as G and therefore
% this can be done shorter and quicker...
% something like yy(jj,:) = sum(G,2)
yy(jj,:) = ...
betai(1) + ...
betai(2)*(aux1./gam1) + ...
betai(3)*(aux1./gam1+aux1-1) + ...
betai(4)*(aux2./gam2+aux2-1);
end
yy = yy-yM;
% RO: this whole loop can be replaced...
% ObjVal = 0;
% for i = 1:size(yM,1) %dim
% ObjVal = ObjVal+dot(aux(i,:)',aux(i,:)');
% %ObjVal = sum(ObjVal);
% end
% ObjVal
% RO ...by this one-liner
Ftemp = sum(yy(:).^2);
% RO: inline penalty here as well
Ptemp = 0;%pen(Pu(:,ii),de,F(ii));
Ftemp = Ftemp+Ptemp;%+CondPen(1,ii);
if Ftemp <= F(ii);
P1(:,ii) = Pu(:,ii);
F(ii) = Ftemp;
if Ftemp < Fbest
Fbest = Ftemp; xbest = ParamsPu(:,ii);
flag = 1;
count = 0;
end
else
P1(:,ii) = P0(:,ii);
end
end
if flag
Fbv(g) = Fbest; end
% RO: if Fbest hasn't changed for 25 generatios, break off
count = count + 1;
if count > 25, break; end
end
output.Fbest = Fbest;
output.xbest = xbest;
output.Fbv = Fbv;
end
% look to inline penalty later (i.e. incoporate into code
function penVal = pen(~,~,~)%pen(beta,pso,vF,data)
penVal = 0;
end
%
function [betas r r2] = NSS_betas(lambda,data)
mats = data.mats2.';
nObs = size(data.y2,2);
G = [ones(nObs,1),...
(1-exp(-mats/lambda(1)))./(mats/lambda(1)),...
((1-exp(-mats/lambda(1)))./(mats/lambda(1)) - exp(-mats/lambda(1))),...
((1-exp(-mats/lambda(2)))./(mats/lambda(2)) - exp(-mats/lambda(2)))];
betas = G\data.y2.';
% RO: output hardly ever needed, while rank()
% is very time consuming
if nargout > 1 && ~isnan(G)
r = rank(G);
r2 = rcond(G);
end
end
It's a bit cryptic, but here's what I can tell you for sure.
Error in ==> NSS_betas at 11
betas = G\data.y2.';
Error in ==> DElambda at 19
betas(:,ii) = NSS_betas(P1(:,ii),data); end
Error in ==> Individual_Lambdas at 46
beta{ii} = DElambda(de,dataList, #OF_NSS);
Essentially, this means that the G matrix is singular, and thus doesn't have a solution. That would be this:
G = [ones(nObs,1),...
(1-exp(-mats/lambda(1)))./(mats/lambda(1)),...
((1-exp(-mats/lambda(1)))./(mats/lambda(1)) - exp(-mats/lambda(1))),...
((1-exp(-mats/lambda(2)))./(mats/lambda(2)) - exp(-mats/lambda(2)))];
betas = G\data.y2.';
What I would do to further diagnose this is to set the stop on error flag. There is a few ways to do this, one from the gui, and another via command. Take a look to see if the matrix looks correct. Odds are, something isn't right. Trace back the error, and you'll figure it out.