I am calling silhouette_score, passing in a sparse matrix as X. The error I am getting is MemoryError. Looking at the Stack Trace, I see something like:
...
packages/sklearn/metrics/pairwise.py", line 245, in euclidean_distances
distances = safe_sparse_dot(X, Y.T, dense_output=True)
...
site-packages/scipy/sparse/compressed.py", line 496, in _mul_sparse_matrix
indices = np.empty(nnz, dtype=idx_dtype)
MemoryError
I see that when calling safe_sparse_dot dense_output=True. My initial thought is that this is the cause of the MemoryError. There seems to be no way to specify this parameter when calling silhouette_score.
Could this be the cause of the issue or am I barking up the wrong tree? Or does sklearn have some rationale for always passing dense_output=True?
Related
I have to plot the solution for masses between 4 and 8kg, which I wrote using the code below:
weight=linspace(4,8,100)
Then I use a for loop to find the solutions for the weights within this vector, while also declaring the variable a, and a guess of the time required:
for z=1:length(weight)
a=(weight./(1360*pi)).^(1/3)
tguess=14400
timeinseconds=fsolve(#(t)cookingtimes(t,a),tguess)
timeinhours=timeinseconds/(60*60)
end
The function that I mentioned previously is below:
function F=cookingtimes(t,a)
k=1:22;
alpha=0.7*10^(-7);
F(1)=(2./(pi*0.464))*sum(((-1).^(k-1))./k).*sin(k*pi*0.464).*exp(((-(k.^2)).*(pi.^2).*((alpha.*t))./(a.^2)))-57/80
end
Where F(1) represents the following equation 1, which will be equal to 57/80. Rather than adding until infinity, I chose the value of 22 as the equation converges to this value. r/a is equal to 0.464, which is why this is present within my function.
When running this code, I am given errors that I cant manage to solve.
Arrays have incompatible sizes for this operation.
Error in Homework1>cookingtimes (line 58)
F(1)=(2./(pi*0.464))*sum(((-1).^(k-1))./k).*sin(k*pi*0.464).*exp(((-(k.^2)).*(pi.^2).*.((alpha.*t))./(a.^2)))-57/80
Error in Homework1 (line 28)
timeinseconds=fsolve(#(t)cookingtimes(t,a),tguess)
Error in fsolve (line 264)
fuser = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial objective function evaluation. FSOLVE cannot continue.
The arrays that I have produced are all of the same length, which is why I am very stuck on this issue.
You are trying to perform an operation on two arrays that have different sizes. In your case, the issue may be caused by the fact that you are defining the variable a as a vector inside the for loop, but using it in the function cookingtimes as a scalar. To fix this, you can modify your function to accept a vector of a values and return a corresponding vector of function values.
I modified the cookingtimes function to accept a vector of a values, and return a corresponding vector of function values.
function F=cookingtimes(t,a)
k=1:22;
alpha=0.7*10^(-7);
F=(2./(pi*0.464))*sum(((-1).^(k-1))./k).*sin(k*pi*0.464).*exp(((-(k.^2)).* (pi.^2).*((alpha.*t))./(a.^2)))-57/80;
end
In the for loop, You need to compute a for each weight value, and use a vector of a values in the call to fsolve. Also store the solutions in a vector timeinseconds instead of a scalar, as there are multiple solutions to be found.
for z=1:length(weight)
a=(weight(z)./(1360*pi)).^(1/3); % compute a for each weight value
tguess=14400;
timeinseconds(z)=fsolve(#(t)cookingtimes(t,a),tguess);
timeinhours=timeinseconds/(60*60);
end
I have a struct as shown in picture, and I need to address one of the columns in a FOR loop, as shown. But I keep getting this error:
Function 'subsindex' is not defined for values of class 'struct'.
Error in analisa_arx_teste (line 351)
In my case, what i want is :line 1 represents i = 1, line 2 i =2; So, for features, When I ask for pref_estemod(i).features is to get the values from the field features associated to each model.
I am just starting programming with matlab, so all your help would be appreciated.
Thanks!
for i=pref_estemod(1:npreferred)
[m,n]=size(Training);
features=(pref_estemod(1,i).features);
end
The error lies in i=pref_estemod(1:npreferred).
If you intend to use i for indexing, the syntax is for i=1:npreferred.
1:npreferred itself expands to the horizontal array [1,2,...,npreferred]. = with a leading for is a special syntax combination. It means do the following code with i=1, i=2, ..., i=npreferred. Now I am sure you already know the idea behind for loop. The reason I write all this is to give you the following warning/advise. Do NOT expect the same syntax to work with non-numeric arrays. Because it works in some cases and not others.
I am using the following code to call a function for ODE45 to solve:
[outputs]=ode45(#(t,y)ILLYAcoupled(t,y,N,w,g),(0:0.5e-3:50),y0);
I am trying to get ode45 to give me values at 0.5e-3 increments between 0 and 50, which should output a solution vector length of about 10000, but I'm getting a solution vector of only 2720 points.
What is weird is that I was calling another function for ode45 to solve in the following fashion:
[outputs] = ode45(#HH,(0:0.5e-3:50),y0);
...and this was giving me the desired 10000 length solution vector--until recently. I tried calling it in this way:
[outputs] = ode45(#(t,y)HH(t,y),(0:0.5e-3:50),y0);
...which gave me a 2720 length solution vector and, now, even when I've changed the code back to the "#HH" by itself it keeps giving me the 2720 length vector rather than the desired 10000 length one.
It seems like something in the way I am specifying inputs and outputs to the called function during the ode45 call is messing things up but I don't know what.
I will be super grateful for any advice one might have!! Thanks!
I have a simple function written
function[] = myfun(p,q)
fminbnd(#(x)myfun1(q,p,b),0,1)
where myfun1's output is from the function quad.
How do I plot myfun? I've tried fplot(#(x)myfun(1,x),0,1) but this gives me a matrix dimensions must agree error...
Your question does not contain enough information to identify exactly where the problem lies, but one issue is certainly that myfun does not return any output. What should fplot plot, if there is nothing returned by the function?
Try
function out = myfun(p,q)
%# you may want to define b here
out = fminbnd(#(x)myfun1(q,p,b),0,1);
If that doesn't fix the issue, turn on the debugging mode by typing dbstop if error at the command line. This will show where exactly the error occurs, and allow you to inspect the variables for correct shape.
what can i do to solve this error in my program(learning the net)? it appear after sim. the net.
Error in ==> network.sim>simargs at 236
switch class(P)
??? Output argument "Pi" (and maybe others) not assigned during call to "C:\Program
Files\MATLAB\R2008b\toolbox\nnet\nnet\#network\sim.m>simargs".
Error in ==> network.sim at 173
case 2, [err,X,Xi,Ai,T,Q,TS,matrixForm] = simargs(net,X);
Error in ==> mlptrptest at 62
y = sim(net,A{1,1})
Note: Don't fall into the same trap I did. There is also a function called SIM in Simulink that will likely show up in searches for the function SIM in the Neural Network Toolbox...
The first thing I would check is that the second input argument A{1,1} is of the correct form. Specifically, A{1,1} would have to be a cell array or a matrix of doubles. If it is of any other form, like a structure or a matrix of any other class, you will get the error you are seeing. Admittedly, this particular error isn't handled very well by the subfunction simargs, in that it gives you some cryptic messages that don't really tell you the basic problem, which is that your input is not in the right format.
Here are a couple things to check:
Do you really mean to pass the first element of cell array A as an input argument, or do you mean to simply pass the cell array itself? If it's the second option, just do this:
y = sim(net,A);
If you do mean to pass the first element of A as an input argument, double-check it's class using the function CLASS:
class(A{1,1})
If you don't see double displayed, it means the first element of A is not the right type. If it is a matrix, you can convert it to double before you pass it to SIM like so:
y = sim(net,double(A{1,1}));