Pathfinder result

Hello, I am using the Pathfinder method from pymc-extras. After running it, it seems to print out a table like the one below. I would like to save these results instead of just printing them. What is the recommended way to do this?

Pathfinder Results                         
                                           
  No. model parameters     2               
                                           
  Configuration:                           
  num_draws_per_path       10000           
  history size (maxcor)    5               
  max iterations           1000            
  ftol                     1.00e-05        
  gtol                     1.00e-08        
  max line search          1000            
  jitter                   2.0             
  epsilon                  1.00e-08        
  ELBO draws               100             
                                           
  LBFGS Status:                            
  CONVERGED                4               
  L-BFGS iterations        mean 6 ± std 0  
                                           
  Path Status:                             
  SUCCESS                  4               
  ELBO argmax              mean 4 ± std 1  
                                           
  Importance Sampling:                     
  Method                   psis            
  Pareto k                 0.55            
                                           
  Timing (seconds):                        
  Compile                  96.05           
  Compute                  23.24           
  Total                    119.29 

fit_pathfinder returns an InferenceData object that will contain all of that information, in addition to the draws from the approximate posterior.

Thank you, but I still don’t know how to access it.

As far as I understand, I need to access the MultiPathfinderResult class, but when creating idata, it seems to only use the samples from this result. It doesn’t look like all the outputs of the class are being used, but rather that only the results are being printed when the class is constructed. Could you please explain this a bit more?

Here is the code I have checked:

mp_result = multipath_pathfinder(
    model,
    num_paths=num_paths,
    num_draws=num_draws,
    num_draws_per_path=num_draws_per_path,
    maxcor=maxcor,
    maxiter=maxiter,
    ftol=ftol,
    gtol=gtol,
    maxls=maxls,
    num_elbo_draws=num_elbo_draws,
    jitter=jitter,
    epsilon=epsilon,
    importance_sampling=importance_sampling,
    progressbar=progressbar,
    concurrent=concurrent,
    random_seed=random_seed,
    pathfinder_kwargs=pathfinder_kwargs,
    compile_kwargs=compile_kwargs,
)
pathfinder_samples = mp_result.samples

idata = convert_flat_trace_to_idata(
    pathfinder_samples,
    postprocessing_backend=postprocessing_backend,
    inference_backend=inference_backend,
    model=model,
    importance_sampling=importance_sampling,
)

My mistake! I could have sworn we were adding this info to the InferenceData object, but apparently not. I will create an issue to do this.

So, I’ve just merged this PR which adds a pathfinder group to the InferenceData object returned by fit_pathfinder. It will be available in the next release of pymc-extras.

1 Like

Thank you! I hope the next version comes out soon.