Rodrigo Ruiz wrote in post #1040708:
> I have to do the minimization of a cost function based on parameters
> (gradient descent).
>
> Is there a decent ruby gem (that works with rails) to do this?
>From what I can tell "gradient descent" is just math:
The Wiki page I found had a computational solution (in Python if I'm not
mistaken):
--------------
# From calculation, we expect that the local minimum occurs at x=9/4
x_old = 0
x_new = 6 # The algorithm starts at x=6
eps = 0.01 # step size
precision = 0.00001
def f_prime(x):
return 4 * x**3 - 9 * x**2
while abs(x_new - x_old) > precision:
x_old = x_new
x_new = x_old - eps * f_prime(x_new)
print "Local minimum occurs at ", x_new
--------------
Maybe just translating that to Ruby will give you what you want. Note:
I'm no mathematician. You may have to consult someone who is the above
needs any tweaking.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.