thomfoster / treeQuadrature

1 stars 1 forks source link

Improved styles, made the package user-friendly, and added RbfIntegrator #27

Open Daniel-Lin-S opened 2 months ago

Daniel-Lin-S commented 2 months ago

container.py

added docstrings and comments added mins and maxs handling to allow arbitrary boundaries in each dimension added filtering of points outside the container using filter_points method modified rvs to support infinite boundaries. changed Assertions to ValueErrors with clear error messages

containerIntegration.py

added docstrings to existing methods added rbfIntegral added an abstract base class ContainerIntegral and modified existing methods to a class

added gaussianProcess.py

with methods necessary to fit GP to a container

visualisation.py

added plotContainers that automatically plots all containers 1-dimensional problems are also also supported by _plotContainers1D. added plotIntegrand to visualise the integrand added plotGP which plots the posterior mean in 1-D cases.
edited _plot2DContainers method so that it supports plotting of any two dimensions for higher-dimensional problems.

exampleDistributions.py

added docstrings MixtureDistribution changed to handle arbitrary weights created abstract class Distribution to allow User to define distribution fixed Uniform.pdf:

added a test in tests/test_distributions.py to ensure Uniform.pdf returns correct values and Uniform.rvs samples are within bounds

exampleProblems.py

added docstrings Added checks to Problem.pdf on the shape of X changed original Problem to BayesProblem created a class Problem for arbitrary problems with only an integrand added Gaussian that represents integrating the pdf of any Multivariate Gaussian distribution on given boundaries added PyramidProblem that does not have rvs method to test samplers.

added sampler, uniformSampler.py, importanceSampler.py , mcmcSampler.py

to accommodate for arbitrary problems without method rvs modified TreeIntegratror so that when problem does not have rvs, self.sampler will be used. (defaults to UniformSampler) the corresponding tests can be found in tests/test_samplers.py

utils.py

added docstring added exception handling to scale (prevent scaling constant array)

added integrators/integrator.py

an abstract base class Integrator for all other integrators test_integrators has been modified to accomodate the changes

added integrators/treeIntegrator.py

an abstract base class inheriting Integrator, represents a tree-based integrator

modified __call__ to allow returning standard deviation estimation when containerIntegration method has return_std option. modified __call__ to return a dictionary, which is easier to use.

modified the tests correspondingly

added integrators/bayesMCIntegrator.py

performs Bayes Monte Carlo

and added to tests/test_integrators.py

added gpTreeIntegrator.py

a more powerful GP fitting scheme with parameter passing between containers.

and added to tests/test_integrators.py

integrators/smcIntegrator.py, integrators/vegasIntegrator.py, integrators/limitedSampleIntegrator.py, integrators/queueIntegrator.py, integrators/simpleIntegrator.py

added docstrings with examples for users modified to inherit from Integrator added better type handling (avoid Users giving wrong types as arguments) LimitedSampleIntegrator, QueueIntegrator and SimpleIntegrator now all inherit from TreeIntegrator added verbose option to TreeIntegrator for easier debugging and tracking.

added splits/split.py

an abstract base class Split for all split methods for container

splits/uniformSplit.py

implemented uniformSplit

splits/kdSplit.py, splits/minSseSplit.py

added docstrings modified to inherit from Split added a check for X with less than 2 unique values. (cannot split anymore) in KdSplit

example_multivariate_normal.ipynb

import containerIntegrals from the package instead so that Users know how to use this package

tests/test_integrators.py

added test_io for all integrators added UniformSplit and RbfIntegral to the tests

added compare_integrators.py

conveniently tests a set of integrators and problems, and writes the results into a csv file.

Daniel-Lin-S commented 1 week ago

Dear Thom, Thank you for your feedback on the ongoing projects. I have addressed all the points you mentioned. Regarding the notebook of problems, I believe Otto has already prepared one. Please let me know if there is anything else that needs attention or if further modifications are required. Best regards, Daniel

