From: Zack M. Davis Date: Sun, 13 Oct 2024 06:32:37 +0000 (-0700) Subject: I don't think my prediction market code is right X-Git-Url: http://unremediatedgender.space/source?a=commitdiff_plain;h=7b3bc3c7708a014ae24db3998e70bf81a6aed7b2;p=Ultimately_Untrue_Thought.git I don't think my prediction market code is right --- diff --git a/content/drafts/prediction-markets-are-not-a-drop-in-replacement-for-concepts.md b/content/drafts/prediction-markets-are-not-a-drop-in-replacement-for-concepts.md index e0f77bf..3e146cc 100644 --- a/content/drafts/prediction-markets-are-not-a-drop-in-replacement-for-concepts.md +++ b/content/drafts/prediction-markets-are-not-a-drop-in-replacement-for-concepts.md @@ -34,37 +34,65 @@ Your teammate objects to the idea of moving elements based on whether they're gr ```` from math import log2 -import prediction markets +import prediction_markets + def prediction_market_sort(my_list): n = len(my_list) + op_count = 0 op_budget = n * log2(n) - is_sorted = prediction_markets.create("Is the list sorted?", data=my_list, options=[True, False]) + is_sorted_market = prediction_markets.create( + "Is the list sorted?", dynamic_data=my_list + ) markets_to_resolve = [] - while not is_sorted: - - if is_sorted - - - next_comparison = prediction_markets.create( - f"Will the list be sorted with no more than {op_budget} comparisons, if the" - "next comparision is between these indicies?", - data=my_list, - options=[(i, j) for i in range(n) for j in range(i, n) if i != j] - ) - i, j = next_comparison.leading - should_swap = prediction_markets.create( + while is_sorted_market.probability < 0.95: + next_comparison_markets = { + (i, j): prediction_markets.create( + f"Will the list be sorted with no more than {op_budget} comparisons, if the" + f"next comparision is between indicies {i} and {j}?", + static_data=my_list, + ) + for i in range(n) + for j in range(i, n) + if i != j + } + + next_comparison = max( + next_comparison_markets.items(), key=lambda m: m[1].probability + )[0] + + for comparison, market in next_comparison_markets.items(): + if comparison != next_comparison: + market.cancel() + else: + markets_to_resolve.append(market) + + i, j = next_comparison + + should_swap_market = prediction_markets.create( f"Will the list be sorted with no more than {op_budget} comparisons, if we swap" f"the elements at indices {i} and {j}?", - data=my_list, - options=[True, False] + static_data=my_list, ) - if should_swap.resolution: + if should_swap_market.probability > 0.5: temp = my_list[i] my_list[i] = my_list[j] my_list[j] = temp + + markets_to_resolve.append(should_swap_market) + else: + should_swap_market.cancel() + + op_count += 1 + + is_sorted_market.resolve(True) + + for market in markets_to_resolve: + market.resolve(op_count <= op_budget) + + return my_list ``` "No," you say.