Git Product home page Git Product logo

Comments (3)

uomodellamansarda avatar uomodellamansarda commented on May 16, 2024

It's a very interesting question.
I don't have the answer sadly.

In general the half normal is the standard for Bayesian Inference, but you can use also other distribution based on this discussion with some reference.

Probably the answer is in this piece of the code, but I don't know enough numpyro to provide a useful solution.
Source Code

def _preprocess_custom_priors(
      self,
      custom_priors: Dict[str, Prior]) -> MutableMapping[str, Prior]:
    """Preprocesses the user input custom priors to Numpyro distributions.


    If numpyro distributions are given they remains untouched, however if any
    other option is passed, it is passed to the default distribution to alter
    its constructor values.

    Args:
      custom_priors: Mapping of the name of the prior to its custom value.

    Returns:
      A mapping of names to numpyro distributions based on user input and
        default values.
    """

from lightweight_mmm.

gustfon avatar gustfon commented on May 16, 2024

Thanks for your answer, @uomodellamansarda!

from lightweight_mmm.

uomodellamansarda avatar uomodellamansarda commented on May 16, 2024

I am still struggling to understand how to provide previous information to the model.
I don't know @gustfon if you were able to do that.

Based on the documentation to use prior information, it seems that we need to provide to the LightweightMMM object a custom_priors argument.

custom_priors: MutableMapping[str, Prior] = dataclasses.field( init=False, repr=False, hash=False, compare=True)

It takes a str and a Prior.

How should be the right format to provide Prior?
For example, if I know that:

  • YouTube follows an Half Normal Numpyro Distribution with a mean value of 0.025 and variance 0.01.
  • I have other three media channels, Facebook - Radio - TV where I don't know the coefficient mean value

How can I provide this information to my model?

custom_priors = { "YouTube" : dist.Normal( mean = 0.025,variance = 0.01) "Facebook": "" "Radio": "" "TV": "" }

Because I am struggling to understand this step:

 """
    default_priors = {
        **models._get_default_priors(),
        **models._get_transform_default_priors()[self.model_name]
    }
    # Checking that the key is contained in custom_priors has already been done
    # at this point in the fit function.
    for prior_name in custom_priors:
      if isinstance(custom_priors[prior_name], numbers.Number):
        custom_priors[prior_name] = default_priors[prior_name].__class__(
            custom_priors[prior_name])
      elif (isinstance(custom_priors[prior_name], collections.abc.Sequence) and
            not isinstance(custom_priors[prior_name], str)):
        custom_priors[prior_name] = default_priors[prior_name].__class__(
            *custom_priors[prior_name])
      elif isinstance(custom_priors[prior_name], dict):
        custom_priors[prior_name] = default_priors[prior_name].__class__(
            **custom_priors[prior_name])
      elif not isinstance(custom_priors[prior_name], dist.Distribution):
        raise ValueError(
            "Priors given must be a Numpyro distribution or one of the "
            "following to fit in the constructor of our default Numpyro "
            "distribution. It could be given as args or kwargs as long as it "
            "is the correct format for such object. Please refer to our "
            "documentation on custom priors to know more.")
    return custom_priors

from lightweight_mmm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.