Replies: 3 comments 6 replies
-
|
hi carlo, just had a look again at it. nice and clear example you came up with.
in the PR of the tmaze i build a function that checks, whether the entropy of the tensor depends on the variational beliefs. if not, it simplifies the whole set up drastically, and we can just use the tensor to calculate the prior. using these implementations yields a posterior over actions [open_lid, close_lid]: p=[0.7499999887495005, 0.25000001125049953] using RxInfer, Tullio, LinearAlgebra, LogExpFunctions, PrettyPrinting
import Pipe: @pipe as @p
@enum Content C1=1 C2 C3
@enum Lid Open=1 Closed
@enum Observation O1=1 O2 O3 # Impaired
@enum Action OpenLid=1 Wait
uniform(data::Type{T}) where {T <: Enum} = @p data |> instances |> length |> ones |> normalize(_, 1)
onehot(elem :: T) where {T <: Enum} = @p T |> instances |> length |> zeros |> setindex!(_, 1, Int(elem))
# Observation_t | Content, Lid_t
# observation_tensor = [1 0 0; 0 1 0; 0 0 1; 0 0 0 ;;;
# 0 0 0; 0 0 0; 0 0 0; 1 1 1]
# Identity matrix for slice 1, Uniform for slice 2
observation_tensor = [1 0 0; 0 1 0; 0 0 1 ;;;
1/3 1/3 1/3; 1/3 1/3 1/3; 1/3 1/3 1/3]
# Lid_t | Lid_{t-1}, Action
transition_tensor = [1 1; 0 0 ;;;
1 0; 0 1]
struct LogMeta end
@model function model(observation)
content ~ Categorical(uniform(Content))
lid_0 ~ Categorical(uniform(Lid))
observation ~ DiscreteTransition(content, observation_tensor, lid_0)
action ~ Categorical(uniform(Action))
lid_1 ~ DiscreteTransition(lid_0, transition_tensor, action)# where {meta=LogMeta()}
lid_1 ~ Categorical(calc_epis_prior_vec(observation_tensor))
# you can both include or exclude these nodes
# observation_1 ~ DiscreteTransition(content, observation_tensor, lid_1) where {meta=LogMeta()}
# observation_1 ~ Categorical(uniform(Observation))
end
@initialization function init()
μ(content) = Categorical(uniform(Content))
end
@marginalrule DiscreteTransition(:out_in_T1) (m_out::Categorical,
m_in::Categorical,
m_T1::Categorical,
q_a::PointMass{<:AbstractArray{T,3}},
meta::LogMeta) where {T} = begin
@tullio result[a, b, c] := q_a.point[a, b, c] * probvec(m_out)[a] * probvec(m_in)[b] * probvec(m_T1)[c]
normalize!(result, 1)
@show result
marginal = Contingency(result, Val(false))
return marginal
end
result = infer(
model = model(),
data = (observation = [1/3, 1/3, 1/3], ),
initialization = init(),
options = (force_marginal_computation=true,),
iterations = 1
)
@p result.posteriors |> Dict(k => last(v) for (k, v) in _) |> pprintlnwhere i had recycled the code from tmaze PR to calculate the epistemic prior (you could also just calculate it once and insert it in the Categorical if you want the model to be lighter) function compute_invariant_entropy_prior(
A::AbstractArray{T, 3},
dim_keep::Int,
dim_reduce::Int;
atol=1e-8,
err_msg="Entropy of tensor depends on hidden state"
) where T <: Real
# 1. Calculate Entropy Map
# We collapse Dim 1 (the probability distribution axis)
# Resulting H has the remaining 2 dimensions
H = map(eachslice(A, dims=(2, 3))) do slice
# calculate -Σ p log p, handling zeros
sum(p -> p > 0 ? p * log(p) : zero(T), slice)
end
# 2. Check Invariance and Extract
# We want to ensure H is uniform along 'dim_reduce'
# Since H is 2D, we need to map the original dims (2,3) to (1,2)
h_axis_to_check = (dim_reduce == 2) ? 1 : 2
# Check if all slices along the invariant dimension are approximately equal
first_slice = selectdim(H, h_axis_to_check, 1)
for i in 2:size(H, h_axis_to_check)
if !isapprox(first_slice, selectdim(H, h_axis_to_check, i); atol=atol)
throw(ArgumentError(err_msg))
end
end
# 3. Return Softmax of the invariant entropy vector
return softmax(first_slice)
end
function calc_epis_prior_vec(tensor::AbstractArray{T, 3}; atol=1e-8) where T <: Real
return compute_invariant_entropy_prior(
tensor,
3, # Keep Dimension (Lid/k)
2 # Marginalize Dimension (Content/j)
)
end |
Beta Was this translation helpful? Give feedback.
-
|
Hi @skoghoern, thank you for your response, it gave me a lot to think about. For starters, you are right in your first point, that if possible observations were just @enum Observation O1=1 O2 O3then the calculation But that feels somewhat like a pyrrhic victory to me: that works because I crafted an observation that is isomorphic to the state I'm interested in, and then I ask to minimize the entropy of this observation. So I see two possible alternatives:
So a more direct way of posing the question is: could the priors compute the mutual information instead of the conditional entropy as written in the paper? Would this have any drawback? The example was crafted to illustrate this tension. [0] The joint marginal we collected: [1] "Epistemic value is the expected information gain (i.e., mutual information) afforded to hidden states by future outcomes and vice-versa", from Active inference, a process theory |
Beta Was this translation helpful? Give feedback.
-
|
Here is my derivation (simply adapted from the great paper):
factorizing the joint
The proof we want to make is then just as in the paper (ill keep their numeration, to make the comparison easier):
Now in (17) comes the time to infuse our different version of the EFE with preferences over observations.
Following the paper: "Here we can replace the general
Here we recognize:
and
Which, when substituted into (18b), together with the definitions of
so we get the same epistemic prior over actions, but a different epistemic prior over observations |
Beta Was this translation helpful? Give feedback.


Uh oh!
There was an error while loading. Please reload this page.
-
Hi all, I'm still thinking about the EFEasVFE paper, and another question has come up. After having done the stochastic maze, I started looking at how the empiric priors are constructed in general, using the minigrid example as a reference.
I have created a simpler scenario, but I cannot reproduce the curious behavior I would expect.
In front of the agent there's a box, which might contain one of three items. The box has a lid that might be open or closed. When closed, it obstructs the perception of the content. The agent observes the closed lid, then has to decide what to do for just one action.
Here is a complete model to make this exchange more precise; since my question concerns the joint distributions, I added a
LogMetaand relative@marginalrulejust to intercept the joint marginals.Running the model yields the following joint observation marginals:
And the joint transition marginals are:
If I understand correctly the argument used in the paper, the structure of the model should generate three empirical priors, one attached to the action, and one for each state variable that is included in the observation. So, using shorthand for brevity (the conditional entropies are calculated per slice):
Now, here are the calculations:
All of the conditional entropies are zero, so the priors do not guide the agent toward opening the box.
There are other possible priors that could distinguish the two actions, for example:
but this choice seems unprincipled. This brings me to my question: is there something I am overlooking? Can I write a generic prior that follows the structure of the paper without directly saying I want to minimize the entropy of the
content?Beta Was this translation helpful? Give feedback.
All reactions