def Weightloss_Shooting():
	age, sex =  38. , 'female'
	H, BW    =  1.73, 72.7
	T		 =  12*7.   # Time frame = 3 months    
	
	PALf, EIf = 1.7, 2025
	def EI(t): return EIf
	
	def PAL(t): return PALf
	
	from solution import fat_mass, compute_weight_curve, weight_odes
	F = fat_mass(BW,age,H,sex)
	L = BW-F
	# Fix activity level and determine Energy Intake to achieve Target weight of 145 lbs = 65.90909 kg
	
	init_FL = np.array([F,L])
	EI0, EI1 = 2000, 1950					# Variable Energy Intake
	beta = 65.90909*2.2
	reltol, abstol = 1e-9,1e-8
	dim, iterate = 2, 15
	print '\nj = 1', '\nt = ', EI0
	for j in range(2,iterate):
		print '\nj = ', j, '\nt = ', EI1
		ode_f = lambda t,y: weight_odes(t,y,EI1,PAL(t))
		example1 = ode(ode_f).set_integrator('dopri5',atol=abstol,rtol=reltol) 
		example1.set_initial_value(init_FL, 0.) 
		y1 = 2.2*sum(example1.integrate(T) )
		
		if abs(y1-beta)<1e-8: 
			print '\n--Solution computed successfully--'
			break
		# Update
		ode_f = lambda t,y: weight_odes(t,y,EI0,PAL(t))
		example0 = ode(ode_f).set_integrator('dopri5',atol=abstol,rtol=reltol) 
		example0.set_initial_value(init_FL, 0.) 
		y0 = 2.2*sum(example0.integrate(T))
		
		EI2 = EI1 - (y1 - beta)*(EI1-EI0)/(y1- y0)
		EI0 = EI1
		EI1 = EI2
		
	# Here we plot the solution 
	ode_f = lambda t,y: weight_odes(t,y,EI1,PAL(t))
	example = ode(ode_f).set_integrator('dopri5',atol=abstol,rtol=reltol)
	example.set_initial_value(init_FL, 0.) 
	
	X = np.linspace(0.,T,801)
	Y = np.zeros((len(X),dim))
	Y[0,:] = init_FL
	
	for j in range(1,len(X)): Y[j,:] = example.integrate(X[j]) 
	
	print '\n|y(T) - Target Weight| = ', np.abs(beta-2.2*sum(Y[-1,:]) ),'\n'
	plt.plot(X,2.2*(Y[:,0]+Y[:,1]),'-k',linewidth=2.0)
	plt.axis([-1,T+1,0,170])
	plt.show(); plt.clf()
	return 
def Predicted_Weight(PAL, EI, Target_Weight, age, sex, H, BW, T):
    from solution import fat_mass, compute_weight_curve, weight_odes
    F = fat_mass(BW, age, H, sex)
    L = BW - F
    # Fix activity level and determine Energy Intake to achieve Target weight of 145 lbs = 65.90909 kg

    init_FL = np.array([F, L])
    reltol, abstol = 1e-9, 1e-8

    ode_f = lambda t, y: weight_odes(t, y, EI, PAL)
    ode_object = ode(ode_f).set_integrator('dopri5', atol=abstol, rtol=reltol)
    ode_object.set_initial_value(init_FL, 0.)
    y1 = sum(ode_object.integrate(T))
    return y1 - Target_Weight
def Predicted_Weight(PAL,EI,Target_Weight,age,sex,H,BW,T):	
	from solution import fat_mass, compute_weight_curve, weight_odes
	F = fat_mass(BW,age,H,sex)
	L = BW-F
	# Fix activity level and determine Energy Intake to achieve Target weight of 145 lbs = 65.90909 kg
	
	init_FL = np.array([F,L])
	reltol, abstol = 1e-9,1e-8
	
	ode_f = lambda t,y: weight_odes(t,y,EI,PAL)
	ode_object = ode(ode_f).set_integrator('dopri5',atol=abstol,rtol=reltol) 
	ode_object.set_initial_value(init_FL, 0.) 
	y1 = sum(ode_object.integrate(T) )
	return y1-Target_Weight
