Goal of this notebook: reproduce a better suited version of this image.
from IPython.display import Image
Image(url='https://upload.wikimedia.org/wikipedia/en/d/df/Total%2C_Average%2C_and_Marginal_Product.gif')
Let's start with a sigmoid function
import holoviews as hv
hv.extension('bokeh', 'matplotlib')
import numpy as np
def sigmoid(x):
return 1/(1 + np.exp(-x))
x = np.linspace(-5, 5)
hv.Curve((x, sigmoid(x)))
Let's define a sigmoid that goes from 0 to 1.
normalized_sigmoid = lambda s: sigmoid(-5 + s*10) - sigmoid(-5)
s = np.linspace(0, 1)
production = hv.Curve((s, normalized_sigmoid(s)), kdims='labor', vdims='production', label='production function')
production
Now, let's derive the numerical gradient of this to get the marginal product.
marginal_product = hv.Curve((s, np.gradient(production.data.production, (s[1] - s[0]))), kdims='labor', vdims='production per labor unit', label='marginal production')
marginal_product
And let's also compute the average production per unit of labor.
average_product = hv.Curve((s, production.data.production / s), kdims='labor', vdims='production per labor unit', label='average production').redim.range(average_production=(0, 1.3))
average_product
%%opts Curve [height=200 width=500 tools=['crosshair']]
(production + marginal_product + average_product).cols(1)
We can also overlay the marginal production as well as the production itself.
%%opts Curve [width=400 tools=['crosshair']] Overlay [legend_position='top_left']
production + marginal_product * average_product
Let's try another layout.
vline = hv.VLine(x=0.5).options(color='green')
%%opts Curve [width=400 tools=['crosshair']] Overlay [legend_position='top_left']
(production * vline + marginal_product * average_product * vline).cols(1)
Finally, the image I need for Anki is:
%%opts Curve [width=400 tools=['crosshair']] Overlay [show_legend=False]
(production * vline + marginal_product * vline).cols(1)
%%output backend='matplotlib' fig='svg'
%%opts Curve [width=400 tools=['crosshair']] Overlay [show_legend=False]
(production * vline + marginal_product * vline).cols(1)