Causal blankets: Theory and algorithmic framework