Exemplo n.º 1
0
def run_fdfsolver():
    A       = 1.
    lambda_ = .1
    b       = .5

    n = 40
    p = 3

    t = numx.arange(n);
    y = testfunc(t, A, lambda_, b)
    sigma = numx.ones(n) * 0.1
    data = numx.array((t,y,sigma), numx.Float)
    #mysys = multifit_nlin.gsl_multifit_function_fdf(exp_f, exp_df, exp_fdf,
    # data, n,p)
    pygsl.set_debug_level(0)
    solver = multifit_nlin.lmsder(n, p)
    pygsl.set_debug_level(0)
    #solver = multifit_nlin.lmder(mysys, n, p)


    x = numx.array((1.0, 0.0, 0.0))
    pygsl.set_debug_level(0)
    solver.set(exp_f, exp_df, exp_fdf, x, data)
    pygsl.set_debug_level(0)
    print "# Testing solver ", solver.name() 
    print "# %5s %9s %9s  %9s  %10s" % ("iter", "A", "lambda", "b", "|f(x)|")
    for iter in range(20):	    
        status = solver.iterate()
	x  = solver.x()
	dx = solver.dx()
	f  = solver.f()
	J  = solver.J()
	#tdx = multifit_nlin.gradient(J, f)
	#status = multifit_nlin.test_delta(dx, x, 1e-8, 1e-8)
	status = solver.test_delta(1e-8, 1e-8)
	fn = numx.sqrt(numx.sum(f*f))
	if status == 0:
		print "# Convereged :"
	if status == 0:
                break
        print "  %5d % .7f % .7f  % .7f  % .7f" %(iter, x[0], x[1], x[2], fn)
    else:
	raise ValueError, "Number of Iterations exceeded!"

    J = solver.J()
    covar =  multifit_nlin.covar(solver.J(), 0.0)
    print "# A      = % .5f +/- % .5f" % (x[0], covar[0,0])
    print "# lambda = % .5f +/- % .5f" % (x[1], covar[1,1])
    print "# b      = % .5f +/- % .5f" % (x[2], covar[2,2])
Exemplo n.º 2
0
 def _run(self, solver):
     #x = Numeric.array((1.0, .4, .1))
     x = Numeric.array((1.0, 0.0, 0.0))
     solver.set(x)
     #g.title('Start')
     #g.plot(Gnuplot.Data(self.data[0], self.data[1]),
     #       Gnuplot.Data(self.data[0], testfunc(self.data[0]),
     #                    with = 'line'),
     #       )
     #raw_input()
     #print "Testing solver ", solver.name()
     #print "%5s %9s %9s  %9s  %10s" % ("iter", "A", "lambda", "b", "|f(x)|")
     for iter in range(20):
         status = solver.iterate()
         assert (status == 0 or status == -2)
         x = solver.getx()
         dx = solver.getdx()
         f = solver.getf()
         J = solver.getJ()
         tdx = multifit_nlin.gradient(J, f)
         status = multifit_nlin.test_delta(dx, x, 1e-8, 1e-8)
         #status = multifit_nlin.test_gradient(dx, 1e-4)
         fn = Numeric.sqrt(Numeric.sum(f * f))
         #g.title('Iteration')
         if status == 0:
             break
         #print "%5d % .7f % .7f  % .7f  % .7f" %(iter, x[0], x[1], x[2], fn)
         #g.plot(Gnuplot.Data(self.data[0], self.data[1]),
         #       Gnuplot.Data(self.data[0],
         #                    testfunc(self.data[0], x[0], x[1], x[2]),
         #                    with = 'line', title='iteration ' + str(iter)),
         #       )
         #raw_input()
     else:
         raise ValueError, "Number of Iterations exceeded!"
     #print "Convereged :"
     #print "%5d % .7f % .7f  %.7f  % .7f" %(iter, x[0], x[1], x[2], fn)
     assert (Numeric.absolute(x[0] - self.A) < _eps)
     assert (Numeric.absolute(x[1] - self.lambda_) < _eps)
     assert (Numeric.absolute(x[2] - self.b) < _eps)
     #J = solver.getJ()
     #print "shape = ", J.shape
     covar = multifit_nlin.covar(solver.getJ(), 0.0)