Ejemplo n.º 4
0
import numpy as np
import matplotlib.pyplot as plt


def weightloss_calculator(age, sex, H, BW, T, (PAL, EI)):
    # Initial stats
    # Age (y), Gender	('male' or 'female'), Height (m), Body Weight (kg)
    # Time (d)
    #
    # Diet/Lifestyle Change
    # (PAL, EI) = Future Physical Activity Level and Energy Intake
    #
    # Call the IVP Solver
    ########################################
    from solution import fat_mass, compute_weight_curve
    F = fat_mass(BW, age, H, sex)
    L = BW - F
    t, y = compute_weight_curve(F, L, T, EI, PAL)

    # Plot the Results
    ####################################
    fig, ax = plt.subplots()
    plt.plot(t, 2.2 * y[:, 0], '-b', label='Fat', linewidth=2.0)
    plt.plot(t, 2.2 * y[:, 1], '-g', label='Lean', linewidth=2.0)
    plt.plot(t, 2.2 * (y[:, 0] + y[:, 1]), '-r', label='Total', linewidth=2.0)
    plt.legend(loc=1)  # Upper right placement
    plt.xlabel('days', fontsize=16)
    plt.ylabel('lbs', fontsize=16)
    plt.axis([0, np.max(t), 20, 180])

    plt.plot(t, 2.2 * 25 * H**2 * np.ones(t.shape),
Ejemplo n.º 5
0
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
import solution


def weightloss_calculator(age, sex, H, BW, T, (PAL, EI)):
    # Initial stats
    # Age (y), Gender	('male' or 'female'), Height (m), Body Weight (kg)
    # Time (d)
    #
    # Diet/Lifestyle Change
    # (PAL, EI) = Future Physical Activity Level and Energy Intake
    #
    # Call the IVP Solver
    ########################################
    F = solution.fat_mass(BW, age, H, sex)
    L = BW - F
    t, y = solution.compute_weight_curve(F, L, T, EI, PAL)

    # Plot the Results
    ####################################
    fig, ax = plt.subplots()
    plt.plot(t, 2.2 * y[:, 0], '-b', label='Fat', linewidth=2.0)
    plt.plot(t, 2.2 * y[:, 1], '-g', label='Lean', linewidth=2.0)
    plt.plot(t, 2.2 * (y[:, 0] + y[:, 1]), '-r', label='Total', linewidth=2.0)
    plt.legend(loc=1)  # Upper right placement
    plt.xlabel('days', fontsize=16)
    plt.ylabel('lbs', fontsize=16)
    plt.axis([0, np.max(t), 20, 180])

    # High end of normal weight range
Ejemplo n.º 6
0
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
import solution


def weightloss_calculator(age, sex, H, BW, T, (PAL, EI)):
	# Initial stats
	# Age (y), Gender	('male' or 'female'), Height (m), Body Weight (kg)
	# Time (d)
	#
	# Diet/Lifestyle Change
	# (PAL, EI) = Future Physical Activity Level and Energy Intake
	#
	# Call the IVP Solver
	########################################
	F = solution.fat_mass(BW, age, H, sex)
	L = BW - F
	t, y = solution.compute_weight_curve(F, L, T, EI, PAL)

	# Plot the Results
	####################################
	fig, ax = plt.subplots()
	plt.plot(t, 2.2 * y[:, 0], '-b', label='Fat', linewidth=2.0)
	plt.plot(t, 2.2 * y[:, 1], '-g', label='Lean', linewidth=2.0)
	plt.plot(t, 2.2 * (y[:, 0] + y[:, 1]), '-r', label='Total', linewidth=2.0)
	plt.legend(loc=1)  # Upper right placement
	plt.xlabel('days', fontsize=16)
	plt.ylabel('lbs', fontsize=16)
	plt.axis([0, np.max(t), 20, 180])

	# High end of normal weight range
import numpy as np
import matplotlib.pyplot as plt


def weightloss_calculator(age, sex, H, BW, T, (PAL,EI) ):
	# Initial stats
	# Age (y), Gender	('male' or 'female'), Height (m), Body Weight (kg)	
	# Time (d)
	# 	
	# Diet/Lifestyle Change
	# (PAL, EI) = Future Physical Activity Level and Energy Intake
	#
	# Call the IVP Solver     
	########################################
	from solution import fat_mass, compute_weight_curve
	F = fat_mass(BW,age,H,sex)
	L = BW-F
	t,y = compute_weight_curve(F,L,T,EI,PAL)
	
	# Plot the Results
	####################################
	fig, ax = plt.subplots()
	plt.plot(t,2.2*y[:,0],'-b',label='Fat',linewidth=2.0)
	plt.plot(t,2.2*y[:,1],'-g',label='Lean',linewidth=2.0)
	plt.plot(t,2.2*(y[:,0]+y[:,1]),'-r',label='Total',linewidth=2.0)
	plt.legend(loc=1)# Upper right placement
	plt.xlabel('days',fontsize=16)
	plt.ylabel('lbs',fontsize=16)
	plt.axis([0, np.max(t),20, 180])
	
	plt.plot(t, 2.2*25*H**2*np.ones(t.shape),'-.k')  # High end of normal weight range
Ejemplo n.º 8
0
def Weightloss_Shooting():
    age, sex = 38., 'female'
    H, BW = 1.73, 72.7
    T = 12 * 7.  # Time frame = 3 months

    PALf, EIf = 1.7, 2025

    def EI(t):
        return EIf

    def PAL(t):
        return PALf

    from solution import fat_mass, compute_weight_curve, weight_odes
    F = fat_mass(BW, age, H, sex)
    L = BW - F
    # Fix activity level and determine Energy Intake to achieve Target weight of 145 lbs = 65.90909 kg

    init_FL = np.array([F, L])
    EI0, EI1 = 2000, 1950  # Variable Energy Intake
    beta = 65.90909 * 2.2
    reltol, abstol = 1e-9, 1e-8
    dim, iterate = 2, 15
    print '\nj = 1', '\nt = ', EI0
    for j in range(2, iterate):
        print '\nj = ', j, '\nt = ', EI1
        ode_f = lambda t, y: weight_odes(t, y, EI1, PAL(t))
        example1 = ode(ode_f).set_integrator('dopri5',
                                             atol=abstol,
                                             rtol=reltol)
        example1.set_initial_value(init_FL, 0.)
        y1 = 2.2 * sum(example1.integrate(T))

        if abs(y1 - beta) < 1e-8:
            print '\n--Solution computed successfully--'
            break
        # Update
        ode_f = lambda t, y: weight_odes(t, y, EI0, PAL(t))
        example0 = ode(ode_f).set_integrator('dopri5',
                                             atol=abstol,
                                             rtol=reltol)
        example0.set_initial_value(init_FL, 0.)
        y0 = 2.2 * sum(example0.integrate(T))

        EI2 = EI1 - (y1 - beta) * (EI1 - EI0) / (y1 - y0)
        EI0 = EI1
        EI1 = EI2

    # Here we plot the solution
    ode_f = lambda t, y: weight_odes(t, y, EI1, PAL(t))
    example = ode(ode_f).set_integrator('dopri5', atol=abstol, rtol=reltol)
    example.set_initial_value(init_FL, 0.)

    X = np.linspace(0., T, 801)
    Y = np.zeros((len(X), dim))
    Y[0, :] = init_FL

    for j in range(1, len(X)):
        Y[j, :] = example.integrate(X[j])

    print '\n|y(T) - Target Weight| = ', np.abs(beta -
                                                2.2 * sum(Y[-1, :])), '\n'
    plt.plot(X, 2.2 * (Y[:, 0] + Y[:, 1]), '-k', linewidth=2.0)
    plt.axis([-1, T + 1, 0, 170])
    plt.show()
    plt.clf()
    return