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? Thanks in advance -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
The problem is that the function I''m trying to minimize is a lot more complicated (so is its derivative), so I wanted a function that could do the minimization for me rather than implementing one myself On Friday, January 13, 2012, Robert Walker <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email torubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org> For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.> >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Rodrigo Ruiz wrote in post #1040810:> The problem is that the function I''m trying to minimize is a lot more > complicated (so is its derivative), so I wanted a function that could do > the minimization for me rather than implementing one myselfI thought it might be something like that. Sorry I don''t know of anything like that either. Is this something that can be solved with matrix math? I noticed mention of that in what I was reading. I''ve used libraries in the past to solve some differential equations, but I had the advantage of having the matrix equation given to me by the company that created the device where it was needed. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
What libraries did you use? On Sat, Jan 14, 2012 at 1:33 AM, Robert Walker <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Rodrigo Ruiz wrote in post #1040810: > > The problem is that the function I''m trying to minimize is a lot more > > complicated (so is its derivative), so I wanted a function that could do > > the minimization for me rather than implementing one myself > > I thought it might be something like that. Sorry I don''t know of > anything like that either. Is this something that can be solved with > matrix math? I noticed mention of that in what I was reading. I''ve used > libraries in the past to solve some differential equations, but I had > the advantage of having the matrix equation given to me by the company > that created the device where it was needed. > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.