Error using bsxfun Mixed integer class inputs are not supported - matlab

I'm working on a project on neural network and my working medium is Matlab. While running the following code:
net=train(net, feat_mat, gt_mat);
The neural network that I've used is a ffnn with 3 hidden layer. The highest value in feat_mat is 255 and the lowest is 0. The highest value in gt_mat is 1 and the lowest is 0. feat_mat has 5x423500 uint8 value and gt_mat has 1x423500 uint8.
I got the following error:
Error using bsxfun
Mixed integer class inputs are not supported.
Error in mapminmax.apply (line 6)
Error in nnet.mode.matlab.processInput (line 7)
Error in nnet.mode.matlab.processInputs (line 12)
Error in nncalc.preCalcData (line 16)
Error in nncalc.setup1>setupImpl (line 176)
Error in nncalc.setup1 (line 16)
Error in nncalc.setup (line 7)
Error in network/train (line 357)
I don't understand why this error is occuring. Any help would be appreciated. Thanks.
P.S: I've searched google and other questions at this site but none of them are relevant to mine.

As detailed in the error, train relies on bsxfun, which doesn't support mixed integer classes.
Your inputs are uint8 arrays, i.e. mixed integers, so train falls over.
To get around this, simply convert the inputs to doubles
net = train( net, double(feat_mat), double(gt_mat) );

Related

Error during rm ANOVA (Matlab) with random factor

I am trying to run a repeated measures ANOVA in Matlab with 4 factors including one factor representing my subjects which I want as a random factor.
The code I have is as follows:
[p,table,stats] = anovan(COORDS_SUBJ_II,{group_hand,group_stim,group_time,group_subs},'random',4,'varnames',{'HAND','STIM','TIME','SUBS'});
Here, all variables have the same dimension, which is 1350x1(all types are 'double'). I checked my code with some proposed code on the net and it matches, yet I keep getting the following error...
Error using chi2inv (line 3)
P and V must be of common size or scalars
Error in anovan>varcompest (line 838)
L = msTerm .* dfTerm ./ chi2inv(1-alpha/2,dfTerm);
Error in anovan>getRandomInfo (line 811)
[varest,varci] = varcompest(ems,randomterms,msTerm,dfTerm,alpha);
Error in anovan (line 296)
getRandomInfo(msterm,dfterm,mse,dfe,emsMat,randomterm,...
My dependent variable (COORDS_SUBJ_II) has a couple of NaN's in it, although I ran the code once where I replaced those NaN's with random numbers and it still gives me the same error. I am kind of lost right now and would appreciate any help.
Best
ty
Found it out. A toolbox I downloaded a while ago also had the chi2inv command and this prompted the error =)

Invalid setting for parameter 'Gain'

I am trying to create a simple controller, but keep receiving an error for the gain block stating that there is an undefined variable 'u'. I do not understand Simulink well and I am just trying to replicate an old homework problem right now. The code I have here was provided as a solution, but I still receive the error when I try to run it. Any insights as to what might be going on?
I= 10; Wl= 5; k= 2; J= 1;
%set initial conditions
thetaIC= 0; phiIC= 0; x0= zeros(4,1);
%fix theta= 0, check output
[xe, ue]= trim('Ex3_System',x0,0,x0,1)
[A,B,~,~]= linmod('Ex3_System', xe, ue)
%choose your desired poles
p= linspace(-1.2,-1.5,4)
%recall the minus sign
K= -acker(A,B,p)
%perturb initial condition
thetaIC= deg2rad(5);
sim('Ex3_Controller');
Invalid setting in 'Ex3_Controller/Gain' for parameter 'Gain'. Caused
by:
Error using hw12 (line 57)
Error evaluating parameter 'Gain' in 'Ex3_Controller/Gain'
Error using hw12 (line 57)
Undefined function or variable 'u'.
Error using hw12 (line 57)
Variable 'u' does not exist.
Suggested Actions:
• Load a file into 'Base Workspace'. - Fix
• Create a new variable. - Fix
Update: After removing the u term from the gain block, I received a different error:
Error using hw12 (line 57)
Error in port widths or dimensions. Output port 1 of 'Ex3_Controller/Gain' is a one dimensional vector with 4 elements.
Error using hw12 (line 57)
Error in port widths or dimensions. Input port 1 of 'Ex3_Controller/Model1' is a one dimensional vector with 1 elements.
The Gain block takes the value of the input signal and multiplies it by the value of the gain. In your case the gain is K and that is all you need to put into the gain block (i.e. remove the *u, Simulink handles that for you.)
Once that is done, the dimension error you are getting is because your controller requires u to be a scalar, but you are feeding a 4 element vector into it. You need to change the appropriate parameter of the Gain block so that it does a matrix multiplication, taking the 4-by-1 matrix K and (matrix) multiplying it with the 4 element "out" signal to produce a scalar.

How to fix the Principle Component Analysis error in Matlab

