31
31
Return the finite support for a discrete univariate distribution.
32
32
Relies on Distributions.support to provide an iterable, finite range.
33
33
"""
34
- enumerate_discrete_values (dist:: Distributions.DiscreteUnivariateDistribution ) = Distributions. support (
35
- dist
36
- )
34
+ enumerate_discrete_values (dist:: Distributions.DiscreteUnivariateDistribution ) =
35
+ Distributions. support (dist)
37
36
38
37
"""
39
38
classify_node_type(dist)
@@ -77,8 +76,15 @@ struct GraphEvaluationData{TNF,TV}
77
76
node_types:: Vector{Symbol}
78
77
is_discrete_finite_vals:: Vector{Bool}
79
78
minimal_cache_keys:: Dict{Int,Vector{Int}}
79
+ marginalization_order:: Vector{Int}
80
80
end
81
81
82
+ """
83
+ GraphEvaluationData(compat constructor)
84
+
85
+ Backward-compatible constructor that fills new caching fields with defaults
86
+ when older call sites provide only the first nine fields.
87
+ """
82
88
function GraphEvaluationData (
83
89
g:: BUGSGraph ,
84
90
sorted_nodes:: Vector{<:VarName} = VarName[
@@ -114,7 +120,7 @@ function GraphEvaluationData(
114
120
end
115
121
end
116
122
117
- return GraphEvaluationData (
123
+ return GraphEvaluationData {typeof(node_function_vals),typeof(loop_vars_vals)} (
118
124
sorted_nodes,
119
125
sorted_parameters,
120
126
is_stochastic_vals,
@@ -124,6 +130,7 @@ function GraphEvaluationData(
124
130
node_types,
125
131
is_discrete_finite_vals,
126
132
Dict {Int,Vector{Int}} (),
133
+ Int[],
127
134
)
128
135
end
129
136
@@ -233,7 +240,7 @@ function BUGSModel(
233
240
JuliaBUGS. Model. _precompute_minimal_cache_keys (m, collect (1 : n))
234
241
end
235
242
# Attach minimal cache keys to GraphEvaluationData (order remains default)
236
- gd2 = GraphEvaluationData (
243
+ gd2 = GraphEvaluationData {typeof(gd.node_function_vals),typeof(gd.loop_vars_vals)} (
237
244
gd. sorted_nodes,
238
245
gd. sorted_parameters,
239
246
gd. is_stochastic_vals,
@@ -243,6 +250,7 @@ function BUGSModel(
243
250
gd. node_types,
244
251
gd. is_discrete_finite_vals,
245
252
minimal_keys,
253
+ gd. marginalization_order,
246
254
)
247
255
# Return final model with cached minimal keys
248
256
return BUGSModel (
@@ -368,7 +376,10 @@ function BUGSModel(
368
376
end
369
377
370
378
# Update graph_evaluation_data with the computed node types
371
- graph_evaluation_data = GraphEvaluationData (
379
+ graph_evaluation_data = GraphEvaluationData{
380
+ typeof (graph_evaluation_data. node_function_vals),
381
+ typeof (graph_evaluation_data. loop_vars_vals),
382
+ }(
372
383
graph_evaluation_data. sorted_nodes,
373
384
graph_evaluation_data. sorted_parameters,
374
385
graph_evaluation_data. is_stochastic_vals,
@@ -378,6 +389,7 @@ function BUGSModel(
378
389
node_types,
379
390
is_discrete_finite_vals,
380
391
Dict {Int,Vector{Int}} (),
392
+ Int[],
381
393
)
382
394
383
395
lowered_model_def, reconstructed_model_def = JuliaBUGS. _generate_lowered_model_def (
@@ -429,7 +441,9 @@ function BUGSModel(
429
441
end
430
442
431
443
# Reconstruct GraphEvaluationData while preserving classification
432
- graph_evaluation_data = GraphEvaluationData (
444
+ graph_evaluation_data = GraphEvaluationData{
445
+ typeof (new_gd. node_function_vals),typeof (new_gd. loop_vars_vals)
446
+ }(
433
447
new_gd. sorted_nodes,
434
448
new_gd. sorted_parameters,
435
449
new_gd. is_stochastic_vals,
@@ -439,6 +453,7 @@ function BUGSModel(
439
453
new_node_types,
440
454
new_is_discrete_finite_vals,
441
455
Dict {Int,Vector{Int}} (),
456
+ Int[],
442
457
)
443
458
else
444
459
log_density_computation_function = nothing
@@ -464,14 +479,17 @@ function BUGSModel(
464
479
mutable_symbols,
465
480
nothing ,
466
481
)
467
- # Precompute minimal cache keys for the default order (1:n)
482
+ # Precompute marginalization order and minimal cache keys once
468
483
n = length (graph_evaluation_data. sorted_nodes)
469
- sorted_indices = collect ( 1 : n )
484
+ sorted_indices = JuliaBUGS . Model . _compute_marginalization_order (model_without_min_keys )
470
485
minimal_keys = JuliaBUGS. Model. _precompute_minimal_cache_keys (
471
486
model_without_min_keys, sorted_indices
472
487
)
473
- # Attach minimal keys to GraphEvaluationData
474
- graph_evaluation_data_with_keys = GraphEvaluationData (
488
+ # Attach cached order and keys to GraphEvaluationData
489
+ graph_evaluation_data_with_keys = GraphEvaluationData{
490
+ typeof (graph_evaluation_data. node_function_vals),
491
+ typeof (graph_evaluation_data. loop_vars_vals),
492
+ }(
475
493
graph_evaluation_data. sorted_nodes,
476
494
graph_evaluation_data. sorted_parameters,
477
495
graph_evaluation_data. is_stochastic_vals,
@@ -481,6 +499,7 @@ function BUGSModel(
481
499
graph_evaluation_data. node_types,
482
500
graph_evaluation_data. is_discrete_finite_vals,
483
501
minimal_keys,
502
+ sorted_indices,
484
503
)
485
504
486
505
# Return final model with cached minimal keys
0 commit comments