How to do a direct increment of the log posterior in greta

Hi there,

I am trying to implement an operation identified previously here in the context of a “bym2” model:

Specifically, I am trying to adjust/account for a “summary statistic” which in STAN is permitted via a direct manipulation of the joint log density (“target”):

 target += -0.5 * dot_self(phi[node1] - phi[node2])

I understand this is not a supported operation in greta. From looking at similar questions, it seems I would need to create a new distribution as indicated by:

and possibly use “greta.funprior” as identified here:

Sadly, this is beyond my poor abilities. Would any of you be aware of a better solution or, provide more guidance on how I might try to get this done?

Thinking it about it some more, would using the zeros trick from Bugs be a potential solution? Something like:

   zeros <- as_data( rep(0L, N) )   
   nlk <- -log( 0.5 * ( phi[node1] - phi[node2] )^2 )
   distribution( zeros ) <- poisson( nlk )