324
324
function premade_categorical_3level (config:: Dict ; verbose:: Bool = true )
325
325
326
326
# Defaults
327
- spec_defaults = Dict (
327
+ defaults = Dict (
328
328
" n_categories" => 4 ,
329
329
(" x2" , " evolution_rate" ) => 0 ,
330
330
(" x2" , " initial_mean" ) => 0 ,
@@ -338,18 +338,18 @@ function premade_categorical_3level(config::Dict; verbose::Bool = true)
338
338
339
339
# Warn the user about used defaults and misspecified keys
340
340
if verbose
341
- warn_premade_defaults (spec_defaults , config)
341
+ warn_premade_defaults (defaults , config)
342
342
end
343
343
344
344
# Merge to overwrite defaults
345
- config = merge (spec_defaults , config)
345
+ config = merge (defaults , config)
346
346
347
347
348
348
# #Prep category node parent names
349
349
# Vector for category node binary parent names
350
- category_binary_parent_names = []
350
+ category_binary_parent_names = Vector {String} ()
351
351
# Vector for binary node continuous parent names
352
- binary_continuous_parent_names = []
352
+ binary_continuous_parent_names = Vector {String} ()
353
353
# Populate the above vectors with node names
354
354
for category_number = 1 : config[" n_categories" ]
355
355
push! (category_binary_parent_names, " x1_" * string (category_number))
@@ -361,7 +361,7 @@ function premade_categorical_3level(config::Dict; verbose::Bool = true)
361
361
input_nodes = Dict (" name" => " u" , " type" => " categorical" )
362
362
363
363
# #List of state nodes
364
- state_nodes = [Dict {String, Any} (" name" => " x1" , " type" => " categorical" )]
364
+ state_nodes = [Dict {String,Any} (" name" => " x1" , " type" => " categorical" )]
365
365
366
366
# Add category node binary parents
367
367
for node_name in category_binary_parent_names
@@ -431,4 +431,184 @@ function premade_categorical_3level(config::Dict; verbose::Bool = true)
431
431
edges = edges,
432
432
verbose = false ,
433
433
)
434
- end
434
+ end
435
+
436
+ function premade_categorical_3level_state_transitions (config:: Dict ; verbose:: Bool = true )
437
+
438
+ # Defaults
439
+ defaults = Dict (
440
+ " n_categories" => 4 ,
441
+ (" x2" , " evolution_rate" ) => 0 ,
442
+ (" x2" , " initial_mean" ) => 0 ,
443
+ (" x2" , " initial_precision" ) => 1 ,
444
+ (" x3" , " evolution_rate" ) => 0 ,
445
+ (" x3" , " initial_mean" ) => 0 ,
446
+ (" x3" , " initial_precision" ) => 1 ,
447
+ (" x1" , " x2" , " value_coupling" ) => 1 ,
448
+ (" x2" , " x3" , " volatility_coupling" ) => 1 ,
449
+ )
450
+
451
+ # Warn the user about used defaults and misspecified keys
452
+ if verbose
453
+ warn_premade_defaults (defaults, config)
454
+ end
455
+
456
+ # Merge to overwrite defaults
457
+ config = merge (defaults, config)
458
+
459
+
460
+ # #Prepare node names
461
+ # Empty lists
462
+ categorical_input_node_names = Vector {String} ()
463
+ categorical_state_node_names = Vector {String} ()
464
+ categorical_node_binary_parent_names = Vector {String} ()
465
+ binary_node_continuous_parent_names = Vector {String} ()
466
+
467
+ # Go through each category that the transition may have been from
468
+ for category_from = 1 : config[" n_categories" ]
469
+ # One input node and its state node parent for each
470
+ push! (categorical_input_node_names, " u" * string (category_from))
471
+ push! (categorical_state_node_names, " x1_" * string (category_from))
472
+ # Go through each category that the transition may have been to
473
+ for category_to = 1 : config[" n_categories" ]
474
+ # Each categorical state node has a binary parent for each
475
+ push! (
476
+ categorical_node_binary_parent_names,
477
+ " x1_" * string (category_from) * " _" * string (category_to),
478
+ )
479
+ # And each binary parent has a continuous parent of its own
480
+ push! (
481
+ binary_node_continuous_parent_names,
482
+ " x2_" * string (category_from) * " _" * string (category_to),
483
+ )
484
+ end
485
+ end
486
+
487
+ # #Create input nodes
488
+ # Initialize list
489
+ input_nodes = Vector {Dict} ()
490
+
491
+ # For each categorical input node
492
+ for node_name in categorical_input_node_names
493
+ # Add it to the list
494
+ push! (input_nodes, Dict (" name" => node_name, " type" => " categorical" ))
495
+ end
496
+
497
+ # #Create state nodes
498
+ # Initialize list
499
+ state_nodes = Vector {Dict} ()
500
+
501
+ # For each cateogrical state node
502
+ for node_name in categorical_state_node_names
503
+ # Add it to the list
504
+ push! (state_nodes, Dict (" name" => node_name, " type" => " categorical" ))
505
+ end
506
+
507
+ # For each categorical node binary parent
508
+ for node_name in categorical_node_binary_parent_names
509
+ # Add it to the list
510
+ push! (state_nodes, Dict (" name" => node_name, " type" => " binary" ))
511
+ end
512
+
513
+ # For each binary node continuous parent
514
+ for node_name in binary_node_continuous_parent_names
515
+ # Add it to the list, with parameter settings from the config
516
+ push! (
517
+ state_nodes,
518
+ Dict (
519
+ " name" => node_name,
520
+ " type" => " continuous" ,
521
+ " evolution_rate" => config[(" x2" , " evolution_rate" )],
522
+ " initial_mean" => config[(" x2" , " initial_mean" )],
523
+ " initial_precision" => config[(" x2" , " initial_precision" )],
524
+ ),
525
+ )
526
+ end
527
+
528
+ # Add the shared volatility parent of the continuous nodes
529
+ push! (
530
+ state_nodes,
531
+ Dict (
532
+ " name" => " x3" ,
533
+ " type" => " continuous" ,
534
+ " evolution_rate" => config[(" x3" , " evolution_rate" )],
535
+ " initial_mean" => config[(" x3" , " initial_mean" )],
536
+ " initial_precision" => config[(" x3" , " initial_precision" )],
537
+ ),
538
+ )
539
+
540
+ # #Create child-parent relations
541
+ # Initialize list
542
+ edges = Vector {Dict} ()
543
+
544
+ # For each categorical input node and its corresponding state node parent
545
+ for (child_name, parent_name) in
546
+ zip (categorical_input_node_names, categorical_state_node_names)
547
+ # Add their relation to the list
548
+ push! (edges, Dict (" child" => child_name, " value_parents" => parent_name))
549
+ end
550
+
551
+ # For each categorical state node
552
+ for child_node_name in categorical_state_node_names
553
+ # Get the category it represents transitions from
554
+ (child_supername, child_category_from) = split (child_node_name, " _" )
555
+
556
+ # For each potential parent node
557
+ for parent_node_name in categorical_node_binary_parent_names
558
+ # Get the category it represents transitions from
559
+ (parent_supername, parent_category_from, parent_category_to) =
560
+ split (parent_node_name, " _" )
561
+
562
+ # If these match
563
+ if parent_category_from == child_category_from
564
+ # Add the parent as parent of the child
565
+ push! (
566
+ edges,
567
+ Dict (" child" => child_node_name, " value_parents" => parent_node_name),
568
+ )
569
+ end
570
+ end
571
+ end
572
+
573
+ # For each binary parent of categorical nodes and their corresponding continuous parents
574
+ for (child_name, parent_name) in
575
+ zip (categorical_node_binary_parent_names, binary_node_continuous_parent_names)
576
+ # Add their relations to the list, with the same value coupling
577
+ push! (
578
+ edges,
579
+ Dict (
580
+ " child" => child_name,
581
+ " value_parents" => (parent_name, config[(" x1" , " x2" , " value_coupling" )]),
582
+ ),
583
+ )
584
+ end
585
+
586
+ # Add the shared continuous node volatility parent to the continuous nodes
587
+ for child_name in binary_node_continuous_parent_names
588
+ push! (
589
+ edges,
590
+ Dict (
591
+ " child" => child_name,
592
+ " volatility_parents" => (" x3" , config[(" x2" , " x3" , " volatility_coupling" )]),
593
+ ),
594
+ )
595
+ end
596
+
597
+ # Initialize the HGF
598
+ init_hgf (
599
+ input_nodes = input_nodes,
600
+ state_nodes = state_nodes,
601
+ edges = edges,
602
+ verbose = false ,
603
+ )
604
+ end
605
+
606
+
607
+
608
+
609
+
610
+
611
+
612
+
613
+
614
+
0 commit comments