Skip to content
Snippets Groups Projects

Fake sampler

Merged Michael Puerrer requested to merge michael.puerrer/bilby:Fake_sampler into master
All threads resolved!

Add a "fake" sampler that reads parameters from a specified posterior file and evaluates the likelihood at these parameters. The results object is updated with these newly computed likelihood values.

One use case for this fake sampler is to test likelihood accuracy for ROQs, by comparing the full and ROQ likelihood at the same parameter space points.

I also added the set_strain_data_from_zero_noise method to InterferometerList for convenience.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Could this be altered slighty, so that the sample_file argument file doesn't just have to be a file, but could also be a Results object, or a structured np.ndarray or pandas DataFrame? The latter would be quite useful if you just want to evaluate the likelihood on a grid.

    For example we could have:

    import pandas as pd
    
    if isinstance(sample_file, str):
        self.samples = self._read_parameter_list_from_file(sample_file)
    elif isinstance(sample_file, bilby.Result)
        self.result = sample_file
    elif isinstance(sample_file, (np.ndarray, pd.DataFrame)):
        try:
            self.result.posterior = pd.DataFrame(sample_file)
        except Exception as e:
            raise RuntimeError("Problem adding samples: {}".format(e))

    As example of creating the mesh samples might be:

    a = np.linspace(0., 1., 100, dtype=[('a', 'f8')])  # grid in parameter 'a'
    b = np.linspace(0., 1., 100, dtype=[('b', 'f8')])  # grid in parameter 'b'
    
    # convert to mesh grid
    A, B = np.meshgrid(a, b)
    
    # merge flattened meshes
    import numpy.lib.recfunctions as rfn
    sample_mesh = rfn.merge_arrays([A, B], flatten=True, usemask=False)

    which could then be passed into the fake sampler.

  • Actually, my suggestion of passing a ndarray mesh may not be ideal, and should perhaps be a dictionary of grids in individual parameters. That way, the grid points are known and numerical marginalisation can be performed if required. This should probably go in its own sampler class, maybe called GridSampler.

  • @matthew-pitkin I've thought about something similar. I would actually like it to not be a Sampler, but rather just a different kind of object, I was thinking Grid. It might require different use syntax, but I think that's better than having the slightly weird case where we call something a sampler that doesn't do any stochastic sampling.

    Maybe we should move this to an issue?

  • mentioned in issue #326 (closed)

  • @michael.puerrer can you relaunch the CI?

  • Michael Puerrer resolved all discussions

    resolved all discussions

  • added 1 commit

    • 58c23a5e - Don't assign samples variable, since nothing is returned

    Compare with previous version

  • @matthew-pitkin @colm.talbot I agree that a Grid object could be useful and should be discussed separately. For posterior comparisons as intended here we need to be able to use scattered data points that don't lie on a grid.

  • added 1 commit

    Compare with previous version

  • Michael Puerrer added 19 commits

    added 19 commits

    Compare with previous version

  • Ok, the pipeline builds now. If there is anything else you'd like me to change before merging this in, let me know.

  • Gregory Ashton changed milestone to %0.4.2

    changed milestone to %0.4.2

  • Michael Puerrer resolved all discussions

    resolved all discussions

  • Michael Puerrer added 39 commits

    added 39 commits

    Compare with previous version

  • Michael Puerrer resolved all discussions

    resolved all discussions

  • Michael Puerrer resolved all discussions

    resolved all discussions

  • Thanks, this looks good to me.

  • Colm Talbot approved this merge request

    approved this merge request

  • Matthew David Pitkin approved this merge request

    approved this merge request

  • mentioned in issue #315 (closed)

  • merged

  • Colm Talbot mentioned in commit c86cb568

    mentioned in commit c86cb568

  • Please register or sign in to reply
    Loading