Functors

a
T a
b
F b

Type Constructor

f
\textrm{fmap } f
  • A functor is a function from one category to another the preserves the cateogorical structure
  • From a programing perspective, it maps types to types and functions to functions
  • We represent this in Haskell via a
  1. parameterized type constructor 
  2. placing the type in the functor typeclass with the fmap typeclass method
(\to) \ r \quad \textrm{is a parameterized type constructor}
f
a
f :: r \to a
b
f :: r \to b
a
(\to) \ r \ a
b
f
\textrm{fmap } f
(\to) \ r \ b
instance Functor ((->) r) where
	fmap f g = (\x -> f (g x))
(\to) \ r \ a
a
(\to) \ r \ a
b
f
instance Functor ((->) r) where
	fmap f g = (\x -> f (g x))

Professor writes down the Model

Student solves optimization problem

Learning how to solve well-posed problems

Typical class

Lecturer writes down question

Student writes down the model

Solver solves the optimization problem

Judgement

Calculus

Statistics

Newspapers/Podcasts

Psychology

Sociology

Finance

Core of Economics

This Class

Write down question

Write down the model

Solver solves the optimization problem

You

Real World Economics

Microeconomic model

Model

\underset{x \in F_p^{-1}(\mathcal{X})}{\textrm{maximize}} \ U_{\alpha}(x)
\underset{x \in F_p^{-1}(\mathcal{X})}{\textrm{maximize}} \ \mathbb{E}[f(x, z^*(x))]

Where to write math

On the Computer

  • Easily capture heterogeneity
  • Easily model uncertainty
  • Solving the model is easy (call a solver!)
  • Build the model step-by-step
  • Easy to visualize
  • We've already covered each aspect! (Nothing new!!)
  • Hard to capture heterogeneity without some planning
  • Hard to model uncertainty without more statistics 
  • Manually solve the model (takes time)
  • Hard to build the model step-by-step
  • Cannot visualize most aspects

If you think something is new, you missed a class

On Paper

xs = jnp.linsapce(0., 5.0, 7)

initial value

final value

Number of elements

Vector of linearly spaced values

Vector of Values

def f(x, y):
  return 2*x + jnp.sin(y)

A Function

Two inputs

x, y \longmapsto 2x + \sin(y)

Output

g = partial(f, 2)

A Function

Partial Evaluation

Is a higher order function (takes a function as input and returns a function)

Pass f as input 

evaluate at x=2

def f(x, y):
  return 2*x + jnp.sin(y)

A Function

Two inputs

x, y \longmapsto 2x + \sin(y)

Output

h = partial(f, y=3)

A Function

Partial Evaluation

Is a higher order function (takes a function as input and returns a function)

Pass f as input 

evaluate at y=3

def f(x):
  return 2*x 

A Function

One Input

Pass in a function

vectorize function

x \longmapsto 2x
z = jax.vmap(f)

Vectorized Function

Output

Please write down a model that provides some insight about which types of firms might increase their production in the US in response to the Pandemic

Application # 1

Copy of Applications

By Patrick Power

Copy of Applications

  • 130