Exemplo n.º 3
0
def run_fdfsolver():
    A = 1.
    lambda_ = .1
    b = .5

    n = 40
    p = 3

    t = numx.arange(n)
    y = testfunc(t, A, lambda_, b)
    sigma = numx.ones(n) * 0.1
    data = numx.array((t, y, sigma), )
    mysys = multifit_nlin.gsl_multifit_function_fdf(exp_f, exp_df, exp_fdf,
                                                    data, n, p)
    solver = multifit_nlin.lmsder(mysys, n, p)
    #solver = multifit_nlin.lmder(mysys, n, p)

    x = numx.array((1.0, 0.0, 0.0))
    solver.set(x)
    print("# Testing solver ", solver.name())
    print("# %5s %9s %9s  %9s  %10s" % ("iter", "A", "lambda", "b", "|f(x)|"))
    for iter in range(20):
        status = solver.iterate()
        x = solver.getx()
        dx = solver.getdx()
        f = solver.getf()
        J = solver.getJ()
        tdx = multifit_nlin.gradient(J, f)
        status = multifit_nlin.test_delta(dx, x, 1e-8, 1e-8)
        fn = numx.sqrt(numx.sum(f * f))
        if status == errno.GSL_SUCCESS:
            print("# Convereged :")
        if status == errno.GSL_SUCCESS:
            break
        print("  %5d % .7f % .7f  % .7f  % .7f" % (iter, x[0], x[1], x[2], fn))
    else:
        raise ValueError("Number of Iterations exceeded!")

    J = solver.getJ()
    covar = multifit_nlin.covar(solver.getJ(), 0.0)
    print("# A      = % .5f +/- % .5f" % (x[0], covar[0, 0]))
    print("# lambda = % .5f +/- % .5f" % (x[1], covar[1, 1]))
    print("# b      = % .5f +/- % .5f" % (x[2], covar[2, 2]))
Exemplo n.º 4
0
 def _run(self, solver):
     #x = Numeric.array((1.0, .4, .1))
     x = Numeric.array((1.0, 0.0, 0.0))
     solver.set(x)
     #g.title('Start')
     #g.plot(Gnuplot.Data(self.data[0], self.data[1]),
     #       Gnuplot.Data(self.data[0], testfunc(self.data[0]),
     #                    with = 'line'),
     #       )
     #raw_input()
     #print "Testing solver ", solver.name() 
     #print "%5s %9s %9s  %9s  %10s" % ("iter", "A", "lambda", "b", "|f(x)|")
     for iter in range(20):
         status = solver.iterate()
         assert(status == 0 or status == -2)
         x  = solver.getx()
         dx = solver.getdx()
         f  = solver.getf()
         J  = solver.getJ()
         tdx = multifit_nlin.gradient(J, f)
         status = multifit_nlin.test_delta(dx, x, 1e-8, 1e-8)
         #status = multifit_nlin.test_gradient(dx, 1e-4)
         fn = Numeric.sqrt(Numeric.sum(f*f))
         #g.title('Iteration')
         if status == 0:
             break
         #print "%5d % .7f % .7f  % .7f  % .7f" %(iter, x[0], x[1], x[2], fn)
         #g.plot(Gnuplot.Data(self.data[0], self.data[1]),
         #       Gnuplot.Data(self.data[0],
         #                    testfunc(self.data[0], x[0], x[1], x[2]),
         #                    with = 'line', title='iteration ' + str(iter)),
         #       )
         #raw_input()
     else:
         raise ValueError, "Number of Iterations exceeded!"
     #print "Convereged :"        
     #print "%5d % .7f % .7f  %.7f  % .7f" %(iter, x[0], x[1], x[2], fn)
     assert(Numeric.absolute(x[0] - self.A) < _eps)
     assert(Numeric.absolute(x[1] - self.lambda_) < _eps)
     assert(Numeric.absolute(x[2] - self.b) < _eps)
     #J = solver.getJ()
     #print "shape = ", J.shape
     covar =  multifit_nlin.covar(solver.getJ(), 0.0)
Exemplo n.º 5
0
 def _run(self, solver):
     x = Numeric.array((1.0, 0.0, 0.0))
     solver.set(x)
     for iter in range(20):
         status = solver.iterate()
         assert (status == 0 or status == -2)
         x = solver.getx()
         dx = solver.getdx()
         f = solver.getf()
         J = solver.getJ()
         tdx = multifit_nlin.gradient(J, f)
         status = multifit_nlin.test_delta(dx, x, 1e-8, 1e-8)
         fn = Numeric.sqrt(Numeric.sum(f * f))
         if status == 0:
             break
     else:
         raise ValueError("Number of Iterations exceeded!")
     assert (Numeric.absolute(x[0] - self.A) < _eps)
     assert (Numeric.absolute(x[1] - self.lambda_) < _eps)
     assert (Numeric.absolute(x[2] - self.b) < _eps)
     covar = multifit_nlin.covar(solver.getJ(), 0.0)