help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to vectorize in the octave


From: c.
Subject: Re: how to vectorize in the octave
Date: Mon, 12 Nov 2012 19:07:45 +0100

Please keep the list in CC and avoid top-posting so that others might also 
follow if interested.

On 12 Nov 2012, at 18:54, Herier chen wrote:

>> On Mon, Nov 12, 2012 at 12:48 PM, c. <address@hidden> wrote:
>> 
>> On 12 Nov 2012, at 18:39, Herier chen wrote:
>> 
>> >  grad(i) = (1.0/m)X(:,i)'(h-y);
>> 
>> this line of code does not make much sense in Octave syntax, what do you 
>> really want to do?
>> c.
> sorry, it miss a * between the X(:,i) '* (h-y) after I copy the code. 
>  m1 = size(grad); 
> 
> h = sigmoid(X*theta); 
> 
>  for i=1:m1,
>  grad(i) = (1.0/m)X(:,i)'*(h-y);
> end
> 
> what I am doing is to compute the gradient descent in machine learning, the 
> code works correctly, but I want to vertorize it to be more efficient. 

there is still something wrong in your line
> grad(i) = (1.0/m)X(:,i)'*(h-y);
maybe another missing multiplication?

It might also be easier to help you if you send code that can actually be run, 
for example adding some initialization
for variables like 'X', 'theta', 'grad', 'y' and 'm' that you have not defined, 
so that we can see what their dimensions are.

c.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]