Пример #1
0
def my_minimize (model, params):
	return scipy.optimize.minimize(model, params, method='SLSQP').x
	nR=np.copy(map(float, params) )
	rml.set_max_P(1.0)
	ret=my_results(0)
	ret.niter=0
	while True:
#		print params
		if(rml.get_max_P()<0.75):	
			rml.set_max_P(0.75)
		ret.jac=Model_jac(params)	
		ret.hess=Model_hess(params)	
		if (np.linalg.det(ret.hess)==0):
			for x in range(0, len(params) ):
				params[x]=params[x]/2.
			continue
		R=np.linalg.inv( np.matrix(ret.hess ) )*np.matrix( ret.jac ).transpose()
		R=np.array(R.transpose() )[0]
		for x in range(0, len(R) ):
			nR[x]=params[x]-R[x]
		params=np.copy(nR)
		if (max ( abs(R) ) < 10**-6):
			break
		ret.niter+=1
		if (ret.niter>99):
			ret.success=False
			break
	ret.x=params
	ret.func=model(params)
	return params
Пример #2
0
def my_minimize(model, params):
    return scipy.optimize.minimize(model, params, method='SLSQP').x
    nR = np.copy(map(float, params))
    rml.set_max_P(1.0)
    ret = my_results(0)
    ret.niter = 0
    while True:
        #		print params
        if (rml.get_max_P() < 0.75):
            rml.set_max_P(0.75)
        ret.jac = Model_jac(params)
        ret.hess = Model_hess(params)
        if (np.linalg.det(ret.hess) == 0):
            for x in range(0, len(params)):
                params[x] = params[x] / 2.
            continue
        R = np.linalg.inv(np.matrix(ret.hess)) * np.matrix(ret.jac).transpose()
        R = np.array(R.transpose())[0]
        for x in range(0, len(R)):
            nR[x] = params[x] - R[x]
        params = np.copy(nR)
        if (max(abs(R)) < 10**-6):
            break
        ret.niter += 1
        if (ret.niter > 99):
            ret.success = False
            break
    ret.x = params
    ret.func = model(params)
    return params
Пример #3
0
def my_dll(model, params, x):
    ret = my_results(model(params))
    ret.x = params
    return scipy.optimize.minimize(model_x[x], params,
                                   method='SLSQP').fun - model(ret.x)
    params = [0., 0., 0., 0., 0., 0., 0.]
    nR = np.copy(map(float, params))
    ret.niter = 0
    P = rml.get_max_P()
    while True:
        if (rml.get_max_P() < 0.75):
            rml.set_max_P(0.75)

        ret.hess = Model_hess(params)
        ret.jac = Model_jac(params)

        ret.hess = np.delete(ret.hess, (x), axis=0)
        ret.hess = np.delete(ret.hess, (x), axis=1)
        ret.jac = np.delete(ret.jac, (x), axis=0)

        if (np.linalg.det(ret.hess) == 0):
            for x in range(0, len(params)):
                params[x] = params[x] / 2.
            continue
        try:
            R = np.linalg.inv(np.matrix(ret.hess)) * np.matrix(
                ret.jac).transpose()
        except:
            print params
            print ret.hess
            print np.linalg.inv(ret.hess)
            print ret.jac
            quit()
        R = np.array(R.transpose())[0]

        for y in range(0, len(params)):
            if y < x:
                nR[y] = params[y] - R[y]
            elif y > x:
                nR[y] = params[y] - R[y - 1]
        params = np.copy(nR)
        if (max(abs(R)) < 10**-4):
            break
        ret.niter += 1
        if (ret.niter > 99):
            ret.success = False
            break
    ret.func = model(params) - model(ret.x)
    ret.x = params
    rml.set_max_P(P)
    return ret.func
Пример #4
0
def my_dll (model, params, x):
	ret=my_results(model(params) )
	ret.x=params
	return scipy.optimize.minimize(model_x[x], params, method='SLSQP').fun-model(ret.x)
	params=[0.,0.,0.,0.,0.,0.,0.]
	nR=np.copy(map(float, params) )
	ret.niter=0
	P=rml.get_max_P()
	while True:
		if(rml.get_max_P()<0.75):	
			rml.set_max_P(0.75)

		ret.hess=Model_hess(params)
		ret.jac=Model_jac(params)

		ret.hess=np.delete(ret.hess, (x), axis=0)
		ret.hess=np.delete(ret.hess, (x), axis=1)
		ret.jac=np.delete(ret.jac, (x), axis=0)

		if (np.linalg.det(ret.hess)==0):
			for x in range(0, len(params) ):
				params[x]=params[x]/2.
			continue
		try:
			R=np.linalg.inv( np.matrix(ret.hess ) )*np.matrix( ret.jac ).transpose()
		except:
			print params
			print ret.hess
			print np.linalg.inv(ret.hess)
			print ret.jac
			quit()
		R=np.array(R.transpose() )[0]

		for y in range(0, len(params) ):
			if y<x:
				nR[y]=params[y]-R[y]
			elif y>x:
				nR[y]=params[y]-R[y-1]
		params=np.copy(nR)
		if (max ( abs(R) ) < 10**-4):
			break
		ret.niter+=1
		if (ret.niter>99):
			ret.success=False
			break
	ret.func=model(params)-model(ret.x)
	ret.x=params
	rml.set_max_P(P)
	return ret.func