@@ -276,117 +276,3 @@ def multiple_choice_add_options(
276276 build_question_forecasts (question )
277277
278278 return question
279-
280-
281- # def multiple_choice_interpret_forecasts(
282- # forecasts: list[Forecast | AggregateForecast],
283- # options_history: OptionsHistoryType | None,
284- # ) -> list[Forecast | AggregateForecast]:
285- # """Interprets multiple choice forecasts with respect to the history of options.
286- # Returns an altered list of forecasts with the PMFs reflecting the total list of
287- # values ever available for the question.
288-
289- # `forecasts` param must be sorted by `start_time`
290-
291- # Example:
292- # options_history = [
293- # (0, ["a", "other"]),
294- # (100, ["a", "b", "other"]),
295- # ]
296- # pmf = [0.6, 0.15, 0.25] at timestamp 50 (a pre-registered forecast)
297- # option "b" is added at timestamp 100
298- # interpreted_pmf at time 50 = [0.6, 0.4, 0.4]
299- # interpreted_pmf at time 100 = [0.6, 0.15, 0.25]
300-
301- # This allows the resolution to be an index used universally across all forecasts
302- # interpreted this way. A resolution of "b" would correspond to index `1`, meaning
303- # that the forecast would be `0.4` at time 50 and `0.15` at time 100.
304- # Similarly, a resolution of "other" would correspond to a forecast of `0.4` at time
305- # 50 and `0.25` at time 100.
306-
307- # NOTE: intepreted "PMF"s are no longer valid forecasts, and the resulting forecasts
308- # should NOT be saved.
309- # """
310- # if not options_history or len(options_history) == 1 or not forecasts:
311- # # we have no change in options, no intepretation is required
312- # return forecasts
313-
314- # list_of_all_options = get_all_options_from_history(options_history)
315-
316- # def interpret_pmf(
317- # pmf: list[float],
318- # current_options: list[str],
319- # next_options: list[str],
320- # ) -> list[float]:
321- # if len(pmf) != len(current_options):
322- # if len(pmf) < len(current_options) or len(pmf) != len(next_options):
323- # raise ValueError(
324- # f"pmf {pmf} not interpretable as "
325- # f"{current_options} or {next_options}"
326- # )
327- # # translate it into equivalent current options
328- # current_pmf = [0.0] * len(current_options)
329- # for value, opt in zip(pmf, next_options):
330- # index = current_options.index(opt) if opt in current_options else -1
331- # current_pmf[index] += value
332- # pmf = current_pmf
333- # interpreted_pmf = [
334- # pmf[current_options.index(opt) if opt in current_options else -1]
335- # for opt in list_of_all_options
336- # ]
337- # return interpreted_pmf
338-
339- # interpreted_forecasts: list[Forecast | AggregateForecast] = []
340- # options_index = -1
341- # next_step = datetime.min.replace(tzinfo=dt_timezone.utc)
342- # for forecast in forecasts:
343- # while (
344- # forecast.start_time >= next_step
345- # ): # important for forecasts to be in order
346- # options_index += 1
347- # _, current_options = options_history[options_index]
348- # if options_index + 1 < len(options_history):
349- # next_ts, next_options = options_history[options_index + 1]
350- # next_step = datetime.fromtimestamp(next_ts).replace(
351- # tzinfo=dt_timezone.utc
352- # )
353- # else: # there is no next step
354- # next_step = datetime.max.replace(tzinfo=dt_timezone.utc)
355- # next_options = current_options
356-
357- # # annotate question type for efficient get_pmf() call
358- # forecast.question_type = Question.QuestionType.MULTIPLE_CHOICE
359- # pmf = forecast.get_pmf()
360- # current_pmf = interpret_pmf(pmf, current_options, next_options)
361- # if isinstance(forecast, Forecast):
362- # forecast.probability_yes_per_category = current_pmf
363- # else:
364- # forecast.forecast_values = current_pmf
365- # if not forecast.end_time or forecast.end_time > next_step:
366- # # we need to split the forecast
367- # next_pmf = interpret_pmf(pmf, next_options, next_options)
368- # if isinstance(forecast, Forecast):
369- # extra_forecast = Forecast(
370- # probability_yes_per_category=next_pmf,
371- # start_time=next_step,
372- # end_time=forecast.end_time,
373- # author_id=forecast.author_id,
374- # question_id=forecast.question_id,
375- # post_id=forecast.post_id,
376- # source=Forecast.SourceChoices.AUTOMATIC,
377- # )
378- # else:
379- # extra_forecast = AggregateForecast(
380- # forecast_values=next_pmf,
381- # start_time=next_step,
382- # end_time=forecast.end_time,
383- # method=forecast.method,
384- # question_id=forecast.question_id,
385- # forecaster_count=forecast.forecaster_count,
386- # )
387- # forecast.end_time = next_step
388- # extra_forecast.question_type = Question.QuestionType.MULTIPLE_CHOICE
389- # interpreted_forecasts.append(extra_forecast)
390- # interpreted_forecasts.append(forecast)
391- # interpreted_forecasts.sort(key=lambda x: x.start_time)
392- # return interpreted_forecasts
0 commit comments