Graph¶
The graph module provides the core data structures for defining probabilistic models.
Overview¶
A Falcon graph consists of Node objects connected by parent-child relationships.
The Graph class manages these relationships and handles topological sorting for
correct execution order.
Classes¶
Node
¶
Node(name, simulator_cls, estimator_cls=None, parents=None, evidence=None, scaffolds=None, observed=False, resample=False, simulator_config=None, estimator_config=None, actor_config=None, num_actors=1, sample_chunk_size=0)
Node definition for a graphical model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the node. |
required |
create_distr
|
class
|
Distribution class to create the node. |
required |
config
|
dict
|
Configuration for the distribution. |
required |
parents
|
list
|
List of parent node names (forward model). |
None
|
evidence
|
list
|
List of evidence node names (inference model). |
None
|
observed
|
bool
|
Whether the node is observed (act as root nodes for inference model). |
False
|
actor_name
|
str
|
Optional name of the actor to deploy the node. |
required |
resample
|
bool
|
Whether to resample the node |
False
|
Source code in src/falcon/core/graph.py
Graph
¶
Source code in src/falcon/core/graph.py
add_node
¶
add_node(name, simulator, estimator=None, *, parents=None, evidence=None, scaffolds=None, observed=None, num_actors=1, sample_chunk_size=0, **ray_kwargs)
Add a node to the graph and return self for chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Node name (must be unique in this graph). |
required |
simulator
|
Simulator class, string |
required | |
estimator
|
Estimator class, string |
None
|
|
parents
|
List of parent node names (forward / simulation direction). |
None
|
|
evidence
|
List of evidence node names (inference direction). |
None
|
|
scaffolds
|
List of scaffold node names. |
None
|
|
observed
|
Observed value — a numpy/torch array (used directly), or
|
None
|
|
num_actors
|
int
|
Number of Ray actors to spawn for this node. |
1
|
sample_chunk_size
|
int
|
Chunk size for sampling (0 = no chunking). |
0
|
**ray_kwargs
|
Node-level Ray actor options, prefixed with |
{}
|
Returns:
| Type | Description |
|---|---|
Graph
|
self, so calls can be chained. |
Source code in src/falcon/core/graph.py
get_parents
¶
get_evidence
¶
Functions¶
CompositeNode
¶
Auxiliary function to create a composite node with multiple child nodes.
Source code in src/falcon/core/graph.py
create_graph_from_config
¶
Create a computational graph from YAML configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_config
|
Dictionary containing graph node definitions |
required | |
_cfg
|
Full Hydra configuration object (optional) |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Graph |
The computational graph |
Raises:
| Type | Description |
|---|---|
ValueError
|
If configuration is invalid (missing required fields, unknown references) |
Source code in src/falcon/core/graph.py
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | |