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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Robert Walker at Jan 13, 2012 at 10:09 pm

    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@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Rodrigo Ruiz at Jan 14, 2012 at 2:03 am
    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 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@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    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@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Robert Walker at Jan 14, 2012 at 3:33 am

    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@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Rodrigo Ruiz at Jan 17, 2012 at 3:15 pm
    What libraries did you use?
    On Sat, Jan 14, 2012 at 1:33 AM, Robert Walker 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@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    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@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJan 13, '12 at 3:37p
activeJan 17, '12 at 3:15p
posts5
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Rodrigo Ruiz: 3 posts Robert Walker: 2 posts

People

Translate

site design / logo © 2021 Grokbase