TaskBasedProduction.jl
Package for task-based production model.
Package Features
- Unit input demand calculator
- General unit input demand calculation
- General production function evaluation
- Specific production function evaluation
- Marginal productivity of labor calculation
- Elasticity of substitution and complementarity calculation
- General marginal productivity of labor calculation
- Elasticity of substitution and complementarity calculation general case
- Find initial guess for Gamma function case
- Find initial guess for general density function case
Function Documentation
TaskBasedProduction.unitInputDemand — FunctionunitInputDemand(xT::AbstractArray{<:Real}, θ::Real, κ::Real, z::Real, αVec::AbstractArray{<:Real}, skipParamChecks::Bool = false) -> AbstractArray{<:Real}Calculates unit labor demands given blueprint scale θ, blueprint shape κ, productivity z, an array of comparative advantage values αVec with H elements (one for each worker type), and an array xT of H-1 thresholds in task space.
Arguments
xT: An array of H-1 thresholds in task space.q: Quantity producedθ: Blueprint scale parameter.κ: Blueprint shape parameter.z: Productivity parameter.αVec: An array of comparative advantage values with H elements.skipParamChecks: A boolean indicating whether to skip parameter checks (default is false).
Returns
- An array representing the labor demand for each labor type.
TaskBasedProduction.unitInputDemand_general — FunctionunitInputDemand_general(xT::Vector{Float64}, z::Real, b_g::Function, e_h::Vector{Function}) -> Vector{Float64}Calculates unit labor demands given an array xT of H-1 thresholds in task space, a productivity value z, a density function b_g for the task distribution, and an array e_h of H functions representing the cost of each labor type as a function of task complexity.
The function first verifies that b_g is a valid density function. Then it computes the labor demand for each labor type by numerically integrating the ratio b_g(x) / (z * e_h[h](x)) over the intervals defined by the thresholds in xT.
Arguments
xT: A vector of H-1 thresholds in task space.q: Production valuez: Productivity value.b_g: A density function for the task distribution.e_h: A vector of H functions representing the cost of each labor type as a function of task complexity.
Returns
- A vector representing the labor demand for each labor type.
TaskBasedProduction.prod_fun_general — Functionprod_fun_general(labor_input::AbstractArray{<:Real}, z::Real, b_g:: Function, e_h::Vector{Function}; initial_guess=nothing, x_tol=1e-12, f_tol=1e-12, g_tol=1e-12, iterations=1000, max_retries=5)Calculates the quantity produced (q), and task thresholds (xT) given labor inputs (laborinput), productivity z, general blueprint density function (bg), and a vector of efficiency functions (e_h), one for each labor type.
Inputs:
labor_input: Array of labor inputs of different types.z: Productivity parameter.b_g: Blueprint density function.e_h: Vector of efficiency functions, one for each type.initial_guess: (optional) Initial guess for optimization. If not provided, defaults to zeros array.x_tol: (optional) Tolerance for the solution vector. Default is 1e-12.f_tol: (optional) Tolerance for the function value. Default is 1e-12.g_tol: (optional) Tolerance for the gradient. Default is 1e-12.iterations: (optional) Maximum number of iterations for the optimization. Default is 1000.max_retries: (optional) Maximum number of retries if the optimization fails. Default is 5.
Returns:
q: Quantity produced.xT: Array of task thresholds.fval: Final value of the objective function.
TaskBasedProduction.prod_fun — Functionprod_fun(labor_input::AbstractArray{<:Real}, θ::Real, κ::Real, z::Real, αVec::AbstractArray{<:Real}; initial_guess=nothing, optim_options=nothing)Calculates the quantity produced (q), and task thresholds (xT) given labor inputs (l), blueprint scale θ, blueprint shape κ, productivity z, and an array of comparative advantage values αVec with H elements (one for each worker type).
Inputs:
labor_input: Array of labor inputs of different types.θ: Blueprint scale parameter.κ: Blueprint shape parameter.z: Productivity parameter.αVec: Array of comparative advantage values with H elements.initial_guess: (optional) Initial guess for optimization. If not provided, defaults to zeros array.optim_options: (optional) Optimization options. If not provided, defaults to high tolerance values.
Returns:
q: Quantity produced.xT: Array of task thresholds.fval: Final value of the objective function.
TaskBasedProduction.margProdLabor — FunctionmargProdLabor(labor_input::Union{AbstractArray{<:Real}, Nothing}, θ::Real, κ::Real, z::Real, αVec::AbstractArray{<:Real}; xT=nothing, q=nothing) -> AbstractArray{<:Real}Calculates the marginal productivity of labor for each worker type given the input parameters.
Arguments
labor_input: An array of labor demand values. Ifnothing, it will be computed internally (given xT and q).θ: Blueprint scale parameter.κ: Blueprint shape parameter.z: Productivity parameter.αVec: An array of comparative advantage values.xT: (optional) An array representing the precomputed task thresholds. If not provided, it will be computed within the function.q: (optional) A scalar representing the precomputed quantity produced. If not provided, it will be computed within the function.
Returns
- An array representing the marginal productivity of labor for each worker type.
If labor_input is not provided, it will be computed using the q and unitInputDemand function based on the other parameters.
TaskBasedProduction.elasticity_sub_comp — Functionelasticity_sub_comp(labor_input::Union{AbstractArray{<:Real}, Nothing}, θ::Real, κ::Real, z::Real, αVec::AbstractArray{<:Real}; MPL=nothing, xT=nothing, q=nothing) -> (AbstractArray{<:Real}, AbstractArray{<:Real})Calculates the elasticity of substitution and complementarity for a given set of parameters.
Arguments
labor_input: An array of labor inputs of different types with H elements. Ifnothing, it will be computed internally given xT and q.θ: Blueprint scale parameter.κ: Blueprint shape parameter.z: Productivity parameter.αVec: An array of comparative advantage values with H elements.MPL: (optional) An array representing the marginal productivity of labor. If not provided, it will be computed within the function.xT: (optional) An array representing precomputed task thresholds. If not provided, it will be computed within the function.q: (optional) A scalar representing total production. If not provided, it will be computed within the function.
Returns
ϵ_h_sub: Matrix of elasticity of substitution values for each worker type h (rows) relative to worker type h_prime (columns).ϵ_h_compl: Matrix of elasticity of complementarity values for each worker type h (rows) relative to worker type h_prime (columns).
TaskBasedProduction.margProdLabor_general — FunctionmargProdLabor_general(labor_input::Union{AbstractArray{<:Real}, Nothing}, z::Real, b_g::Function, e_h::Vector{Function}; xT=nothing, q=nothing) -> AbstractArray{<:Real}Calculates the marginal productivity of labor for each worker type given the input parameters.
Arguments
labor_input: An array of labor inputs of different types with H elements. Ifnothing, it will be computed internally given xT and q.z: A productivity scalar.b_g: A task density function.e_h: A vector of comparative advantage functions.xT: (optional) An array representing the precomputed task thresholds. If not provided, it will be computed within the function.q: (optional) A scalar representing the precomputed quantity produced. If not provided, it will be computed within the function.
Returns
- An array representing the marginal productivity of labor for each worker type.
If labor_input is not provided, it will be computed using the q and unitInputDemand_general function based on the other parameters.
TaskBasedProduction.elasticity_sub_comp_general — Functionelasticity_sub_comp_general(labor_input::AbstractArray{<:Real}, z::Real, b_g::Function, e_h::Vector{Function}; MPL=nothing, xT=nothing, q=nothing) -> (AbstractArray{<:Real}, AbstractArray{<:Real})Calculates the elasticity of substitution and complementarity for a given set of parameters.
Arguments
labor_input: An array of labor inputs of different types with H elements. Ifnothing, it will be computed internally given xT and q.z: Productivity parameter.b_g: General task density function.e_h: Vector of comparative advantage functions.MPL: (optional) An array representing the marginal productivity of labor. If not provided, it will be computed within the function.xT: (optional) An array representing precomputed task thresholds. If not provided, it will be computed within the function.
-q: (optional) A scalar of total output produced. If not provided, it will be computed within the function.
Returns
ϵ_h_sub: Matrix of elasticity of substitution values for each worker type h (rows) relative to worker type h_prime (columns).ϵ_h_compl: Matrix of elasticity of complementarity values for each worker type h (rows) relative to worker type h_prime (columns).
TaskBasedProduction.find_initial_guess — Functionfind_initial_guess(labor_input::AbstractArray{<:Real}, θ::Real, κ::Real, z::Real, αVec::AbstractArray{<:Real}; threshold::Real=1e-2)Generate an initial guess for the optimization problem in prod_fun such that the implied labor demand is non-trivial.
Arguments
labor_input::AbstractArray{<:Real}: The observed labor input for each task.θ::Real: The scale parameter of the gamma distribution.κ::Real: The shape parameter of the gamma distribution.z::Real: A scaling factor for the labor input.αVec::AbstractArray{<:Real}: An array of task-specific parameters.threshold::Real: The minimum acceptable labor demand for each task.
Returns
initial_guess::Array{<:Real}: A vector containing the initial guess for the optimization, including the log of the initial production quantityqand the initial task thresholdsxT.
Description
This function generates an initial guess for the optimization problem by:
- Fixing the initial guess for
qat 1. - Generating initial
xTvalues using random percentiles from the gamma distribution defined byθandκ. - Adjusting the
xTvalues iteratively to ensure the implied labor demand for each task is above the specified threshold.
If the implied labor demand for any task is below the threshold, the xT values are re-shuffled using the generate_initial_xT function. This process continues until the implied labor demand for all tasks is above the threshold or the maximum number of iterations is reached.
If the adjustment process encounters an error, new xT values are generated from scratch.
TaskBasedProduction.find_initial_guess_gen — Functionfind_initial_guess_gen(labor_input::AbstractArray{<:Real}, z::Real, αVec::AbstractArray{<:Real}, pdf::Function; threshold::Real=1e-2, verbose::Bool=false)Generate an initial guess for the optimization problem using a general density function such that the implied labor demand is non-trivial.
Arguments
labor_input::AbstractArray{<:Real}: An array of labor demand values. Ifnothing, it will be computed internally (given xT and q).z::Real: A scaling factor for the labor input.αVec::AbstractArray{<:Real}: An array of task-specific parameters.pdf::Function: The general density function.threshold::Real: The minimum acceptable labor demand for each task.verbose::Bool: Optional boolean flag to enable or disable verbose output for debugging.
Returns
initial_guess::Array{<:Real}: A vector containing the initial guess for the optimization, including the log of the initial production quantityqand the initial task thresholdsxT.
Description
This function generates an initial guess for the optimization problem by:
- Fixing the initial guess for
qat 1. - Generating initial
xTvalues using random percentiles from the provided CDF function. - Adjusting the
xTvalues iteratively to ensure the implied labor demand for each task is above the specified threshold.
If the implied labor demand for any task is below the threshold, the xT values are re-shuffled using the generate_initial_xT function. This process continues until the implied labor demand for all tasks is above the threshold or the maximum number of iterations is reached.
If the adjustment process encounters an error, new xT values are generated from scratch.
Verbose output can be enabled by setting the verbose parameter to true, which will print debug information during the percentile calculation.