Closed Berlyli866 closed 1 year ago
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.
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
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)
thanks !!! yeah i found it in the starter notebook. thank you !
Is there a way we can check the Beta of the regressors we have in the model? if we have multiple regressors in the model and want to see the contribution of each regressor to the accumulative impact, how do we process it? the idea is to see what regressors' importance rank and how much the impact is for each regressor for a significant intervention effect on y
thanks for your insights.