Getting weights

60 views
Skip to first unread message

Jim Lindstrom

unread,
Feb 26, 2011, 1:45:48 PM2/26/11
to ruby_fann
I'm not seeing how to get the weights out of the network once I train
it. ... Help?

sunder

unread,
Feb 26, 2011, 4:37:06 PM2/26/11
to ruby_fann
Jim,

Good question. There is a function in FANN that has that
information. I need to implement it on the ruby side of the world. I
haven't done any updates in a while, so this is probably as good a
time as any. I'll give you more details once it is in.

Thanks,
-Steven
Message has been deleted

Jim Lindstrom

unread,
Feb 26, 2011, 5:24:35 PM2/26/11
to ruby...@googlegroups.com
Steven,

That'd be fantastic.  Thanks for the quick response time.  

In case anyone else finds it useful, I made a quick work around that relies on FANN's save-to-disk call.  (Not shown is how you figure out which connections belong to which neuron, but that's not too hard.)

class RubyFann::Standard

    # returns an array of { :src_node, :weight } elements
    def get_connections
        # ruby-fann doesn't let you get at the raw weights -- as far as I can tell.  So
        # this is a workaround that saves the network to a file and parses the weights out
        # of it.
        self.save("/tmp/test.fann")
        connections_str = `grep connections /tmp/test.fann`# read the saved network from file
        connections_str.gsub!(/.*=/,"")                    # get rid of some boilerplate at beginning of line
        connections = connections_str.split("(")           # turn string of repeated "(src_node, weight)" elements into an array
        connections.shift                                  # get rid of the bogus first element
        connections = connections.map { |x| x.split(",") } # split each (src_node, weight) pairs into an array
        connections = connections.map{ |x| { :src_node => Integer( x[0]                  ),
                                             :weight   => Float(   x[1].gsub(/\).*/, "") ) } }
        dummy = `rm /tmp/test.fann`

        return connections
    end
end

jbl

-- 
Jim Lindstrom
Email: jim.li...@gmail.com
Mobile: 773-339-4770
Twitter: @jimlindstrom

--
You received this message because you are subscribed to the Google Groups "ruby_fann" group.
To post to this group, send email to ruby...@googlegroups.com.
To unsubscribe from this group, send email to ruby_fann+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ruby_fann?hl=en.




Reply all
Reply to author
Forward
0 new messages