Skip to content

Commit c5662ec

Browse files
committed
fix latex equations in the new example
1 parent 51f20c3 commit c5662ec

File tree

4 files changed

+80
-107
lines changed

4 files changed

+80
-107
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "RxInfer"
22
uuid = "86711068-29c9-4ff7-b620-ae75d7495b3d"
33
authors = ["Bagaev Dmitry <d.v.bagaev@tue.nl> and contributors"]
4-
version = "3.8.3"
4+
version = "3.8.4"
55

66
[deps]
77
BayesBase = "b4ee3484-f114-42fe-b91c-797d54a0c67e"

codemeta.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
"downloadUrl": "https://github.com/reactivebayes/RxInfer.jl/releases",
1010
"issueTracker": "https://github.com/reactivebayes/RxInfer.jl/issues",
1111
"name": "RxInfer.jl",
12-
"version": "3.8.3",
12+
"version": "3.8.4",
1313
"description": "Julia package for automated, scalable and efficient Bayesian inference on factor graphs with reactive message passing. ",
1414
"applicationCategory": "Statistics",
1515
"developmentStatus": "active",
1616
"readme": "https://reactivebayes.github.io/RxInfer.jl/stable/",
17-
"softwareVersion": "3.8.3",
17+
"softwareVersion": "3.8.4",
1818
"keywords": [
1919
"Bayesian inference",
2020
"message passing",

docs/src/contributing/examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ We welcome examples from the community that showcase RxInfer.jl in action! Wheth
88
- **Tutorial Series on RxInfer.jl** - Explore a series of engaging tutorial videos on RxInfer.jl's functionalities, presented by [@doggotodjl](https://www.youtube.com/@doggodotjl/search?query=RxInfer).
99

1010
!!! note
11-
If you're interested in contributing an example, we'd love to hear from you! Please initiate an issue or start a new discussion on our [GitHub repository](https://github.com/reactivebayes/RxInfer.jl) to get involved.
11+
If you're interested in contributing an example, we'd love to hear from you! Please initiate an issue or start a new discussion on our [GitHub repository](https://github.com/reactivebayes/RxInfer.jl) to get involved. The example notebook must follow a specific structure, which is described in the [Contribute to the examples](@ref contributing-new-example) section.

examples/problem_specific/Structural Dynamics with Augmented Kalman Filter.ipynb

Lines changed: 76 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,9 @@
474474
"\n",
475475
"State-space models are fundamental tools in control theory and signal processing that allow us to analyze complex dynamical systems by breaking them down into first-order differential equations. They are particularly important for structural dynamics problems because they can capture both the internal states (like position and velocity) and external influences (like forces) in a unified mathematical framework. A typical **state-space model** formulation might look like this:\n",
476476
"\n",
477-
"$$\n",
478-
"x[k+1] \\sim \\mathcal{N}(A x[k] + B p[k], Q),\n",
479-
"$$\n",
480-
"$$\n",
481-
"y[k] \\sim \\mathcal{N}(G x[k] + J p[k], R),\n",
482-
"$$\n",
477+
"$$x[k+1] \\sim \\mathcal{N}(A x[k] + B p[k], Q),$$\n",
478+
"\n",
479+
"$$y[k] \\sim \\mathcal{N}(G x[k] + J p[k], R),$$\n",
483480
"\n",
484481
"where:\n",
485482
"- $x[k]$ represents the system states at time-step $k$\n",
@@ -506,19 +503,17 @@
506503
"cell_type": "markdown",
507504
"metadata": {},
508505
"source": [
509-
"In this example, the dynamics of a structural system are governed by its **mass** ($ M $), **stiffness** ($ K $), and **damping** ($ C $) matrices, leading to the equation of motion:\n",
506+
"In this example, the dynamics of a structural system are governed by its **mass** ($M$), **stiffness** ($K$), and **damping** ($C$) matrices, leading to the equation of motion:\n",
510507
"\n",
511-
"$$\n",
512-
"M \\ddot{x}(t) + C \\dot{x}(t) + K x(t) = p(t),\n",
513-
"$$\n",
508+
"$$M \\ddot{x}(t) + C \\dot{x}(t) + K x(t) = p(t),$$\n",
514509
"\n",
515-
"where $ x(t) $ represents the displacements at each degree of freedom, and $ (t) $ is the external force applied to the system.\n",
510+
"where $x(t)$ represents the displacements at each degree of freedom, and $p(t)$ is the external force applied to the system.\n",
516511
"\n",
517512
"This model captures the essential dynamics of a multi-story structure while remaining computationally manageable. The system matrices are defined as follows:\n",
518513
"\n",
519-
"- $ M $ is the diagonal mass matrix representing the lumped masses at each floor, \n",
520-
"- $ K $ is the stiffness matrix representing inter-floor lateral stiffness, and \n",
521-
"- $ C $ is the proportional damping matrix reflecting energy dissipation."
514+
"- $M$ is the diagonal mass matrix representing the lumped masses at each floor, \n",
515+
"- $K$ is the stiffness matrix representing inter-floor lateral stiffness, and \n",
516+
"- $C$ is the proportional damping matrix reflecting energy dissipation."
522517
]
523518
},
524519
{
@@ -617,32 +612,30 @@
617612
"\n",
618613
"We convert the structural system into its **discrete-time state-space form** for numerical simulation. Starting from the equation of motion:\n",
619614
"\n",
620-
"$$\n",
621-
"M \\ddot{x}(t) + C \\dot{x}(t) + K x(t) = F(t),\n",
622-
"$$\n",
615+
"$$M \\ddot{x}(t) + C \\dot{x}(t) + K x(t) = F(t),$$\n",
623616
"\n",
624617
"we introduce the state variable:\n",
625-
"$$\n",
626-
"z(t) = \\begin{bmatrix} x(t) \\\\ \\dot{x}(t) \\end{bmatrix},\n",
627-
"$$\n",
618+
"\n",
619+
"$$z(t) = \\begin{bmatrix} x(t) \\\\ \\dot{x}(t) \\end{bmatrix},$$\n",
620+
"\n",
628621
"which allows us to express the system as:\n",
629-
"$$\n",
630-
"\\dot{z}(t) = A_{\\text{c}} z(t) + B_{\\text{c}} p(t),\n",
631-
"$$\n",
622+
"\n",
623+
"$$\\dot{z}(t) = A_{\\text{c}} z(t) + B_{\\text{c}} p(t),$$\n",
624+
"\n",
632625
"where:\n",
633-
"- $ A_{\\text{c}} = \\begin{bmatrix} 0 & I \\\\ -(M^{-1} K) & -(M^{-1} C) \\end{bmatrix} $\n",
634-
"- $ B_{\\text{c}} = \\begin{bmatrix} 0 \\\\ M^{-1} S_p \\end{bmatrix} $\n",
635-
"- $ S_p $ is the input selection matrix that determines where the external forces $ p(t) $ are applied.\n",
636-
"\n",
637-
"To perform simulations, the system is discretized using a time step $ \\Delta t $ as:\n",
638-
"$$\n",
639-
"z[k+1] = A z[k] + B p[k],\n",
640-
"$$\n",
626+
"- $A_{\\text{c}} = \\begin{bmatrix} 0 & I \\\\ -(M^{-1} K) & -(M^{-1} C) \\end{bmatrix}$\n",
627+
"- $B_{\\text{c}} = \\begin{bmatrix} 0 \\\\ M^{-1} S_p \\end{bmatrix}$\n",
628+
"- $S_p$ is the input selection matrix that determines where the external forces $p(t)$ are applied.\n",
629+
"\n",
630+
"To perform simulations, the system is discretized using a time step $\\Delta t$ as:\n",
631+
"\n",
632+
"$$z[k+1] = A z[k] + B p[k],$$\n",
633+
"\n",
641634
"where:\n",
642-
"- $ A = e^{A_{\\text{c}} \\Delta t} $ is the **state transition matrix**.\n",
643-
"- $ B = (A - I) A_{\\text{c}}^{-1} B_{\\text{c}} $ is the **input matrix**, obtained by integrating the continuous-time system.\n",
635+
"- $A = e^{A_{\\text{c}} \\Delta t}$ is the **state transition matrix**.\n",
636+
"- $B = (A - I) A_{\\text{c}}^{-1} B_{\\text{c}}$ is the **input matrix**, obtained by integrating the continuous-time system.\n",
644637
"\n",
645-
"This state-space representation forms the basis for propagating the system states during simulation.\n"
638+
"This state-space representation forms the basis for propagating the system states during simulation."
646639
]
647640
},
648641
{
@@ -692,14 +685,13 @@
692685
"source": [
693686
"### Generating Input Forces\n",
694687
"\n",
695-
"External forces $ p[k] $ acting on the system are modeled as **Gaussian white noise**:\n",
688+
"External forces $p[k]$ acting on the system are modeled as **Gaussian white noise**:\n",
689+
"\n",
690+
"$$p[k] \\sim \\mathcal{N}(\\mu, \\sigma^2),$$\n",
696691
"\n",
697-
"$$\n",
698-
"p[k] \\sim \\mathcal{N}(\\mu, \\sigma^2),\n",
699-
"$$\n",
700-
"where $ \\mu $ is the mean and $ \\sigma $ controls the intensity of the force.\n",
692+
"where $\\mu$ is the mean and $\\sigma$ controls the intensity of the force.\n",
701693
"\n",
702-
"In this example, the inputs are generated independently at each time step $ k $ and across input channels to simulate random excitations, such as wind or seismic forces.\n",
694+
"In this example, the inputs are generated independently at each time step $k$ and across input channels to simulate random excitations, such as wind or seismic forces.\n",
703695
"\n"
704696
]
705697
},
@@ -735,15 +727,14 @@
735727
"\n",
736728
"System responses, such as accelerations, are often measured at specific locations using sensors. The measurements are simulated using the equation:\n",
737729
"\n",
738-
"$$\n",
739-
"y[k] = G x[k] + J p[k] + v[k],\n",
740-
"$$\n",
730+
"$$y[k] = G x[k] + J p[k] + v[k],$$\n",
731+
"\n",
741732
"where:\n",
742-
"- $ G $ maps the system states $ x[k] $ to measured outputs.\n",
743-
"- $ J $ maps the input forces $ p[k] $ to the measurements.\n",
744-
"- $ v[k] \\sim \\mathcal{N}(0, \\sigma_y^2 I) $ is Gaussian noise representing sensor inaccuracies.\n",
733+
"- $G$ maps the system states $x[k]$ to measured outputs.\n",
734+
"- $J$ maps the input forces $p[k]$ to the measurements.\n",
735+
"- $v[k] \\sim \\mathcal{N}(0, \\sigma_y^2 I)$ is Gaussian noise representing sensor inaccuracies.\n",
745736
"\n",
746-
"The noise variance $ \\sigma_y^2 $ is chosen as a fraction of the true system response variance for realism.\n",
737+
"The noise variance $\\sigma_y^2$ is chosen as a fraction of the true system response variance for realism.\n",
747738
"\n",
748739
"In this example, **accelerations** are measured at selected degrees of freedom (e.g., nodes 1 and 4).\n"
749740
]
@@ -804,20 +795,19 @@
804795
"\n",
805796
"The structural response under applied forces is governed by the state-space equations:\n",
806797
"\n",
807-
"$$\n",
808-
"\\begin{aligned}\n",
798+
"$$\\begin{aligned}\n",
809799
"x[k+1] & = A x[k] + B p[k], \\\\\n",
810800
"y[k] & = G_{\\text{full}} x[k] + J_{\\text{full}} p[k],\n",
811-
"\\end{aligned}\n",
812-
"$$\n",
813-
"where $ x[k] $ are the system states, $ p[k] $ are the input forces, and $ y[k] $ are the **full-field responses**, i.e., the response at every degree of freedom in our structure.\n",
801+
"\\end{aligned}$$\n",
802+
"\n",
803+
"where $x[k]$ are the system states, $p[k]$ are the input forces, and $y[k]$ are the **full-field responses**, i.e., the response at every degree of freedom in our structure.\n",
814804
"\n",
815805
"\n",
816806
"The function below returns:\n",
817-
"- **True States**: $ x_{\\text{real}} $, propagated using $ A $ and $ B $.\n",
818-
"- **Full-Field Responses**: $ y_{\\text{real}} $, incorporating both states and inputs.\n",
819-
"- **Input Forces**: $ p_{\\text{real}} $, generated as stochastic excitations.\n",
820-
"- **Response Matrices**: $ G_{\\text{full}} $ (state-to-response) and $ J_{\\text{full}} $ (input-to-response).\n",
807+
"- **True States**: $x_{\\text{real}}$, propagated using $ A $ and $ B $.\n",
808+
"- **Full-Field Responses**: $y_{\\text{real}}$, incorporating both states and inputs.\n",
809+
"- **Input Forces**: $p_{\\text{real}}$, generated as stochastic excitations.\n",
810+
"- **Response Matrices**: $G_{\\text{full}}$ (state-to-response) and $J_{\\text{full}}$ (input-to-response).\n",
821811
"\n",
822812
"These outputs simulate the physical behavior of the system and serve as the basis for inference. We keep the matrices because they will be used later when analyzing our results.\n"
823813
]
@@ -881,63 +871,56 @@
881871
"source": [
882872
"### Augmented State-Space Model\n",
883873
"\n",
884-
"In structural health monitoring, external input forces $ p[k] $ acting on a structure, such as environmental loads or unknown excitations, are often not directly measurable. To estimate both the system states $ x[k] $ and these unknown input forces, we **augment the state vector** as follows:\n",
874+
"In structural health monitoring, external input forces $p[k]$ acting on a structure, such as environmental loads or unknown excitations, are often not directly measurable. To estimate both the system states $x[k]$ and these unknown input forces, we **augment the state vector** as follows:\n",
885875
"\n",
886-
"$$\n",
887-
"\\tilde{x}[k] = \n",
876+
"$$\\tilde{x}[k] = \n",
888877
"\\begin{bmatrix}\n",
889878
"x[k] \\\\\n",
890879
"p[k]\n",
891-
"\\end{bmatrix}.\n",
892-
"$$\n",
880+
"\\end{bmatrix}.$$\n",
893881
"\n",
894882
"This approach allows us to simultaneously infer the internal system states (e.g., displacements and velocities) and the unknown inputs using available measurements.\n",
895883
"\n",
896-
"\n",
897884
"The augmented system dynamics are then expressed as:\n",
898885
"\n",
899-
"$$\n",
900-
"\\begin{aligned}\n",
886+
"$$\\begin{aligned}\n",
901887
"\\tilde{x}[k+1] & = A_{\\text{aug}} \\tilde{x}[k] + w[k], \\\\\n",
902888
"y[k] & = G_{\\text{aug}} \\tilde{x}[k] + v[k],\n",
903-
"\\end{aligned}\n",
904-
"$$\n",
889+
"\\end{aligned}$$\n",
905890
"\n",
906891
"where:\n",
907-
"- $ A_{\\text{aug}} $: Augmented state transition matrix. \n",
908-
"- $ G_{\\text{aug}} $: Augmented measurement matrix. \n",
909-
"- $ Q_{\\text{akf}} $: Augmented process noise covariance, capturing uncertainties in both states and inputs. \n",
910-
"- $ w[k] $, $ v[k] $: Process and measurement noise. \n",
892+
"- $A_{\\text{aug}}$: Augmented state transition matrix. \n",
893+
"- $G_{\\text{aug}}$: Augmented measurement matrix. \n",
894+
"- $Q_{\\text{akf}}$: Augmented process noise covariance, capturing uncertainties in both states and inputs. \n",
895+
"- $w[k]$, $v[k]$: Process and measurement noise. \n",
911896
"\n",
912897
"##### Full-Field vs. Measurement Space \n",
913898
"\n",
914899
"To avoid confusion, we define two augmented measurement matrices: \n",
915-
"- $ G_{\\text{aug}} $: Projects the augmented state vector $ \\tilde{x}[k] $ to the observed **sensor measurements** (e.g., accelerations at specific nodes). \n",
916-
"- $ G^* $: The **augmented full-field measurement matrix**, which projects the augmented state vector to the full-field **system response**. This includes all degrees of freedom (displacements, velocities, and accelerations). \n",
900+
"- $G_{\\text{aug}}$: Projects the augmented state vector $\\tilde{x}[k]$ to the observed **sensor measurements** (e.g., accelerations at specific nodes). \n",
901+
"- $G^*$: The **augmented full-field measurement matrix**, which projects the augmented state vector to the full-field **system response**. This includes all degrees of freedom (displacements, velocities, and accelerations). \n",
917902
"\n",
918903
"The distinction is critical:\n",
919-
"- $ G_{\\text{aug}} $ is used directly in the smoother to estimate states and inputs from limited measurements. \n",
920-
"- $ G^* $ is used later to reconstruct the full response field for visualization and validation.\n",
904+
"- $G_{\\text{aug}}$ is used directly in the smoother to estimate states and inputs from limited measurements. \n",
905+
"- $G^*$ is used later to reconstruct the full response field for visualization and validation.\n",
921906
"\n",
922-
"For clarity, we will refer to the **augmented full-field matrix** as $ G^* $ throughout the rest of this example, whereas, in the code, this will be the `G_aug_fullfield` object.\n",
907+
"For clarity, we will refer to the **augmented full-field matrix** as $G^*$ throughout the rest of this example, whereas, in the code, this will be the `G_aug_fullfield` object.\n",
908+
"\n",
909+
"#### Noise Covariances \n",
923910
"\n",
924-
"#### Noise Covariances \n",
925911
"In this step, the process and measurement noise covariances are assumed to be **known** or **pre-calibrated**. For example:\n",
926-
"- The input force uncertainty $ Q_p $ is set to reflect significant variability. \n",
927-
"- State noise covariance $ Q_x $ is chosen to reflect uncertainty in the model. \n",
912+
"- The input force uncertainty $Q_p$ is set to reflect significant variability. \n",
913+
"- State noise covariance $Q_x$ is chosen to reflect uncertainty in the model. \n",
928914
"\n",
929-
"The augmented noise covariance matrix $ Q_{\\text{akf}} $ combines these quantities:\n",
915+
"The augmented noise covariance matrix $Q_{\\text{akf}}$ combines these quantities:\n",
930916
"\n",
931-
"$$\n",
932-
"Q_{\\text{akf}} =\n",
917+
"$$Q_{\\text{akf}} =\n",
933918
"\\begin{aligned}\n",
934919
"\\begin{bmatrix}\n",
935920
"Q_x & 0 \\\\\n",
936921
"0 & Q_p\n",
937922
"\\end{bmatrix}\n",
938-
"\\end{aligned}.\n",
939-
"$$\n",
940-
"\n"
923+
"\\end{aligned}.$$\n"
941924
]
942925
},
943926
{
@@ -1077,15 +1060,11 @@
10771060
"\n",
10781061
"Here, we define our **Augmented Kalman Filter (AKF)** smoother using RxInfer. This probabilistic model estimates the system states and unknown input forces based on the measurements.\n",
10791062
"- **State Prior**: We start with a prior belief about the initial state, `x0`. \n",
1080-
"- **State Transition**: At each time step, the system state evolves based on the transition matrix $ A $ and process noise covariance $ Q $:\n",
1081-
" $$\n",
1082-
" x[k] \\sim \\mathcal{N}(A x[k-1], Q).\n",
1083-
" $$\n",
1063+
"- **State Transition**: At each time step, the system state evolves based on the transition matrix $A$ and process noise covariance $Q$:\n",
1064+
" $$x[k] \\sim \\mathcal{N}(A x[k-1], Q).$$\n",
10841065
"- **Measurements**: The observations (sensor data) are modeled as noisy measurements of the states:\n",
1085-
" $$\n",
1086-
" y[k] \\sim \\mathcal{N}(G x[k], R),\n",
1087-
" $$\n",
1088-
" where $ G $ maps the states to the measurements, and $ R $ is the measurement noise covariance.\n"
1066+
" $$y[k] \\sim \\mathcal{N}(G x[k], R),$$\n",
1067+
" where $G$ maps the states to the measurements, and $R$ is the measurement noise covariance.\n"
10891068
]
10901069
},
10911070
{
@@ -1123,9 +1102,7 @@
11231102
"\n",
11241103
"2. **Set the Initial State**: \n",
11251104
" We start with a prior belief about the first state, assuming it's zero with some process noise: \n",
1126-
" $$\n",
1127-
" x_0 \\sim \\mathcal{N}(0, Q_{\\text{akf}}).\n",
1128-
" $$\n",
1105+
" $$x_0 \\sim \\mathcal{N}(0, Q_{\\text{akf}}).$$\n",
11291106
"\n",
11301107
"3. **Run the Smoother**: \n",
11311108
" We define a helper function to keep things tidy. This function calls RxInfer’s `infer` method, which does the heavy lifting for us.\n",
@@ -1219,15 +1196,11 @@
12191196
"\n",
12201197
"While the smoother estimates the system states, we often care about physical quantities like accelerations or displacements across the entire structure.\n",
12211198
"\n",
1222-
"Using the **augmented full-field matrix** $ G^* $, we compute:\n",
1199+
"Using the **augmented full-field matrix** $G^*$, we compute:\n",
12231200
"- **Response means** from state means: \n",
1224-
" $$\n",
1225-
" \\mu_y[i] = G^* \\mu_x[i].\n",
1226-
" $$ \n",
1201+
" $$\\mu_y[i] = G^* \\mu_x[i].$$ \n",
12271202
"- **Response uncertainties** from state covariances: \n",
1228-
" $$\n",
1229-
" \\sigma_y[i] = \\sqrt{\\text{diag}(G^* \\Sigma_x[i] {G^*}^\\top)}.\n",
1230-
" $$ \n",
1203+
" $$\\sigma_y[i] = \\sqrt{\\text{diag}(G^* \\Sigma_x[i] {G^*}^\\top)}.$$ \n",
12311204
"\n",
12321205
"This gives us both the expected **responses** and their **uncertainties** at each time step. \n",
12331206
"\n",
@@ -1255,7 +1228,7 @@
12551228
" x_marginals,\n",
12561229
" G_aug_fullfield,\n",
12571230
" N_data::Int\n",
1258-
" )\n",
1231+
")\n",
12591232
" \n",
12601233
" # preallocate the full field response\n",
12611234
" y_means = Vector{Vector{Float64}}(undef, N_data) # vector of vectors\n",

0 commit comments

Comments
 (0)