Class: GSL::MultiFit::MultidLM
- Inherits:
-
Object
- Object
- GSL::MultiFit::MultidLM
- Defined in:
- lib/gsl_extras.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#chi2 ⇒ Object
Returns the value of attribute chi2.
-
#covar ⇒ Object
Returns the value of attribute covar.
-
#dof ⇒ Object
Returns the value of attribute dof.
-
#my_chi2 ⇒ Object
Returns the value of attribute my_chi2.
-
#position ⇒ Object
Returns the value of attribute position.
Class Method Summary collapse
Instance Method Summary collapse
- #eval(*points) ⇒ Object
-
#initialize(yproc = nil, fproc, dfproc, ndata, ndims, nparams) ⇒ MultidLM
constructor
A new instance of MultidLM.
- #set_data(xstart, *gridpoints, y, sigma) ⇒ Object
- #solve(print_out = false) ⇒ Object
Constructor Details
#initialize(yproc = nil, fproc, dfproc, ndata, ndims, nparams) ⇒ MultidLM
Returns a new instance of MultidLM.
863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 |
# File 'lib/gsl_extras.rb', line 863 def initialize(yproc = nil, fproc, dfproc, ndata, ndims, nparams) @fproc = Proc.new do |x, t, y, sigma, f| # gridpoints = (0...@ndims).to_a.map do |i| # @gridpoints.col(i) # end fproc.call(x, *@gridpoints, y, sigma, f) end @dfproc = Proc.new do |x, t, y, sigma, jac| # gridpoints = (0...@ndims).to_a.map do |i| # @gridpoints.col(i) # end # puts 'hello' dfproc.call(x, *@gridpoints, y, sigma, jac) end @yproc = yproc # fproc # @dfproc = dfproc @ndata = ndata; @ndims = ndims; @nparams = nparams @f = GSL::MultiFit::Function_fdf.alloc(@fproc, @dfproc, @nparams) @solver = GSL::MultiFit::FdfSolver.alloc(FdfSolver::LMDER, @ndata, @nparams) end |
Instance Attribute Details
#chi2 ⇒ Object
Returns the value of attribute chi2.
920 921 922 |
# File 'lib/gsl_extras.rb', line 920 def chi2 @chi2 end |
#covar ⇒ Object
Returns the value of attribute covar.
920 921 922 |
# File 'lib/gsl_extras.rb', line 920 def covar @covar end |
#dof ⇒ Object
Returns the value of attribute dof.
920 921 922 |
# File 'lib/gsl_extras.rb', line 920 def dof @dof end |
#my_chi2 ⇒ Object
Returns the value of attribute my_chi2.
920 921 922 |
# File 'lib/gsl_extras.rb', line 920 def my_chi2 @my_chi2 end |
#position ⇒ Object
Returns the value of attribute position.
920 921 922 |
# File 'lib/gsl_extras.rb', line 920 def position @position end |
Class Method Details
.alloc(*args) ⇒ Object
859 860 861 |
# File 'lib/gsl_extras.rb', line 859 def self.alloc(*args) new(*args) end |
Instance Method Details
#eval(*points) ⇒ Object
922 923 924 925 |
# File 'lib/gsl_extras.rb', line 922 def eval(*points) raise "yproc not set" unless @yproc @yproc.call(@solver.position, *points) end |
#set_data(xstart, *gridpoints, y, sigma) ⇒ Object
886 887 888 889 890 891 892 893 |
# File 'lib/gsl_extras.rb', line 886 def set_data(xstart, *gridpoints, y, sigma) # p 'g', gridpoints.size @gridpoints = gridpoints; @y = y; @x = xstart.dup; @sigma = sigma @t = GSL::Vector.alloc(@y.size) @t.set_all(0.0) # t should never be used. @f.set_data(@t, @y, @sigma) @solver.set(@f, @x) end |
#solve(print_out = false) ⇒ Object
895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 |
# File 'lib/gsl_extras.rb', line 895 def solve(print_out = false) (puts "Warning: due to a bug, print out doesn't work with less than 3 params"; print_out = false) if @nparams < 3 # p @nparams, @solver.send(:p) iter = 0 @solver.print_state(iter) if print_out begin iter += 1 status = @solver.iterate @solver.print_state(iter) if print_out status = @solver.test_delta(1e-7, 1e-7) end while status == GSL::CONTINUE and iter < 500 @covar = @solver.covar(0.0) @position = @solver.position @my_chi2 = 0.0 # gp = @gridpoints.transpose for i in 0...@y.size @my_chi2 += (@y[i] - eval(*@gridpoints.map{|vec| vec[i]}))**2.0 / @sigma[i]**2.0 end @chi2 = (@solver.f.dnrm2)**2 @dof = @ndata - @nparams @solved = true @solver.position end |