def row_scaling(a: numpy.matrix, row_totals: numpy.matrix, e: numpy.matrix) -> numpy.matrix: r_hat = matrix_divide(diagonal(row_totals), diagonal(matrix_multiply(a, e))) return r_hat
def run_model(consumption: numpy.matrix, production: numpy.matrix, emissions: numpy.matrix, final_demand: numpy.matrix=None) -> numpy.matrix: """ :param consumption: U :param production: V :param emissions: e :return: """ i = numpy.identity(len(consumption)) q = get_row_sum(production.source_data.elements) g = get_col_sum(production.source_data.elements) if final_demand is None: y = get_row_sum(consumption.source_data.elements) else: y = final_demand b = matrix_divide(consumption.source_data.elements, diagonal(g)) d = matrix_divide(production.source_data.elements, diagonal(q)) a = matrix_multiply(b, d) money_part = matrix_multiply(inv(i - a), y) return element_wise_divide(emissions.source_data.elements, money_part)
def column_scaling(a: numpy.matrix, column_totals: numpy.matrix, e: numpy.matrix) -> numpy.matrix: s_hat = matrix_divide(diagonal(column_totals), diagonal(matrix_multiply(e.T, a))) return s_hat