I happened to a Matlab Problem, the error looks like this:
Error using pca
Too many input arguments.
Error in mdscale (line 413)
[~,score] = pca(Y,'Economy',false);
Error in demo_libsvm_test1 (line 140)
newCoor = mdscale(distanceMatrix,2);
When I debug my code step by step, the error comes from here:
distanceMatrix = pdist(heart_scale_inst,'euclidean'); (line 139)
newCoor = mdscale(distanceMatrix,2); (line 140)
Everything above the two lines are all right. I do not know how to fix the problem. I use Matlab 2014a. Can anyone give me a help?

getting complex-valued Jacobian Matrix using NonLinearModel.fit in matlab

I am trying to use the NonLinearModel.fit() function in Matlab to regress two variables. However, I am getting the following error:
Error using internal.stats.getscheffeparam>ValidateParameters
(line 182)
If non-empty, JW must be a numeric, real matrix.
Error in internal.stats.getscheffeparam (line 110)
[J,VF,VP,JW,Intopt,TolSVD,TolE,VQ,usingJ] =
ValidateParameters(J,VF,VP,JW,Intopt,TolSVD,TolE,VQ,allowedIntopt);
Error in nlinfit (line 340)
sch =
internal.stats.getscheffeparam('WeightedJacobian',J(~nans,:),'Intopt','observation','VQ',VQ);
Error in NonLinearModel/fitter (line 1121)
[model.Coefs,~,J_r,model.CoefficientCovariance,model.MSE,model.ErrorModelInfo,~]
= ...
Error in classreg.regr.FitObject/doFit (line 219)
model = fitter(model);
Error in NonLinearModel.fit (line 1484)
model = doFit(model);
Error in getMatrix (line 101)
nlm =
NonLinearModel.fit(regressorMatrix',temp2',modelfun,beta0);
My regressorMatrix is 2-by-N (so the transpose is N-by-2), temp2' is N-by-1, and beta0 and model are given by:
model =#(b,x)b(1).*x(:,1).*x(:,2).^b(2);
beta0=[.14 .6];
nlm = NonLinearModel.fit(regressorMatrix',temp2',model,beta0);
Could someone please help me in figuring out what is causing this error?
EDIT: ok, no help so far so I will try to be more specific. I know that this error is referring to the weighted Jacobian matrix. I am just not sure why this Jacobian would not be real-valued.
Here are the first few rows of my regressor matrix:
regressorMatrix =
1.0e+07 *
0.000000000776613 3.762601240855837
0.000000001683014 3.762601240855837
0.000000001496807 3.762601240855837
0.000000000753495 3.762601240855837
and my response matrix:
temp2 =
-0.011811061934317
0.987582922964869
0.010621342764736
0.135001167018444
0.091950680609212
I can see that something is wrong here (the orders of magnitude in col2 of my regressor matrix are off. I will fix this and get back with an explanation if it turns out to the the cause. I am also working on printing out J. and JW
EDIT2:
I was able to print out JW before the error occurs and discovered that JW is a Nx2 complex matrix. So the specific reason the error is occurring is that the weighted Jacobian matrix is not real valued. Not sure why...
After a lot of digging, I found that the answer to this problem is quite obvious. I didn't realize that some of the values for one of my regressor variables was going negative sometimes. This lead (jumping a few steps ahead) to a complex Jacobian.

MATLAB NN toolbox: Error using trainlm

I have a 90×8 dataset that I feature-extracted (by summing 1's in every 10×10 cell) from 90 character images i.e. digits 1-9. Every row represents an image.
I am trying to use following code to train a neural network and recognize new input images(that are digits between 1 and 9 inclusive):
net.trainFcn='traingdx';
net.performFcn='sse';
net.trainParam.goal=0.1;
net.trainParam.show=20;
net.trainParam.epochs=5000;
net.trainParam.mc=0.95;
net =newff(minmax(datasetNormalized'),[20 9],{'logsig' 'logsig'});
T=reshape(repmat([1:9],10,1),1,90);
[net,tr]=train(net,datasetNormalized,T);
Afterwards I want to use the following to recognize new images using the trained network. m is an image character that has also been feature extracted.
[a,m]=max(sim(net,m));
disp(b);
I am getting the following errors and I don't have any idea how to solve it:
Error using trainlm (line 109)
Inputs and targets have different numbers of samples.
Error in network/train (line 106) [net,tr] =
feval(net.trainFcn,net,X,T,Xi,Ai,EW,net.trainParam);
Error in Neural (line 55) [net,tr]=train(net,datasetNormalized,T);
Note: datasetNormalized is my dataset normalized in [0,1].
Which part causes the problem?
Inputs and targets have different numbers of samples. it seems to be the problem
T=reshape(repmat([1:9],10,1),1,90) --> T=reshape(repmat([1:9],10,1),90,1)
[net,tr]=train(net,datasetNormalized,T); --> [net,tr]=train(net,datasetNormalized',T);
T is to be used as target for the network; Therefore, following a friend's advice, I defined T as a 9*90 array in such a way that the first 10 columns have 1 in their first row-other rows being zero, the second 10 columns have 1 in their second row, and so on
T=zeros(9,90);
for j=1:90
i=ceil(j/10);
T(i,j)=1;
end
[net,tr]=train(net,datasetNormalized',T);
This solved the error I was getting upon training network, though I'm not still sure how it's going to be mapped to input characters and determine them.