Plot different methods side by side Args: dataset: str, name of the dataset methods: list of str, names of methods to plot (e.g. ['timeMCL', 'timeGrad', 'deepAR']) num_hyps: int, number of hypotheses suffixes: dict, mapping method names to their suffixes (e.g
(dataset, methods, num_hyps, suffixes, rows=6, cols=3, dims_to_plot=None, seed=None)
| 414 | plot_mcl(target_df, hypothesis_forecasts, forecast_length, rows=rows, cols=1, plot_mean=plot_mean, context_points=context_points, freq_type=freq_type, extract_unique=extract_unique, save_path=save_path, is_mcl=is_mcl, plot_p=plot_p, main_color=main_color, mean_color=mean_color, dataset=dataset, seed=seed) |
| 415 | |
| 416 | def plot_multiple_methods(dataset, methods, num_hyps, suffixes, rows=6, cols=3, dims_to_plot=None, seed=None): |
| 417 | """ |
| 418 | Plot different methods side by side |
| 419 | Args: |
| 420 | dataset: str, name of the dataset |
| 421 | methods: list of str, names of methods to plot (e.g. ['timeMCL', 'timeGrad', 'deepAR']) |
| 422 | num_hyps: int, number of hypotheses |
| 423 | suffixes: dict, mapping method names to their suffixes (e.g. {'timeMCL': ['amcl', 'relaxed']}) |
| 424 | rows: int, number of rows |
| 425 | cols: int, number of columns (should match total number of methods including variants) |
| 426 | """ |
| 427 | # First pass: find global min and max probabilities for MCL methods |
| 428 | global_min_prob = float('inf') |
| 429 | global_max_prob = float('-inf') |
| 430 | |
| 431 | for method in methods: |
| 432 | if 'MCL' in method: |
| 433 | print('method', method) |
| 434 | if method in suffixes: |
| 435 | method_suffixes = suffixes[method] |
| 436 | else: |
| 437 | method_suffixes = [None] |
| 438 | |
| 439 | for suffix in method_suffixes: |
| 440 | logdir = find_last_log_dir(dataset, method, num_hyps, suffix, seed) |
| 441 | if logdir is not None: |
| 442 | with open(f"{logdir}/hypothesis_forecasts.pkl", "rb") as f: |
| 443 | import pickle |
| 444 | hypothesis_forecasts = pickle.load(f) |
| 445 | |
| 446 | hypothesis_forecasts, probabilities = extract_unique_forecasts(hypothesis_forecasts) |
| 447 | |
| 448 | print('probabilities', probabilities.shape) |
| 449 | # Update global min and max |
| 450 | min_prob = min(probabilities[h_idx][0,0] for h_idx in range(len(hypothesis_forecasts))) |
| 451 | max_prob = max(probabilities[h_idx][0,0] for h_idx in range(len(hypothesis_forecasts))) |
| 452 | global_min_prob = min(global_min_prob, min_prob) |
| 453 | global_max_prob = max(global_max_prob, max_prob) |
| 454 | |
| 455 | # Create figure with a special layout for the sidebar |
| 456 | fig = plt.figure(figsize=(9*cols + 3, 5.5*rows)) |
| 457 | |
| 458 | # Create GridSpec to manage subplot layout |
| 459 | from matplotlib.gridspec import GridSpec |
| 460 | width_ratios = [] |
| 461 | for _ in range(cols-1): |
| 462 | width_ratios.append(1) # Original column width |
| 463 | width_ratios.append(0.1) # Blank column for spacing |
| 464 | width_ratios.append(1) # Last column |
| 465 | width_ratios.append(0.01) # Last blank column |
| 466 | width_ratios.append(0.1) # Colorbar column |
| 467 | |
| 468 | num_columns = cols * 2 + 1 # Original columns + blank columns + colorbar column |
| 469 | gs = GridSpec(rows+1, num_columns, width_ratios=width_ratios, wspace=0, height_ratios=[0.05] + [1]*rows) |
| 470 | |
| 471 | # Create main plot axes |
| 472 | axs = [] |
| 473 | for i in range(rows): |
no test coverage detected