Probabilistic
inspeqtor.models.probabilistic
LearningModel
The learning model.
Source code in src/inspeqtor/v1/probabilistic.py
363 364 365 366 367 | |
make_probabilistic_model
make_probabilistic_model(
predictive_model: Callable[..., ndarray],
shots: int = 1,
block_graybox: bool = False,
separate_observables: bool = False,
log_expectation_values: bool = False,
)
Make probabilistic model from the Statistical model with priors
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_model
|
Module
|
The statistical based model, currently only support flax.linen module |
required |
model_prediction_to_expvals_fn
|
Callable[..., ndarray]
|
Function to convert output from model to expectation values array |
required |
bnn_prior
|
dict[str, Distribution] | Distribution
|
The priors of BNN. Defaults to dist.Normal(0.0, 1.0). |
required |
shots
|
int
|
The number of shots forcing PGM to sample. Defaults to 1. |
1
|
block_graybox
|
bool
|
If true, the latent variables in Graybox model will be hidden, i.e. not traced by |
False
|
enable_bnn
|
bool
|
If true, the statistical model will be convert to probabilistic model. Defaults to True. |
required |
separate_observables
|
bool
|
If true, the observable will be separate into dict form. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
|
typing.Callable: Probabilistic Graybox Model |
Source code in src/inspeqtor/v1/probabilistic.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | |
get_args_of_distribution
get_args_of_distribution(x)
Get the arguments used to construct Distribution, if the provided parameter is not Distribution, return it.
So that the function can be used with jax.tree.map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
Maybe Distribution |
required |
Returns:
| Type | Description |
|---|---|
|
typing.Any: Argument of Distribution if Distribution is provided. |
Source code in src/inspeqtor/v1/probabilistic.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
construct_normal_priors
construct_normal_priors(posterior)
Construct a dict of Normal Distributions with posterior
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
posterior
|
Any
|
Dict of Normal distribution arguments |
required |
Returns:
| Type | Description |
|---|---|
|
typing.Any: dict of Normal distributions |
Source code in src/inspeqtor/v1/probabilistic.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
construct_normal_prior_from_samples
construct_normal_prior_from_samples(
posterior_samples: dict[str, ndarray],
) -> dict[str, Distribution]
Construct a dict of Normal Distributions with posterior sample
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
posterior_samples
|
dict[str, ndarray]
|
Posterior sample |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Distribution]
|
dict[str, dist.Distribution]: dict of Normal Distributions |
Source code in src/inspeqtor/v1/probabilistic.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
make_normal_posterior_dist_fn_from_svi_result
make_normal_posterior_dist_fn_from_svi_result(
key: ndarray,
guide: Callable,
params: dict[str, ndarray],
num_samples: int,
prefix: str,
) -> Callable[[str, tuple[int, ...]], Distribution]
This function create a get posterior function to be used with numpyro.contrib.module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
ndarray
|
The random key |
required |
guide
|
Callable
|
The guide (variational distribution) |
required |
params
|
dict[str, ndarray]
|
The variational parameters |
required |
num_samples
|
int
|
The number of sample for approxiatation the posterior distributions |
required |
Examples:
prefix = "graybox"
prior_fn = make_normal_posterior_dist_fn_from_svi_result(
jax.random.key(0), guide, result.params, 10_000, prefix
)
graybox_model = sq.probabilistic.make_flax_probabilistic_graybox_model(
name=prefix,
base_model=base_model,
adapter_fn=sq.probabilistic.observable_to_expvals,
prior=prior_fn,
)
posterior_model = sq.probabilistic.make_probabilistic_model(
predictive_model=graybox_model, log_expectation_values=True
)
Returns:
| Type | Description |
|---|---|
Callable[[str, tuple[int, ...]], Distribution]
|
typing.Callable[[str, tuple[int, ...]], dist.Distribution]: The function that return posterior distribution |
Source code in src/inspeqtor/v1/probabilistic.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
make_predictive_fn
make_predictive_fn(
posterior_model, learning_model: LearningModel
)
Construct predictive model from the probabilsitic model. This function does not relied on guide and the variational parameters
Examples:
characterized_result = sq.probabilistic.SVIResult.from_file(
PGM_model_path / "model.json"
)
base_model = sq.models.library.linen.WoModel(
shared_layers=characterized_result.config["model_config"]["hidden_sizes"][0],
pauli_layers=characterized_result.config["model_config"]["hidden_sizes"][1],
)
graybox_model = sq.probabilistic.make_flax_probabilistic_graybox_model(
name="graybox",
base_model=base_model,
adapter_fn=sq.probabilistic.observable_to_expvals,
prior=dist.Normal(0, 1),
)
model = sq.probabilistic.make_probabilistic_model(
graybox_probabilistic_model=graybox_model,
)
# initialize guide
guide = sq.probabilistic.auto_diagonal_normal_guide(
model,
ml.custom_feature_map(loaded_data.control_parameters),
loaded_data.unitaries,
jnp.zeros(shape=(shots, loaded_data.control_parameters.shape[0], 18)),
)
priors = {
k.strip("graybox/"): v
for k, v in make_prior_from_params(guide, characterized_result.params).items()
}
graybox_model = sq.probabilistic.make_flax_probabilistic_graybox_model(
name="graybox",
base_model=base_model,
adapter_fn=sq.probabilistic.observable_to_expvals,
prior=priors,
)
posterior_model = sq.probabilistic.make_probabilistic_model(
graybox_probabilistic_model=graybox_model,
shots=shots,
block_graybox=True,
log_expectation_values=True,
)
predicetive_fn = sq.probabilistic.make_predictive_fn(
posterior_model, sq.probabilistic.LearningModel.BernoulliProbs
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
posterior_model
|
Any
|
probabilsitic model |
required |
learning_model
|
LearningModel
|
description |
required |
Source code in src/inspeqtor/v1/probabilistic.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |
make_pdf
make_pdf(sample: ndarray, bins: int, srange=(-1, 1))
Make the numberical PDF from given sample using histogram method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
ndarray
|
Sample to make PDF. |
required |
bins
|
int
|
The number of interval bin. |
required |
srange
|
tuple
|
The range of the pdf. Defaults to (-1, 1). |
(-1, 1)
|
Returns:
| Type | Description |
|---|---|
|
typing.Any: The approximated numerical PDF |
Source code in src/inspeqtor/v1/probabilistic.py
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | |
safe_kl_divergence
safe_kl_divergence(p: ndarray, q: ndarray)
Calculate the KL divergence where the infinity is converted to zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
ndarray
|
The left PDF |
required |
q
|
ndarray
|
The right PDF |
required |
Returns:
| Type | Description |
|---|---|
|
jnp.ndarray: The KL divergence |
Source code in src/inspeqtor/v1/probabilistic.py
476 477 478 479 480 481 482 483 484 485 486 | |
kl_divergence
kl_divergence(p: ndarray, q: ndarray)
Calculate the KL divergence
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
ndarray
|
The left PDF |
required |
q
|
ndarray
|
The right PDF |
required |
Returns:
| Type | Description |
|---|---|
|
jnp.ndarray: The KL divergence |
Source code in src/inspeqtor/v1/probabilistic.py
489 490 491 492 493 494 495 496 497 498 499 | |
safe_jensenshannon_divergence
safe_jensenshannon_divergence(p: ndarray, q: ndarray)
Calculate Jensen-Shannon Divergnece using KL divergence. Implement following: https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.jensenshannon.html
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
ndarray
|
The left PDF |
required |
q
|
ndarray
|
The right PDF |
required |
Returns:
| Type | Description |
|---|---|
|
typing.Any: description |
Source code in src/inspeqtor/v1/probabilistic.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 | |
jensenshannon_divergence_from_pmf
jensenshannon_divergence_from_pmf(p: ndarray, q: ndarray)
Calculate the Jensen-Shannon Divergence from PMF
Example
key = jax.random.key(0)
key_1, key_2 = jax.random.split(key)
sample_1 = jax.random.normal(key_1, shape=(10000, ))
sample_2 = jax.random.normal(key_2, shape=(10000, ))
# Determine srange from sample
merged_sample = jnp.concat([sample_1, sample_2])
srange = jnp.min(merged_sample), jnp.max(merged_sample)
# https://stats.stackexchange.com/questions/510699/discrete-kl-divergence-with-decreasing-bin-width
# Recommend this book: https://catalog.lib.uchicago.edu/vufind/Record/6093380/TOC
bins = int(2 * (sample_2.shape[0]) ** (1/3))
# bins = 10
dis_1 = sq.probabilistic.make_pdf(sample_1, bins=bins, srange=srange)
dis_2 = sq.probabilistic.make_pdf(sample_2, bins=bins, srange=srange)
jsd = sq.probabilistic.jensenshannon_divergence_from_pdf(dis_1, dis_2)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
ndarray
|
The 1st probability mass function |
required |
q
|
ndarray
|
The 1st probability mass function |
required |
Returns:
| Type | Description |
|---|---|
|
jnp.ndarray: The Jensen-Shannon Divergence of p and q |
Source code in src/inspeqtor/v1/probabilistic.py
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 | |
jensenshannon_divergence_from_sample
jensenshannon_divergence_from_sample(
sample_1: ndarray, sample_2: ndarray
) -> ndarray
Calculate the Jensen-Shannon Divergence from sample
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_1
|
ndarray
|
The left PDF |
required |
sample_2
|
ndarray
|
The right PDF |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: The Jensen-Shannon Divergence of p and q |
Source code in src/inspeqtor/v1/probabilistic.py
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | |
batched_matmul
batched_matmul(x, w, b)
A specialized batched matrix multiplication of weight and input x, then add the bias.
This function is intended to be used in dense_layer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
The input x |
required |
w
|
ndarray
|
The weight to multiply to x |
required |
b
|
ndarray
|
The bias |
required |
Returns:
| Type | Description |
|---|---|
|
jnp.ndarray: Output of the operations. |
Source code in src/inspeqtor/v1/probabilistic.py
579 580 581 582 583 584 585 586 587 588 589 590 591 | |
get_trace
get_trace(fn, key=key(0))
Convinent function to get a trace of the probabilistic model in numpyro.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
function
|
The probabilistic model in numpyro. |
required |
key
|
ndarray
|
The random key. Defaults to jax.random.key(0). |
key(0)
|
Source code in src/inspeqtor/v1/probabilistic.py
594 595 596 597 598 599 600 601 602 603 604 605 | |
default_priors_fn
default_priors_fn(
name: str, shape: tuple[int, ...]
) -> Distribution
This is a default prior function for the dense_layer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The site name of the parameters, if end with |
required |
Returns:
| Type | Description |
|---|---|
Distribution
|
typing.Any: description |
Source code in src/inspeqtor/v1/probabilistic.py
608 609 610 611 612 613 614 615 616 617 618 619 620 621 | |
dense_layer
dense_layer(
x: ndarray,
name: str,
in_features: int,
out_features: int,
priors_fn: Callable[
[str, tuple[int, ...]], Distribution
] = default_priors_fn,
)
A custom probabilistic dense layer for neural network model.
This function intended to be used with numpyro
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
The input x |
required |
name
|
str
|
Site name of the layer |
required |
in_features
|
int
|
The size of the feature. |
required |
out_features
|
int
|
The desired size of the output feature. |
required |
priors_fn
|
Callable[[str], Distribution]
|
The prior function to be used for initializing prior distribution. Defaults to default_priors_fn. |
default_priors_fn
|
Returns:
| Type | Description |
|---|---|
|
typing.Any: Output of the layer given x. |
Source code in src/inspeqtor/v1/probabilistic.py
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 | |
init_default
init_default(params_name: str)
The initialization function for deterministic dense layer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params_name
|
str
|
The site name |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
Unsupport site name |
Returns:
| Type | Description |
|---|---|
|
typing.Any: The function to be used for parameters init given site name. |
Source code in src/inspeqtor/v1/probabilistic.py
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 | |
dense_deterministic_layer
dense_deterministic_layer(
x,
name: str,
in_features: int,
out_features: int,
batch_shape: tuple[int, ...] = (),
init_fn=init_default,
)
The deterministic dense layer, to be used with SVI optimizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
The input feature |
required |
name
|
str
|
The site name |
required |
in_features
|
int
|
The size of the input features |
required |
out_features
|
int
|
The desired size of the output features. |
required |
batch_shape
|
tuple[int, ...]
|
The batch size of the x. Defaults to (). |
()
|
init_fn
|
Any
|
Initilization function of the model parameters. Defaults to init_default. |
init_default
|
Returns:
| Type | Description |
|---|---|
|
typing.Any: The output of the layer given x. |
Source code in src/inspeqtor/v1/probabilistic.py
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 | |
make_posteriors_fn
make_posteriors_fn(
key: ndarray, guide, params, num_samples=10000
)
Make the posterior distribution function that will return the posterior of parameter of the given name, from guide and parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
guide
|
Any
|
The guide function |
required |
params
|
Any
|
The parameters of the guide |
required |
num_samples
|
int
|
The sample size. Defaults to 10000. |
10000
|
Returns:
| Type | Description |
|---|---|
|
typing.Any: A function of parameter name that return the sample from the posterior distribution of the parameters. |
Source code in src/inspeqtor/v1/probabilistic.py
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 | |
auto_diagonal_normal_guide
auto_diagonal_normal_guide(
model,
*args,
block_sample: bool = False,
init_loc_fn=zeros,
key: ndarray = key(0),
)
Automatically generate guide from given model. Expected to be initialized with the example input of the model. The given input should also including the observed site. The blocking capability is intended to be used in the when the guide will be used with its corresponding model in anothe model. This is the avoid site name duplication, while allows for model to use newly sample from the guide.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
The probabilistic model. |
required |
block_sample
|
bool
|
Flag to block the sample site. Defaults to False. |
False
|
init_loc_fn
|
Any
|
Initialization of guide parameters function. Defaults to jnp.zeros. |
zeros
|
Returns:
| Type | Description |
|---|---|
|
typing.Any: description |
Source code in src/inspeqtor/v1/probabilistic.py
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 | |
auto_diagonal_normal_guide_v2
auto_diagonal_normal_guide_v2(
model,
*args,
init_dist_fn=init_normal_dist_fn,
init_params_fn=init_params_fn,
block_sample: bool = False,
key: ndarray = key(0),
)
Automatically generate guide from given model. Expected to be initialized with the example input of the model. The given input should also including the observed site. The blocking capability is intended to be used in the when the guide will be used with its corresponding model in anothe model. This is the avoid site name duplication, while allows for model to use newly sample from the guide.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
The probabilistic model. |
required |
block_sample
|
bool
|
Flag to block the sample site. Defaults to False. |
False
|
init_loc_fn
|
Any
|
Initialization of guide parameters function. Defaults to jnp.zeros. |
required |
Returns:
| Type | Description |
|---|---|
|
typing.Any: description |
Source code in src/inspeqtor/v1/probabilistic.py
842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 | |
make_predictive_fn_v2
make_predictive_fn_v2(model, guide, params, shots: int)
Make a postirior predictive model function from model, guide, SVI parameters, and the number of shots. This version relied explicitly on the guide and variational parameters. It might be slow than the first version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Probabilistic model. |
required |
guide
|
Any
|
Gudie corresponded to the model |
required |
params
|
Any
|
SVI parameters of the guide |
required |
shots
|
int
|
The number of shots |
required |
Returns:
| Type | Description |
|---|---|
|
typing.Any: The posterior predictive model. |
Source code in src/inspeqtor/v1/probabilistic.py
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 | |
make_predictive_SGM_model
make_predictive_SGM_model(
model: Module,
model_params,
output_to_expectation_values_fn,
shots: int,
)
Make a predictive model from given SGM model, the model parameters, and number of shots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
Flax model |
required |
model_params
|
Any
|
The model parameters. |
required |
shots
|
int
|
The number of shots. |
required |
Source code in src/inspeqtor/v1/probabilistic.py
971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 | |
make_predictive_MCDGM_model
make_predictive_MCDGM_model(model: Module, model_params)
Make a predictive model from given Monte-Carlo Dropout Graybox model, and the model parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
Monte-Carlo Dropout Graybox model |
required |
model_params
|
Any
|
The model parameters |
required |
Source code in src/inspeqtor/v1/probabilistic.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 | |
make_predictive_resampling_model
make_predictive_resampling_model(
predictive_fn: Callable[[ndarray, ndarray], ndarray],
shots: int,
) -> Callable[[ndarray, ndarray, ndarray], ndarray]
Make a binary predictive model from given SGM model, the model parameters, and number of shots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictive_fn
|
Callable[[ndarray, ndarray], ndarray]
|
The predictive_fn embeded with the SGM model. |
required |
shots
|
int
|
The number of shots. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[ndarray, ndarray, ndarray], ndarray]
|
typing.Callable[[jnp.ndarray, jnp.ndarray, jnp.ndarray], jnp.ndarray]: Binary predictive model. |
Source code in src/inspeqtor/v1/probabilistic.py
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 | |
make_probabilistic_graybox_model
make_probabilistic_graybox_model(model, adapter_fn)
This function make a probabilistic graybox model using custom numpyro BNN model
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
_type_
|
description |
required |
adapter_fn
|
_type_
|
description |
required |
Source code in src/inspeqtor/v1/probabilistic.py
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 | |
auto_diagonal_normal_guide_v3
auto_diagonal_normal_guide_v3(
model,
*args,
init_dist_fn=bnn_init_dist_fn,
init_params_fn=bnn_init_params_fn,
dist_transform_fn=default_transform_dist_fn,
block_sample: bool = False,
key: ndarray = key(0),
)
Automatically generate guide from given model. Expected to be initialized with the example input of the model. The given input should also including the observed site. The blocking capability is intended to be used in the when the guide will be used with its corresponding model in anothe model. This is the avoid site name duplication, while allows for model to use newly sample from the guide.
Notes
This version enable even more flexible initialization strategy. This function intended to be able to be compatible with auto marginal guide.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
The probabilistic model. |
required |
block_sample
|
bool
|
Flag to block the sample site. Defaults to False. |
False
|
init_loc_fn
|
Any
|
Initialization of guide parameters function. Defaults to jnp.zeros. |
required |
Returns:
| Type | Description |
|---|---|
|
typing.Any: description |
Source code in src/inspeqtor/v1/probabilistic.py
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 | |
make_posterior_fn
make_posterior_fn(
params, get_dist_fn: Callable[[str], Any]
)
This function create a posterior function to make a posterior predictive model
Examples:
posterior_model = sq.probabilistic.make_probabilistic_model(
predictive_model=partial(
probabilistic_graybox_model,
priors_fn=make_posterior_fn(result.params, init_bnn_dist_fn),
),
log_expectation_values=True,
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
_type_
|
The variational parameters from SVI |
required |
get_dist_fn
|
Callable[[str], Distribution]
|
The function that return function given name |
required |
Source code in src/inspeqtor/v1/probabilistic.py
1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 | |