Пример #1
0
def main():
    Settings.new(
        linear_solver_partial_time_limit=None,
        non_linear_solver_partial_time_limit=None,
        solver_total_time_limit=20000,
    )

    products = [i for i in range(11)]
    ground_truth = MixedLogitModel(
        products=products,
        mus=[p + 1 for p in products],
        sigmas=[1 if p % 2 == 0 else 10 for p in products])

    offersets = OfferedProductsGenerator(products).generate(TRANSACTIONS)
    transactions = TransactionGenerator(ground_truth).generate_for(offersets)

    initial_solution = MixedLogitModel.simple_deterministic(products)
    estimator_mx = MaximumLikelihoodEstimator()
    estimation_mx = estimator_mx.estimate(initial_solution, transactions)

    initial_solution = MultinomialLogitModel.simple_deterministic(products)
    estimator_mnl = MaximumLikelihoodEstimator()
    estimation_mnl = estimator_mnl.estimate(initial_solution, transactions)

    plot(ground_truth, estimation_mx, estimator_mx, estimation_mnl,
         estimator_mnl, transactions)
Пример #2
0
def main():
    Settings.new(
        linear_solver_partial_time_limit=None,
        non_linear_solver_partial_time_limit=None,
        solver_total_time_limit=20000,
    )
    nests = [
        {'lambda': 0.8, 'products': [0, 1, 2]},
        {'lambda': 0.8, 'products': [3, 4, 5]},
        {'lambda': 0.8, 'products': [6, 7, 8]},
        {'lambda': 0.8, 'products': [9, 10]},
    ]

    products = [i for i in range(11)]
    ground_truth = NestedLogitModel(products=products, etas=[0.1 * i for i in range(1, 12)], nests=nests)

    offersets = OfferedProductsGenerator(products).generate(TRANSACTIONS)
    transactions = TransactionGenerator(ground_truth).generate_for(offersets)

    initial_solution = NestedLogitModel.simple_deterministic(products, nests)
    estimator_nl = MaximumLikelihoodEstimator()
    estimation_nl = estimator_nl.estimate(initial_solution, transactions)

    initial_solution = MultinomialLogitModel.simple_deterministic(products)
    estimator_mnl = MaximumLikelihoodEstimator()
    estimation_mnl = estimator_mnl.estimate(initial_solution, transactions)

    plot(ground_truth, estimator_mnl, estimation_mnl, estimator_nl, estimation_nl, transactions)
Пример #3
0
def main():
    Settings.new(
        linear_solver_partial_time_limit=300.0,
        non_linear_solver_partial_time_limit=300.0,
        solver_total_time_limit=1800.0,
    )

    ground_truth, transactions = read_synthetic_instance(
        'instances/100_lists_300_periods_1_instance.json')
    products = ground_truth.products

    nests = [{
        'products': [0],
        'lambda': 0.8
    }, {
        'products': [i for i in range(1, len(products)) if i % 2 == 0],
        'lambda': 0.8
    }, {
        'products': [i for i in range(1, len(products)) if i % 2 == 1],
        'lambda': 0.8
    }]

    lists = [[i] + list(sorted(set(products) - {i}))
             for i in range(len(products))]

    models_to_run = [
        (ExponomialModel.simple_deterministic(products),
         MaximumLikelihoodEstimator()),
        (MultinomialLogitModel.simple_deterministic(products),
         MaximumLikelihoodEstimator()),
        (RandomChoiceModel.simple_deterministic(products),
         RandomChoiceModelMaximumLikelihoodEstimator()),
        (LatentClassModel.simple_deterministic(products, 1),
         LatentClassFrankWolfeEstimator()),
        (MarkovChainModel.simple_deterministic(products),
         MarkovChainExpectationMaximizationEstimator()),
        (MarkovChainRank2Model.simple_deterministic(products),
         MaximumLikelihoodEstimator()),
        (MixedLogitModel.simple_deterministic(products),
         MaximumLikelihoodEstimator()),
        (NestedLogitModel.simple_deterministic(products, nests=nests),
         MaximumLikelihoodEstimator()),
        (RankedListModel.simple_deterministic(products, ranked_lists=lists),
         RankedListExpectationMaximizationEstimator(MIPMarketExplorer())),
    ]

    results = []
    for initial_solution, estimator in models_to_run:
        if hasattr(estimator, 'estimate_with_market_discovery'):
            model = estimator.estimate_with_market_discovery(
                initial_solution, transactions)
        else:
            model = estimator.estimate(initial_solution, transactions)
        soft_rmse = model.soft_rmse_for(ground_truth)
        results.append((model, estimator.profiler(), soft_rmse))

    plot(results)
Пример #4
0
 def look_for_new_mnl_model(self, model,
                            likelihood_loss_function_coefficients):
     possible_mnl_model = MultinomialLogitModel.simple_deterministic(
         model.products)
     problem = NewMNLSubProblem(model, possible_mnl_model,
                                likelihood_loss_function_coefficients)
     solution = NonLinearSolver.default().solve(problem, self.profiler())
     possible_mnl_model.update_parameters_from_vector(solution)
     return possible_mnl_model
def main():
    Settings.new(
        linear_solver_partial_time_limit=None,
        non_linear_solver_partial_time_limit=None,
        solver_total_time_limit=20000,
    )

    products = [i for i in range(11)]
    ground_truth = MultinomialLogitModel.simple_random(products=products)

    offersets = OfferedProductsGenerator(products).generate(TRANSACTIONS)
    transactions = TransactionGenerator(ground_truth).generate_for(offersets)

    initial_solution = ExponomialModel.simple_deterministic(products)
    estimator_exp = MaximumLikelihoodEstimator()
    estimation_exp = estimator_exp.estimate(initial_solution, transactions)

    initial_solution = MultinomialLogitModel.simple_deterministic(products)
    estimator_mnl = MaximumLikelihoodEstimator()
    estimation_mnl = estimator_mnl.estimate(initial_solution, transactions)

    plot(ground_truth, estimation_exp, estimator_exp, estimation_mnl, estimator_mnl, transactions)
Пример #6
0
 'mkv2': {
     'estimator':
     MaximumLikelihoodEstimator(),
     'model_class':
     lambda products: MarkovChainRank2Model.simple_deterministic(
         products),
     'name':
     'Markov Chain Rank 2',
     'settings':
     NORMAL_SETTINGS
 },
 'mnl': {
     'estimator':
     MaximumLikelihoodEstimator(),
     'model_class':
     lambda products: MultinomialLogitModel.simple_deterministic(
         products),
     'name':
     'Multinomial Logit',
     'settings':
     NORMAL_SETTINGS
 },
 'nl': {
     'estimator':
     MaximumLikelihoodEstimator(),
     'model_class':
     lambda products: NestedLogitModel.
     simple_deterministic_ordered_nests(products, [
         1,
         len(products) // 2,
         len(products) - (len(products) // 2) - 1
     ]),