From: thomfoster @.> Date: Tuesday, 27 August 2024 at 14:14 To: thomfoster/treeQuadrature @.> Cc: Daniel Lin @.>, Author @.> Subject: Re: [thomfoster/treeQuadrature] Improved styles, made the package user-friendly, and added RbfIntegrator (PR #27)

@thomfoster approved this pull request.

This is great work Daniel. Happy to merge this into main.

Moving forward, we need to:


In treeQuadrature/container.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722186623:

  • assert y.shape[1] == 1

Why add this? What if I want to specify a container that is bounded only on 1 side for example?


In treeQuadrature/container.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722187311:

     self.D = X.shape[1]

Move shape checks inside _handle_min_max_bounds


In treeQuadrature/container.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722188757:

 def add(self, new_X, new_y):

Why do this when we've already thrown a warning?


In treeQuadrature/container.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722189899:

@@ -92,14 +216,43 @@ def X(self):

 def y(self):

     return self._y.contents

nice!


On tests/test_container.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722193903:

Nice job adding these tests


On treeQuadrature/containerIntegration/containerIntegral.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722199765:

I don't love how we've done this - I'd quite like to refactor this such that ContainerIntegrals aren't classes, they are just functions that operate on Containers and return an integral number + results dict. What do you think?


In treeQuadrature/containerIntegration/constantIntegral.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722201903:

  • '''estimate integral by the function value at mid-point of container'''

+class MedianIntegral(ContainerIntegral):

return_std breaks that containerIntegral's should always return a dict with a key of 'integral' that is a single float value. Should instead return {'integral': float, 'std': float} for the case where n==0


On treeQuadrature/containerIntegration/monteCarloIntegral.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722215573:

nice work


On treeQuadrature/gaussianProcess.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722216945:

This should be deleted right? in place of /gaussianProcess/gaussianProcess.py


In treeQuadrature/exampleProblems.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722218017:

-class Problem:

this is a crazy thing to restrict to but I guess we're doing it ahaha


On treeQuadrature/exampleDistributions.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722227163:

I think this is confusing and maybe obselete now - do you agree? we can just merge this with exampleProblems and clean up?


In treeQuadrature/splits/uniformSplit.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722231604:

  • n_divisions = kwargs.get('n_divisions', self.n_divisions)

+

If this is slow and we want to speed it up I think we can remove the for loops and do as straight numpy


On treeQuadrature/samplers/sobolSampler.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722233705:

cool! Hadn't heard of this before


On treeQuadrature/samplers/mcmcSampler.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722237004:

Nice! Wild that you implemented this yourself - i would have definitely just used a library so I learnt something here!


On treeQuadrature/samplers/lowDiscrepancySampler.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722237802:

Replication of sobolSampler.py??


In treeQuadrature/integrators/vegasIntegrator.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722240924:

     integ = vegas.Integrator([[-1.0, 1.0]] * problem.D)

Nice I like this change to using integrand


In treeQuadrature/integrators/limitedSampleIntegrator.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722292511:

@@ -26,72 +29,159 @@ def save_weights_image(q):

 plt.close()

-class LimitedSampleIntegrator:

-

+class LimitedSampleIntegrator(TreeIntegrator):

Should this inherit from QueueIntegrator?


On treeQuadrature/integrators/limitedSampleGpIntegrator.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722293376:

Isn't most of this code already written in limited sample integrator?


On treeQuadrature/integrators/integrator.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722294465:

A nice addition here would be typing the return value of the integrators, ie returning a TypedDict or dataclass that we specify must contain the 'estimate' key


On treeQuadrature/integrators/gpTreeIntegrator.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722294959:

As with the limited sample integrator, let's clean this up and make use of code sharing


On treeQuadrature/gaussianProcess/visualisation.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1722296531:

nice


On treeQuadrature/container.pyhttps://github.com/thomfoster/treeQuadrature/pull/27#discussion_r1732825925:

I think we can just do numpy.stack :)

— Reply to this email directly, view it on GitHubhttps://github.com/thomfoster/treeQuadrature/pull/27#pullrequestreview-2246193090, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ASDZYQFGLRYYZ5O3OAAJLKTZTR3UZAVCNFSM6AAAAABK2MNULCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDENBWGE4TGMBZGA. You are receiving this because you authored the thread.Message ID: @.***>