market = Faker() market.genData(150, 10, 6, 500) blp = BLP(market.X1, market.X2, market.Z, market.M, market.S) blp.prepareSample() a = np.random.rand(market.X2.shape[1]) bounds = [(-3, 3) for x in a] # Keep initial delta vector initial_delta = blp.initial_delta.copy() # Test non-accelerated convergence print("Starting non-accelerated...") blp.delta_method = 0 start4 = time() res4 = blp.solve(a, method="Nelder-Mead", delta_method="picard") end4 = time() # Test non-accelerated convergence np.copyto(blp.initial_delta, initial_delta) print("Starting BFGS non-accelerated...") blp.delta_method = 0 start1 = time() res1 = blp.solve(a, method="BFGS", delta_method="picard", bounds=bounds) end1 = time() # Test Anderson-accelerated convergence np.copyto(blp.initial_delta, initial_delta) print("Starting BFGS Anderson accelerated...") blp.delta_method = 1 blp.anderson = np.empty((6, blp.initial_delta.shape[0]))
if __name__ == "__main__": market = Faker() market.genData(150, 10, 6, 500) a = np.random.rand(market.X2.shape[1]) bounds = [(-3, 3) for x in a] # Test serial unique convergence blp = BLP(market.X1, market.X2, market.Z, market.M, market.S) blp.prepareSample() population = blp.population.copy() population_size = blp.population_size # Keep these for easier comparison print("Starting picard serial...") start1 = time() res1 = blp.solve(a, method="Nelder-Mead", delta_method="picard") end1 = time() blp = None # Test serial multiple convergence blp2 = BLP(market.X1, market.X2, market.Z, market.M, market.S, par_cut=2) blp2.population = population blp2.status = 1 blp2.population_size = population_size print("Starting picard split...") start2 = time() res2 = blp2.solve(a, method="Nelder-Mead", delta_method="picard") end2 = time() blp2 = None # Test parallel convergence
self.beta = beta self.sigma = sigma self.demand_shock = demand_shock return if __name__ == "__main__": market = Faker() market.genData(50, 15, 6, 500) blp = BLP(market.X1, market.X2, market.Z, market.M, market.S) blp.prepareSample() a = np.random.rand(market.X2.shape[1]) ls = np.bincount(market.M, weights=market.S) s = ls[market.M] res = blp.solve(a, method="Nelder-Mead") print("The resulting message is : %s" % res.message) print("The flag is: %s" % res.success) print("Found theta1 is %s " % res.theta1) print("Real theta1 was %s %s" % (market.alpha, market.beta)) print("Found theta2 is %s" % (res.theta2)) print("Real theta2 was %s" % market.sigma) print("Starting theta2 was %s" % a) bounds = tuple([(-3, 3) for j in a]) res = blp.solve(a, method="BFGS", bounds=bounds) print("The resulting message is : %s" % res.message) print("The flag is: %s" % res.success) print("Found theta1 is %s " % res.theta1)