Git Product home page Git Product logo

Comments (4)

Berlyli866 avatar Berlyli866 commented on June 18, 2024 2

thanks !!! yeah i found it in the starter notebook. thank you !

from tfcausalimpact.

WillianFuks avatar WillianFuks commented on June 18, 2024 1

Looks like you optimized using hmc, in this case use the code discussed in the next cell:

def get_param_index(model, name):
    for i, v in enumerate(model.parameters):
        if v.name == name:
            return i

tf.reduce_mean(ci.model.components_by_name['SparseLinearRegression/'].params_to_weights(
    ci.model_samples[get_param_index(ci.model, 'SparseLinearRegression/_global_scale_variance')],
    ci.model_samples[get_param_index(ci.model, 'SparseLinearRegression/_global_scale_noncentered')],
    ci.model_samples[get_param_index(ci.model, 'SparseLinearRegression/_local_scale_variances')],
    ci.model_samples[get_param_index(ci.model, 'SparseLinearRegression/_local_scales_noncentered')],
    ci.model_samples[get_param_index(ci.model, 'SparseLinearRegression/_weights_noncentered')],
), axis=0)

from tfcausalimpact.

WillianFuks avatar WillianFuks commented on June 18, 2024

Hi @Berlyli866 ,

Yes, there is. Please refer to the getting_started.ipnb on section "2.5 Understanding Results", there's some discussion about this subject.

As a reference, here's an example of getting the average weights when the optimization technique is default variational inference:

tf.reduce_mean(ci.model.components_by_name['SparseLinearRegression/'].params_to_weights(
    ci.model_samples['SparseLinearRegression/_global_scale_variance'],
    ci.model_samples['SparseLinearRegression/_global_scale_noncentered'],
    ci.model_samples['SparseLinearRegression/_local_scale_variances'],
    ci.model_samples['SparseLinearRegression/_local_scales_noncentered'],
    ci.model_samples['SparseLinearRegression/_weights_noncentered'],
), axis=0)

I think TFP already offers some functions for performing this operation but couldn't update the notebook so far.

Let me know if this helps you.

from tfcausalimpact.

Berlyli866 avatar Berlyli866 commented on June 18, 2024

Hey @WillianFuks ,
i used same code and got error

ci.model.components_by_name
tf.reduce_mean(ci.model.components_by_name['SparseLinearRegression/'].params_to_weights(
    ci.model_samples['SparseLinearRegression/_global_scale_variance'],
    ci.model_samples['SparseLinearRegression/_global_scale_noncentered'],
    ci.model_samples['SparseLinearRegression/_local_scale_variances'],
    ci.model_samples['SparseLinearRegression/_local_scales_noncentered'],
    ci.model_samples['SparseLinearRegression/_weights_noncentered'],
), axis=0)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_12815/3091180208.py in <module>
      1 tf.reduce_mean(ci.model.components_by_name['SparseLinearRegression/'].params_to_weights(
----> 2     ci.model_samples['SparseLinearRegression/_global_scale_variance'],
      3     ci.model_samples['SparseLinearRegression/_global_scale_noncentered'],
      4     ci.model_samples['SparseLinearRegression/_local_scale_variances'],
      5     ci.model_samples['SparseLinearRegression/_local_scales_noncentered'],

TypeError: list indices must be integers or slices, not str

i checked the ci.model_samples it's a list of array instead of a dictionary. do you know how to know the order of ci.model_samples['SparseLinearRegression/_global_scale_variance'],
ci.model_samples['SparseLinearRegression/_global_scale_noncentered'],
ci.model_samples['SparseLinearRegression/_local_scale_variances'],
ci.model_samples['SparseLinearRegression/_local_scales_noncentered'],
ci.model_samples['SparseLinearRegression/_weights_noncentered'],
in the array ? the ci.model_samples total has 7 elements

Screenshot 2023-01-12 at 11 06 55

from tfcausalimpact.

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.