Skip to content

Commit 57c6e56

Browse files
committed
Deploying to gh-pages from @ 3811de8 🚀
0 parents  commit 57c6e56

File tree

397 files changed

+304664
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

397 files changed

+304664
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
.DS_Store
3+
**/* backup *.jl

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Bayesian Machine Learning for Information Processing
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 379 additions & 0 deletions
Large diffs are not rendered by default.

Software installation.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Software installation _(for students)_
2+
3+
Welcome to Bayesian Machine Learning for Information Processing! This course combines mathematical theory and **software implementation**, so that you can _learn by doing_.
4+
5+
A bit of **background information** about the software we are using:
6+
7+
## Julia and RxInfer
8+
For the coding, we use the [Julia programming language](https://julialang.org/). Julia is a high-level programming language (like Python, Matlab, R, JavaScript, etc) which makes it easy to use for complex tasks, but it has the advantage that you can write very fast numerical code (like C++, Rust, Fortran, etc). Not convinced? _Learning Julia is also a [good way to get better at other languages like Python](https://plutojl.org/en/docs/education/#why-julia-for-education)!_
9+
10+
At the [BIASLab](https://biaslab.github.io/), we have developed a specialized package for probabilistic programming and Bayesian inference in Julia: [RxInfer.jl](https://rxinfer.com/). We will use RxInfer in the later lectures, in the Probabilistic Programming lectures and in the assignments. You don't need to install RxInfer manually, it will be loaded automatically when you open a lecture/assignment that uses it.
11+
12+
## Pluto
13+
We use the [Pluto programming environment](https://plutojl.org) for course materials and for assignments. Pluto is an educational notebook environment, which makes it ideal for interactive lectures (with buttons and sliders), and for your assignments (with easy setup, improved error messages, live documentation, and more).
14+
15+
Pluto was developed at MIT to teach the course [Computational Thinking](https://computationalthinking.mit.edu/), the first interactive Julia course website. Pluto is now being developed at TU/e, specifically for this course! So if you have any feedback about Pluto, or you would like to contribute, contact [Fons](github.com/fonsp)!
16+
17+
# How to install
18+
19+
## 1️⃣ Julia
20+
First, start by installing Julia. Follow the instructions on https://julialang.org/install/ . We recommend reading this page carefully.
21+
22+
Now you have Julia installed! Check that you know **how to start Julia**, and run `1 + 1` (should give `2`). You need at least Julia 1.10 for this course.
23+
24+
## 2️⃣ Pluto
25+
Next, you can install and run **Pluto**. This is easy, because Julia has an easy built-in package manager.
26+
27+
👉 Follow the instructions on https://plutojl.org/#install
28+
29+
## 3️⃣ That's it
30+
Because Pluto has a built-in package manager, this is all you need to do for now. 🌟 When you open a lecture or assignment, Pluto will automatically make sure that the right packages are installed. When a package has not been used for a while, Julia will automatically delete it.
31+
32+
33+
34+
35+
# ⚠️ Not working?
36+
If you encounter **any problems**, please contact us in class or on Piazza.
37+
38+
# 🙋 Feedback
39+
If you have feedback about Pluto, RxInfer or Julia (positive, negative, ideas), please write something in Piazza or tell us in class. Feedback is really valuable for me (Fons), to guide the development of Pluto!
40+
41+
42+
43+
44+
# 🗑️ Uninstall
45+
To uninstall Julia and all the packages that you used, you can run the following commands in your terminal:
46+
47+
Linux/MacOS:
48+
49+
```
50+
# Uninstall Julia and juliaup
51+
juliaup self uninstall
52+
53+
# Remove the Julia installation caches
54+
rm -rf ~/.julia
55+
```
56+
57+
For Windows Powershell, replace the last command with:
58+
59+
```
60+
Remove-Item -Recurse -Force "$env:USERPROFILE\.julia"
61+
```
62+
63+
For Windows Command Prompt, replace the last command with:
64+
65+
```
66+
rmdir /s /q %USERPROFILE%\.julia
67+
```

assets/ai_agent/ Mountain Car Problem

Whitespace-only changes.
134 KB
Loading
25.9 KB
Loading

assets/ai_agent/agent_1d.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function initializeAgent()
2+
m_s_t_min = s_0 # Set initial brain state prior
3+
v_s_t_min = 0.01
4+
5+
# Initialize messages and marginals dictionary
6+
messages = Vector{Message}(undef, 59)
7+
marginals = Dict{Symbol, ProbabilityDistribution}()
8+
function infer(u_t::Float64, o_t::Float64)
9+
data = Dict(:o_t => o_t,
10+
:u_t => u_t,
11+
:m_o => zeros(T-1),
12+
:v_o => sigma*ones(T-1),
13+
:m_s_t_min => m_s_t_min,
14+
:v_s_t_min => v_s_t_min)
15+
16+
step!(data, marginals, messages)
17+
end
18+
19+
marginals[:u_2] = ProbabilityDistribution(Univariate, GaussianMeanVariance, m=0.0, v=tiny) # Register initial action
20+
act() = mode(marginals[:u_2]) # Choose the mode of the current control state as action
21+
22+
function slide(slide_msg_idx=7)
23+
(m_s_t_min, V_s_t_min) = ForneyLab.unsafeMeanCov(messages[slide_msg_idx].dist) # Reset prior state statistics
24+
end
25+
26+
return (infer, act, slide)
27+
end

assets/ai_agent/agent_2d.jl

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Internal dynamic model
2+
function g(s_t_min::Vector{Float64}, u_t::Vector{Float64}) # Transition function
3+
ϕ_t_min = s_t_min[1]
4+
x_t_min = s_t_min[2]
5+
y_t_min = s_t_min[3]
6+
7+
Δϕ_t = u_t[1]
8+
r_t = u_t[2]
9+
10+
# Compute next state
11+
ϕ_t = ϕ_t_min + Δϕ_t
12+
x_t = x_t_min + r_t*cos(ϕ_t)
13+
y_t = y_t_min + r_t*sin(ϕ_t)
14+
15+
s_t = [ϕ_t, x_t, y_t]
16+
17+
return s_t
18+
end
19+
20+
function g_inv_in1(s_t::Vector{Float64}, u_t::Vector{Float64}) # Inverse transition function towards previous state
21+
ϕ_t = s_t[1]
22+
x_t = s_t[2]
23+
y_t = s_t[3]
24+
25+
Δϕ_t = u_t[1]
26+
r_t = u_t[2]
27+
28+
# Compute previous state
29+
ϕ_t_min = ϕ_t - Δϕ_t
30+
x_t_min = x_t - r_t*cos(ϕ_t)
31+
y_t_min = y_t - r_t*sin(ϕ_t)
32+
33+
s_t_min = [ϕ_t_min, x_t_min, y_t_min]
34+
35+
return s_t_min
36+
end
37+
38+
function g_inv_in2(s_t::Vector{Float64}, s_t_min::Vector{Float64}) # Inverse transition function towards control
39+
ϕ_t_min = s_t_min[1]
40+
x_t_min = s_t_min[2]
41+
y_t_min = s_t_min[3]
42+
43+
ϕ_t = s_t[1]
44+
x_t = s_t[2]
45+
y_t = s_t[3]
46+
47+
# Compute corresponding control
48+
Δϕ_t = ϕ_t - ϕ_t_min
49+
if Δϕ_t > 0.0
50+
Δϕ_t_tor = Δϕ_t - 2*pi
51+
else
52+
Δϕ_t_tor = Δϕ_t + 2*pi
53+
end
54+
if abs(Δϕ_t_tor) < abs(Δϕ_t)
55+
Δϕ_t = Δϕ_t_tor
56+
end
57+
Δx_t = x_t - x_t_min
58+
Δy_t = y_t - y_t_min
59+
r_t = sign(Δx_t*cos(ϕ_t) + Δy_t*sin(ϕ_t))*sqrt(Δx_t^2 + Δy_t^2)
60+
61+
u_t = [Δϕ_t, r_t]
62+
63+
return u_t
64+
end
65+
66+
function initializeAgent()
67+
m_s_t_min = [ϕ_0, x_0, y_0] # Set initial brain state prior
68+
V_s_t_min = 0.01*diageye(3)
69+
70+
# Initialize messages and marginals dictionary
71+
messages = Vector{Message}(undef, 59)
72+
marginals = Dict{Symbol, ProbabilityDistribution}()
73+
function infer(u_t::Vector{Float64}, o_t::Vector{Float64})
74+
x_t_c = m_s_t_min[2]
75+
y_t_c = m_s_t_min[3]
76+
θ_t = atan(y_t_c, x_t_c)
77+
if θ_t < 0
78+
m = [θ_t + pi, 0.0, 0.0] # Goal prior mean with orientation against polar angle
79+
else
80+
m = [θ_t - pi, 0.0, 0.0]
81+
end
82+
83+
data = Dict(:o_t => o_t,
84+
:u_t => u_t,
85+
:m_o => [m for k=2:T],
86+
:V_o => [Sigma for k=2:T],
87+
:m_s_t_min => m_s_t_min,
88+
:V_s_t_min => V_s_t_min)
89+
90+
step!(data, marginals, messages)
91+
end
92+
93+
marginals[:u_2] = ProbabilityDistribution(Multivariate, GaussianMeanVariance, m=zeros(2), v=tiny*diageye(2)) # Register initial action
94+
act() = mode(marginals[:u_2]) # Choose the mode of the current control state as action
95+
96+
function slide(slide_msg_idx=7)
97+
(m_s_t_min, V_s_t_min) = ForneyLab.unsafeMeanCov(messages[slide_msg_idx].dist) # Reset prior state statistics
98+
end
99+
100+
return (infer, act, slide)
101+
end

assets/ai_agent/design_cycle.png

30.1 KB
Loading

0 commit comments

Comments
 (0)