Transforms
Haskell implementation of the Overview/Transforms
Sections
Definition
Given a histogram $X \in \mathcal{A}$ and a subset of its variables $W \subseteq \mathrm{vars}(X)$, the pair $T = (X,W)$ forms a transform. The Transform
type is defined with a pair of a Histogram
and a Variable
set,
newtype Transform = Transform (Histogram, (Set.Set Variable))
A Transform
is constructed from a Histogram
and a set of Variable
,
histogramsSetVarsTransform :: Histogram -> Set.Set Variable -> Maybe Transform
Consider the deck of cards example,
let lluu ll = fromJust $ listsSystem [(v,Set.fromList ww) | (v,ww) <- ll]
let [suit,rank] = map VarStr ["suit","rank"]
[hearts,clubs,diamonds,spades] = map ValStr ["hearts","clubs","diamonds","spades"]
[jack,queen,king,ace] = map ValStr ["J","Q","K","A"]
let uu = lluu [
(suit, [hearts, clubs, diamonds, spades]),
(rank, [jack,queen,king,ace] ++ map ValInt [2..10])]
let vv = Set.fromList [suit, rank]
rp uu
"{(rank,{A,J,K,Q,2,3,4,5,6,7,8,9,10}),(suit,{clubs,diamonds,hearts,spades})}"
rp vv
"{rank,suit}"
let aa = unit (cart uu vv)
rpln $ aall aa
"({(rank,A),(suit,clubs)},1 % 1)"
"({(rank,A),(suit,diamonds)},1 % 1)"
"({(rank,A),(suit,hearts)},1 % 1)"
"({(rank,A),(suit,spades)},1 % 1)"
"({(rank,J),(suit,clubs)},1 % 1)"
"({(rank,J),(suit,diamonds)},1 % 1)"
...
"({(rank,9),(suit,hearts)},1 % 1)"
"({(rank,9),(suit,spades)},1 % 1)"
"({(rank,10),(suit,clubs)},1 % 1)"
"({(rank,10),(suit,diamonds)},1 % 1)"
"({(rank,10),(suit,hearts)},1 % 1)"
"({(rank,10),(suit,spades)},1 % 1)"
A transform can be constructed from a histogram $X$ relating the suit to the colour,
let colour = VarStr "colour"
red = ValStr "red"; black = ValStr "black"
let xx = llaa [(llss [(suit, u),(colour, w)],1) | (u,w) <- [(hearts, red), (clubs, black), (diamonds, red), (spades, black)]]
rpln $ aall xx
"({(colour,black),(suit,clubs)},1 % 1)"
"({(colour,black),(suit,spades)},1 % 1)"
"({(colour,red),(suit,diamonds)},1 % 1)"
"({(colour,red),(suit,hearts)},1 % 1)"
let ww = Set.fromList [colour]
let trans xx ww = fromJust $ histogramsSetVarsTransform xx ww
rp $ trans xx ww
"({({(colour,black),(suit,clubs)},1 % 1),({(colour,black),(suit,spades)},1 % 1),({(colour,red),(suit,diamonds)},1 % 1),({(colour,red),(suit,hearts)},1 % 1)},{colour})"
The variables, $W$, are the derived variables. The complement $K = \mathrm{vars}(X) \setminus W$ are the underlying variables,
rp ww
"{colour}"
let kk = vars xx `Set.difference` ww
rp kk
"{suit}"
The set of all transforms is \[ \begin{eqnarray} \mathcal{T} &:=& \{(X,W) : X \in \mathcal{A},~W \subseteq \mathrm{vars}(X)\} \end{eqnarray} \] The transform histogram is $X = \mathrm{his}(T)$. The transform derived is $W = \mathrm{der}(T)$. The transform underlying is $K = \mathrm{und}(T)$,
transformsHistogram :: Transform -> Histogram
transformsUnderlying :: Transform -> Set.Set Variable
transformsDerived :: Transform -> Set.Set Variable
For example,
let ttaa = transformsHistogram
und = transformsUnderlying
der = transformsDerived
let tt = trans xx ww
ttaa tt == xx
True
und tt == kk
True
der tt == ww
True
The null transform is $(X,\emptyset)$,
histogramsTransformNull :: Histogram -> Transform
For example,
let null = histogramsTransformNull
ttaa (null aa) == aa
True
und (null aa) == vars aa
True
der (null aa) == Set.empty
True
The full transform is $(X,\mathrm{vars}(X))$,
histogramsTransformDisjoint :: Histogram -> Transform
For example,
let full = histogramsTransformDisjoint
ttaa (full aa) == aa
True
und (full aa) == Set.empty
True
der (full aa) == vars aa
True
Given a histogram $A \in \mathcal{A}$, the multiplication of the histogram, $A$, by the transform $T \in \mathcal{T}$ equals the multiplication of the histogram, $A$, by the transform histogram $X = \mathrm{his}(T)$ followed by the reduction to the derived variables $W = \mathrm{der}(T)$, \[ \begin{eqnarray} A * T~=~A * (X,W) &:=& A * X~\%~W \end{eqnarray} \]
transformsHistogramsApply :: Transform -> Histogram -> Histogram
For example,
let tmul aa tt = transformsHistogramsApply tt aa
rpln $ aall $ aa `tmul` tt
"({(colour,black)},26 % 1)"
"({(colour,red)},26 % 1)"
aa `tmul` tt == aa `mul` xx `ared` ww
True
If the histogram variables are a superset of the underlying variables, $\mathrm{und}(T) \subseteq \mathrm{vars}(A)$,
und tt `Set.isSubsetOf` vars aa
True
then the histogram, $A$, is called the underlying histogram and the multiplication, $A * T$, is called the derived histogram. The derived histogram variables equals the derived variables, $\mathrm{vars}(A*T) = \mathrm{der}(T)$.
If the set of underlying variables of a transform is a proper subset of the set of histogram variables, $K \subset V$, the transform can be expanded by multiplying its histogram by the cartesian histogram of the set of remaining variables, $V \setminus K$. In the deck of cards example, the set of underlying variables, $K$, is a singleton consisting of the suit,
rp $ und tt
"{suit}"
The transform is expanded to the histogram variables, $V$, by multiplying by the cartesian histogram for the rank,
let vk = vv `Set.difference` kk
rp $ vk
"{rank}"
let ttv = trans (ttaa tt `mul` unit (cart uu vk)) (der tt)
rp $ und ttv
"{rank,suit}"
und ttv == vv
True
The set of derived variables of the expanded transform is unchanged, so the derived histogram is unchanged,
der ttv == der tt
True
aa `tmul` ttv == aa `tmul` tt
True
The application of the null transform of the cartesian is the scalar, $A * (V^{\mathrm{C}},\emptyset) = A \% \emptyset = \mathrm{scalar}(\mathrm{size}(A))$, where $V = \mathrm{vars}(A)$,
let vvc = unit (cart uu vv)
aa `tmul` null vvc == aa `ared` Set.empty
True
The application of the full transform of the cartesian is the histogram, $A * (V^{\mathrm{C}},V) = A \% V = A$,
aa `tmul` full vvc == aa
True
Formal and Abstract
Given a histogram $A \in \mathcal{A}$ and a transform $T \in \mathcal{T}$, the formal histogram is defined as the independent derived, $A^{\mathrm{X}} * T$. In the case of the deck of cards example, the histogram, $A$, is just the cartesian and is already independent. So the formal histogram equals the derived histogram,
rpln $ aall $ ind aa `tmul` tt
"({(colour,black)},26 % 1)"
"({(colour,red)},26 % 1)"
ind aa `tmul` tt == aa `tmul` tt
True
Consider a transform $T’$ with two derived variables constructed on two underlying variables as follows,
let tt' = trans (cdaa [[1,1,1,2],[1,2,1,1],[1,3,1,1],[2,1,2,1],[2,2,2,2],[2,3,2,1],[3,1,2,1],[3,2,2,1],[3,3,1,2]]) (Set.fromList [VarInt 3, VarInt 4])
rpln $ aall $ ttaa tt'
"({(1,1),(2,1),(3,1),(4,2)},1 % 1)"
"({(1,1),(2,2),(3,1),(4,1)},1 % 1)"
"({(1,1),(2,3),(3,1),(4,1)},1 % 1)"
"({(1,2),(2,1),(3,2),(4,1)},1 % 1)"
"({(1,2),(2,2),(3,2),(4,2)},1 % 1)"
"({(1,2),(2,3),(3,2),(4,1)},1 % 1)"
"({(1,3),(2,1),(3,2),(4,1)},1 % 1)"
"({(1,3),(2,2),(3,2),(4,1)},1 % 1)"
"({(1,3),(2,3),(3,1),(4,2)},1 % 1)"
rp $ und tt'
"{1,2}"
rp $ der tt'
"{3,4}"
rpln $ aall $ regcart 3 2 `tmul` tt'
"({(3,1),(4,1)},2 % 1)"
"({(3,1),(4,2)},2 % 1)"
"({(3,2),(4,1)},4 % 1)"
"({(3,2),(4,2)},1 % 1)"
rpln $ aall $ regdiag 3 2 `tmul` tt'
"({(3,1),(4,2)},2 % 1)"
"({(3,2),(4,2)},1 % 1)"
Now the formal histogram of a regular diagonal underlying differs from the derived histogram,
rpln $ aall $ ind (regdiag 3 2) `tmul` tt'
"({(3,1),(4,1)},2 % 3)"
"({(3,1),(4,2)},2 % 3)"
"({(3,2),(4,1)},4 % 3)"
"({(3,2),(4,2)},1 % 3)"
ind (regdiag 3 2) `tmul` tt' == regdiag 3 2 `tmul` tt'
False
ind (regcart 3 2) `tmul` tt' == regcart 3 2 `tmul` tt'
True
The abstract histogram is defined as the derived independent, $(A * T)^{\mathrm{X}}$. In the case of the deck of cards example, the transform, $T$, has only one derived variable and so the derived histogram is already independent,
rpln $ aall $ ind (aa `tmul` tt)
"({(colour,black)},26 % 1)"
"({(colour,red)},26 % 1)"
ind (aa `tmul` tt) == aa `tmul` tt
True
In the case of transform $T’$, however, the abstract histogram of a regular cartesian underlying differs from the derived histogram,
rpln $ aall $ ind (regcart 3 2 `tmul` tt')
"({(3,1),(4,1)},8 % 3)"
"({(3,1),(4,2)},4 % 3)"
"({(3,2),(4,1)},10 % 3)"
"({(3,2),(4,2)},5 % 3)"
ind (regcart 3 2 `tmul` tt') == regcart 3 2 `tmul` tt'
False
ind (regdiag 3 2 `tmul` tt') == regdiag 3 2 `tmul` tt'
True
In the case where the formal and abstract are equal, $A^{\mathrm{X}} * T = (A * T)^{\mathrm{X}}$, the abstract equals the independent abstract, $(A * T)^{\mathrm{X}} = A^{\mathrm{X}} * T = (A^{\mathrm{X}} * T)^{\mathrm{X}}$, and so only depends on the independent, $A^{\mathrm{X}}$, not on the histogram, $A$. The formal equals the formal independent, $A^{\mathrm{X}} * T = (A * T)^{\mathrm{X}} = (A^{\mathrm{X}} * T)^{\mathrm{X}}$, and so is itself independent. For example, when the transform $T’$ has only one derived variable and varies with only one of the underlying variables,
let tt' = trans (cdaa [[1,1,1],[1,2,1],[1,3,1],[2,1,2],[2,2,2],[2,3,2],[3,1,2],[3,2,2],[3,3,2]]) (Set.fromList [VarInt 3])
rpln $ aall $ ttaa tt'
"({(1,1),(2,1),(3,1)},1 % 1)"
"({(1,1),(2,2),(3,1)},1 % 1)"
"({(1,1),(2,3),(3,1)},1 % 1)"
"({(1,2),(2,1),(3,2)},1 % 1)"
"({(1,2),(2,2),(3,2)},1 % 1)"
"({(1,2),(2,3),(3,2)},1 % 1)"
"({(1,3),(2,1),(3,2)},1 % 1)"
"({(1,3),(2,2),(3,2)},1 % 1)"
"({(1,3),(2,3),(3,2)},1 % 1)"
rpln $ aall $ regcart 3 2 `tmul` tt'
"({(3,1)},3 % 1)"
"({(3,2)},6 % 1)"
ind (regcart 3 2) `tmul` tt' == ind (regcart 3 2 `tmul` tt')
True
rpln $ aall $ regdiag 3 2 `tmul` tt'
"({(3,1)},1 % 1)"
"({(3,2)},2 % 1)"
ind (regdiag 3 2) `tmul` tt' == ind (regdiag 3 2 `tmul` tt')
True
In the case where $T’$ varies with both of the underlying variables, formal-abstract equivalence holds only for the cartesian,
let tt' = trans (cdaa [[1,1,1],[1,2,1],[1,3,1],[2,1,2],[2,2,2],[2,3,2],[3,1,2],[3,2,2],[3,3,1]]) (Set.fromList [VarInt 3])
rpln $ aall $ ttaa tt'
"({(1,1),(2,1),(3,1)},1 % 1)"
"({(1,1),(2,2),(3,1)},1 % 1)"
"({(1,1),(2,3),(3,1)},1 % 1)"
"({(1,2),(2,1),(3,2)},1 % 1)"
"({(1,2),(2,2),(3,2)},1 % 1)"
"({(1,2),(2,3),(3,2)},1 % 1)"
"({(1,3),(2,1),(3,2)},1 % 1)"
"({(1,3),(2,2),(3,2)},1 % 1)"
"({(1,3),(2,3),(3,1)},1 % 1)"
ind (regcart 3 2) `tmul` tt' == ind (regcart 3 2 `tmul` tt')
True
ind (regdiag 3 2) `tmul` tt' == ind (regdiag 3 2 `tmul` tt')
False
Functional transforms
A transform $T \in \mathcal{T}$ is functional if there is a causal relation between the underlying variables $K = \mathrm{und}(T)$ and the derived variables $W = \mathrm{der}(T)$, \[ \begin{eqnarray} \mathrm{split}(K,X^{\mathrm{FS}}) &\in& K^{\mathrm{CS}} \to W^{\mathrm{CS}} \end{eqnarray} \] where $X=\mathrm{his}(T)$. In the deck of cards example,
xx == ttaa tt
True
rpln $ aall $ xx
"({(colour,black),(suit,clubs)},1 % 1)"
"({(colour,black),(suit,spades)},1 % 1)"
"({(colour,red),(suit,diamonds)},1 % 1)"
"({(colour,red),(suit,hearts)},1 % 1)"
rp kk
"{suit}"
rp ww
"{colour}"
let ssplit = setVarsSetStatesSplit
rpln $ Set.toList $ ssplit kk (states xx)
"({(suit,clubs)},{(colour,black)})"
"({(suit,diamonds)},{(colour,red)})"
"({(suit,hearts)},{(colour,red)})"
"({(suit,spades)},{(colour,black)})"
let iscausal = histogramsIsCausal
iscausal xx
True
The expanded transform is still causal,
rpln $ Set.toList $ ssplit vv (states (ttaa ttv))
"({(rank,A),(suit,clubs)},{(colour,black)})"
"({(rank,A),(suit,diamonds)},{(colour,red)})"
"({(rank,A),(suit,hearts)},{(colour,red)})"
"({(rank,A),(suit,spades)},{(colour,black)})"
"({(rank,J),(suit,clubs)},{(colour,black)})"
"({(rank,J),(suit,diamonds)},{(colour,red)})"
...
"({(rank,9),(suit,hearts)},{(colour,red)})"
"({(rank,9),(suit,spades)},{(colour,black)})"
"({(rank,10),(suit,clubs)},{(colour,black)})"
"({(rank,10),(suit,diamonds)},{(colour,red)})"
"({(rank,10),(suit,hearts)},{(colour,red)})"
"({(rank,10),(suit,spades)},{(colour,black)})"
iscausal (ttaa ttv)
True
The set of functional transforms $\mathcal{T}_{\mathrm{f}} \subset \mathcal{T}$ is the subset of all transforms that are causal.
A functional transform $T \in \mathcal{T}_{\mathrm{f}}$ has an inverse, \[ \begin{eqnarray} T^{-1} &:=& \{((S\%K,c), S\%W) : (S,c) \in X\}^{-1} \end{eqnarray} \]
transformsInverse :: Transform -> Map.Map State Histogram
For example,
let inv = Map.toList . transformsInverse
rpln $ inv tt
"({(colour,black)},{({(suit,clubs)},1 % 1),({(suit,spades)},1 % 1)})"
"({(colour,red)},{({(suit,diamonds)},1 % 1),({(suit,hearts)},1 % 1)})"
rpln $ inv ttv
"({(colour,black)},{({(rank,A),(suit,clubs)},1 % 1),...,({(rank,10),(suit,spades)},1 % 1)})"
"({(colour,red)},{({(rank,A),(suit,diamonds)},1 % 1),...,({(rank,10),(suit,hearts)},1 % 1)})"
A transform $T$ is one functional in system $U$ if the reduction of the transform histogram to the underlying variables equals the cartesian histogram, $X\%K = K^{\mathrm{C}}$,
xx `ared` kk == unit (cart uu kk)
True
(ttaa ttv) `ared` vv == unit (cart uu vv)
True
So the causal relation is a derived state valued left total function of underlying state, $\mathrm{split}(K,X^{\mathrm{S}}) \in K^{\mathrm{CS}} :\to W^{\mathrm{CS}}$. The set of one functional transforms $\mathcal{T}_{U,\mathrm{f},1} \subset \mathcal{T}_{\mathrm{f}}$ is \[ \begin{eqnarray} \mathcal{T}_{U,\mathrm{f},1} &=& \{ (\{(S \cup R,1) : (S,R) \in Q\},W) : \\ &&\hspace{5em}K,W \subseteq \mathrm{vars}(U),~K \cap W = \emptyset, ~Q \in K^{\mathrm{CS}} :\to W^{\mathrm{CS}}\} \end{eqnarray} \] The application of a one functional transform to an underlying histogram preserves the size, $\mathrm{size}(A * T) = \mathrm{size}(A)$,
size (aa `tmul` tt) == size aa
True
size (aa `tmul` ttv) == size aa
True
The one functional transform inverse is a unit component valued function of derived state, $T^{-1} \in W^{\mathrm{CS}} \to \mathrm{P}(K^{\mathrm{C}})$. That is, the range of the inverse corresponds to a partition of the cartesian states into components, $\mathrm{ran}(T^{-1}) \in \mathrm{B}(K^{\mathrm{C}})$,
let [(_,cc),(_,dd)] = inv tt
rpln $ aall $ cc
"({(suit,clubs)},1 % 1)"
"({(suit,spades)},1 % 1)"
rpln $ aall $ dd
"({(suit,diamonds)},1 % 1)"
"({(suit,hearts)},1 % 1)"
cc `add` dd == unit (cart uu kk)
True
and
let [(_,cc),(_,dd)] = inv ttv
rpln $ aall $ cc
"({(rank,A),(suit,clubs)},1 % 1)"
"({(rank,A),(suit,spades)},1 % 1)"
"({(rank,J),(suit,clubs)},1 % 1)"
...
"({(rank,9),(suit,spades)},1 % 1)"
"({(rank,10),(suit,clubs)},1 % 1)"
"({(rank,10),(suit,spades)},1 % 1)"
rpln $ aall $ dd
"({(rank,A),(suit,diamonds)},1 % 1)"
"({(rank,A),(suit,hearts)},1 % 1)"
"({(rank,J),(suit,diamonds)},1 % 1)"
...
"({(rank,9),(suit,hearts)},1 % 1)"
"({(rank,10),(suit,diamonds)},1 % 1)"
"({(rank,10),(suit,hearts)},1 % 1)"
cc `add` dd == unit (cart uu vv)
True
The application of a one functional transform $T$ to its underlying cartesian $K^{\mathrm{C}}$ is the component cardinality histogram, $K^{\mathrm{C}} * T = \{(R,|C|) : (R,C) \in T^{-1}\}$,
rpln $ aall $ unit (cart uu kk) `tmul` tt
"({(colour,black)},2 % 1)"
"({(colour,red)},2 % 1)"
rpln $ aall $ unit (cart uu vv) `tmul` ttv
"({(colour,black)},26 % 1)"
"({(colour,red)},26 % 1)"
The effective cartesian derived volume is less than or equal to the derived volume, $|(K^{\mathrm{C}} * T)^{\mathrm{F}}| = |T^{-1}| \leq |W^{\mathrm{C}}|$,
Set.size $ states $ eff $ unit (cart uu kk) `tmul` tt
2
Set.size $ states $ eff $ unit (cart uu vv) `tmul` ttv
2
Application to history
A one functional transform $T \in \mathcal{T}_{U,\mathrm{f},1}$ may be applied to a history $H \in \mathcal{H}$ in the underlying variables of the transform, $\mathrm{vars}(H) \supseteq \mathrm{und}(T)$, to construct a derived history, \[ \begin{eqnarray} H * T &:=& \{(x,R) : (x,S) \in H,~\{R\} = (\{S\}^{\mathrm{U}} * T)^{\mathrm{FS}}\} \end{eqnarray} \] The size is unchanged, $|H * T| = |H|$, and the event identifiers are conserved, $\mathrm{dom}(H * T) = \mathrm{dom}(H)$.
transformsHistoriesApply :: Transform -> History -> History
For example,
let llhh = fromJust . listsHistory
hhll = historyToList
let hh = llhh $ zip (map IdInt [1..]) (Set.toList (cart uu vv))
rpln $ hhll hh
"(1,{(rank,A),(suit,clubs)})"
"(2,{(rank,A),(suit,diamonds)})"
"(3,{(rank,A),(suit,hearts)})"
"(4,{(rank,A),(suit,spades)})"
"(5,{(rank,J),(suit,clubs)})"
"(6,{(rank,J),(suit,diamonds)})"
...
"(47,{(rank,9),(suit,hearts)})"
"(48,{(rank,9),(suit,spades)})"
"(49,{(rank,10),(suit,clubs)})"
"(50,{(rank,10),(suit,diamonds)})"
"(51,{(rank,10),(suit,hearts)})"
"(52,{(rank,10),(suit,spades)})"
let htmul hh tt = transformsHistoriesApply tt hh
rpln $ hhll $ hh `htmul` tt
"(1,{(colour,black)})"
"(2,{(colour,red)})"
"(3,{(colour,red)})"
"(4,{(colour,black)})"
"(5,{(colour,black)})"
"(6,{(colour,red)})"
...
"(47,{(colour,red)})"
"(48,{(colour,black)})"
"(49,{(colour,black)})"
"(50,{(colour,red)})"
"(51,{(colour,red)})"
"(52,{(colour,black)})"
Partition transforms
Given a partition $P \in \mathrm{B}(V^{\mathrm{CS}})$ of the cartesian states of variables $V$, a one functional transform can be constructed. The partition transform is \[ \begin{eqnarray} P^{\mathrm{T}} &:=& (\{(S \cup \{(P,C)\}, 1) : C \in P,~S \in C \}, \{P\}) \end{eqnarray} \]
partitionsTransformVarPartition :: Partition -> Transform
The set of derived variables of the partition transform is a singleton of the partition variable, $\mathrm{der}(P^{\mathrm{T}}) = \{P\}$. The derived volume is the component cardinality, $|\{P\}^{\mathrm{C}}| = |P|$. The underlying variables are the given variables, $\mathrm{und}(P^{\mathrm{T}}) = V$. For example, consider a partition of the deck of cards,
let qqpp = fromJust . setComponentsPartition
ppqq = partitionsSetComponent
let cc = Set.fromList $ take 13 $ Set.toList $ cart uu vv
let dd = Set.fromList $ drop 13 $ Set.toList $ cart uu vv
let pp = qqpp $ Set.fromList [cc,dd]
Set.size (ppqq pp)
2
[Set.size ee | ee <- Set.toList (ppqq pp)]
[13,39]
let pptt = partitionsTransformVarPartition
rp $ und $ pptt pp
"{rank,suit}"
rpln $ aall $ ttaa (pptt pp) `ared` und (pptt pp)
"({(rank,A),(suit,clubs)},1 % 1)"
"({(rank,A),(suit,diamonds)},1 % 1)"
"({(rank,A),(suit,hearts)},1 % 1)"
"({(rank,A),(suit,spades)},1 % 1)"
"({(rank,J),(suit,clubs)},1 % 1)"
"({(rank,J),(suit,diamonds)},1 % 1)"
...
"({(rank,9),(suit,hearts)},1 % 1)"
"({(rank,9),(suit,spades)},1 % 1)"
"({(rank,10),(suit,clubs)},1 % 1)"
"({(rank,10),(suit,diamonds)},1 % 1)"
"({(rank,10),(suit,hearts)},1 % 1)"
"({(rank,10),(suit,spades)},1 % 1)"
der (pptt pp) == Set.singleton (VarPartition pp)
True
rpln $ snd $ unzip $ aall $ aa `tmul` pptt pp
"13 % 1"
"39 % 1"
The expanded transform in the deck of cards example partitions the cartesian set of states,
let [(_,cc),(_,dd)] = inv ttv
let pp = qqpp (Set.fromList [states cc,states dd])
Set.size $ ppqq pp
2
[Set.size ee | ee <- Set.toList (ppqq pp)]
[26,26]
rp $ und $ pptt pp
"{rank,suit}"
rpln $ aall $ ttaa (pptt pp) `ared` und (pptt pp)
"({(rank,A),(suit,clubs)},1 % 1)"
"({(rank,A),(suit,diamonds)},1 % 1)"
"({(rank,A),(suit,hearts)},1 % 1)"
"({(rank,A),(suit,spades)},1 % 1)"
"({(rank,J),(suit,clubs)},1 % 1)"
"({(rank,J),(suit,diamonds)},1 % 1)"
...
"({(rank,9),(suit,hearts)},1 % 1)"
"({(rank,9),(suit,spades)},1 % 1)"
"({(rank,10),(suit,clubs)},1 % 1)"
"({(rank,10),(suit,diamonds)},1 % 1)"
"({(rank,10),(suit,hearts)},1 % 1)"
"({(rank,10),(suit,spades)},1 % 1)"
der (pptt pp) == Set.singleton (VarPartition pp)
True
rpln $ snd $ unzip $ aall $ aa `tmul` pptt pp
"26 % 1"
"26 % 1"
The unary partition transform is $T_{\mathrm{u}} = \{V^{\mathrm{CS}}\}^{\mathrm{T}}$,
let unary uu vv = fromJust $ systemsSetVarsPartitionUnary uu vv
let uu' = sysreg 2 2
let pp = unary uu' (uvars uu')
Set.size $ ppqq pp
1
[Set.size ee | ee <- Set.toList (ppqq pp)]
[4]
rp $ und $ pptt pp
"{1,2}"
rp $ der $ pptt pp
"{ { { {(1,1),(2,1)},{(1,1),(2,2)},{(1,2),(2,1)},{(1,2),(2,2)} } } }"
rpln $ aall $ ttaa (pptt pp) `ared` und (pptt pp)
"({(1,1),(2,1)},1 % 1)"
"({(1,1),(2,2)},1 % 1)"
"({(1,2),(2,1)},1 % 1)"
"({(1,2),(2,2)},1 % 1)"
rpln $ aall $ ttaa (pptt pp)
"({(1,1),(2,1),({ { {(1,1),(2,1)},{(1,1),(2,2)},{(1,2),(2,1)},{(1,2),(2,2)} } },{ {(1,1),(2,1)},{(1,1),(2,2)},{(1,2),(2,1)},{(1,2),(2,2)} })},1 % 1)"
"({(1,1),(2,2),({ { {(1,1),(2,1)},{(1,1),(2,2)},{(1,2),(2,1)},{(1,2),(2,2)} } },{ {(1,1),(2,1)},{(1,1),(2,2)},{(1,2),(2,1)},{(1,2),(2,2)} })},1 % 1)"
"({(1,2),(2,1),({ { {(1,1),(2,1)},{(1,1),(2,2)},{(1,2),(2,1)},{(1,2),(2,2)} } },{ {(1,1),(2,1)},{(1,1),(2,2)},{(1,2),(2,1)},{(1,2),(2,2)} })},1 % 1)"
"({(1,2),(2,2),({ { {(1,1),(2,1)},{(1,1),(2,2)},{(1,2),(2,1)},{(1,2),(2,2)} } },{ {(1,1),(2,1)},{(1,1),(2,2)},{(1,2),(2,1)},{(1,2),(2,2)} })},1 % 1)"
The self partition transform is $T_{\mathrm{s}} = V^{\mathrm{CS}\{\}\mathrm{T}}$,
let self uu vv = fromJust $ systemsSetVarsPartitionSelf uu vv
let uu' = sysreg 2 2
let pp = self uu' (uvars uu')
Set.size $ ppqq pp
4
[Set.size ee | ee <- Set.toList (ppqq pp)]
[1,1,1,1]
rp $ und $ pptt pp
"{1,2}"
rp $ der $ pptt pp
"{ { { {(1,1),(2,1)} },{ {(1,1),(2,2)} },{ {(1,2),(2,1)} },{ {(1,2),(2,2)} } } }"
rpln $ aall $ ttaa (pptt pp) `ared` und (pptt pp)
"({(1,1),(2,1)},1 % 1)"
"({(1,1),(2,2)},1 % 1)"
"({(1,2),(2,1)},1 % 1)"
"({(1,2),(2,2)},1 % 1)"
rpln $ aall $ ttaa (pptt pp)
"({(1,1),(2,1),({ { {(1,1),(2,1)} },{ {(1,1),(2,2)} },{ {(1,2),(2,1)} },{ {(1,2),(2,2)} } },{ {(1,1),(2,1)} })},1 % 1)"
"({(1,1),(2,2),({ { {(1,1),(2,1)} },{ {(1,1),(2,2)} },{ {(1,2),(2,1)} },{ {(1,2),(2,2)} } },{ {(1,1),(2,2)} })},1 % 1)"
"({(1,2),(2,1),({ { {(1,1),(2,1)} },{ {(1,1),(2,2)} },{ {(1,2),(2,1)} },{ {(1,2),(2,2)} } },{ {(1,2),(2,1)} })},1 % 1)"
"({(1,2),(2,2),({ { {(1,1),(2,1)} },{ {(1,1),(2,2)} },{ {(1,2),(2,1)} },{ {(1,2),(2,2)} } },{ {(1,2),(2,2)} })},1 % 1)"
Natural converse
Given a one functional transform $T \in \mathcal{T}_{U,\mathrm{f},1}$, the natural converse is \[ \begin{eqnarray} T^{\dagger} &:=& (X/(X\%W),V) \end{eqnarray} \] where $(X,W) = T$ and $V = \mathrm{und}(T)$,
transformsConverseNatural :: Transform -> Transform
In the deck of cards example, the natural converse of the expanded suit-colour transform is
let nat = transformsConverseNatural
rpln $ aall $ ttaa ttv
"({(colour,black),(rank,A),(suit,clubs)},1 % 1)"
"({(colour,black),(rank,A),(suit,spades)},1 % 1)"
"({(colour,black),(rank,J),(suit,clubs)},1 % 1)"
...
"({(colour,red),(rank,9),(suit,hearts)},1 % 1)"
"({(colour,red),(rank,10),(suit,diamonds)},1 % 1)"
"({(colour,red),(rank,10),(suit,hearts)},1 % 1)"
rp $ der ttv
"{colour}"
rp $ und ttv
"{rank,suit}"
rpln $ aall $ ttaa $ nat ttv
"({(colour,black),(rank,A),(suit,clubs)},1 % 26)"
"({(colour,black),(rank,A),(suit,spades)},1 % 26)"
"({(colour,black),(rank,J),(suit,clubs)},1 % 26)"
...
"({(colour,red),(rank,9),(suit,hearts)},1 % 26)"
"({(colour,red),(rank,10),(suit,diamonds)},1 % 26)"
"({(colour,red),(rank,10),(suit,hearts)},1 % 26)"
rp $ der $ nat ttv
"{rank,suit}"
rp $ und $ nat ttv
"{colour}"
Another example is $T’$,
let cdtt pp ll = trans (cdaa ll `cdtp` pp) (Set.singleton (VarInt (last pp)))
let tt' = cdtt [1,2,3] [[1,1,1],[1,2,1],[1,3,1],[2,1,2],[2,2,2],[2,3,2],[3,1,2],[3,2,2],[3,3,1]]
rpln $ aall $ ttaa tt'
"({(1,1),(2,1),(3,1)},1 % 1)"
"({(1,1),(2,2),(3,1)},1 % 1)"
"({(1,1),(2,3),(3,1)},1 % 1)"
"({(1,2),(2,1),(3,2)},1 % 1)"
"({(1,2),(2,2),(3,2)},1 % 1)"
"({(1,2),(2,3),(3,2)},1 % 1)"
"({(1,3),(2,1),(3,2)},1 % 1)"
"({(1,3),(2,2),(3,2)},1 % 1)"
"({(1,3),(2,3),(3,1)},1 % 1)"
rp $ der tt'
"{3}"
rpln $ aall $ ttaa $ nat tt'
"({(1,1),(2,1),(3,1)},1 % 4)"
"({(1,1),(2,2),(3,1)},1 % 4)"
"({(1,1),(2,3),(3,1)},1 % 4)"
"({(1,2),(2,1),(3,2)},1 % 5)"
"({(1,2),(2,2),(3,2)},1 % 5)"
"({(1,2),(2,3),(3,2)},1 % 5)"
"({(1,3),(2,1),(3,2)},1 % 5)"
"({(1,3),(2,2),(3,2)},1 % 5)"
"({(1,3),(2,3),(3,1)},1 % 4)"
rp $ der $ nat tt'
"{1,2}"
The natural converse may be expressed in terms of components, \[ T^{\dagger}~:=~(\sum_{(R,C) \in T^{-1}} \{R\}^{\mathrm{U}} * \hat{C},~V) \]
let inv = Map.toList . transformsInverse
sunit = unit . Set.singleton
rpln $ inv ttv
"({(colour,black)},{({(rank,A),(suit,clubs)},1 % 1),...,({(rank,10),(suit,spades)},1 % 1)})"
"({(colour,red)},{({(rank,A),(suit,diamonds)},1 % 1),...,({(rank,10),(suit,hearts)},1 % 1)})"
rpln $ aall $ foldl1 add [sunit rr `mul` norm cc | (rr,cc) <- inv ttv]
"({(colour,black),(rank,A),(suit,clubs)},1 % 26)"
"({(colour,black),(rank,A),(suit,spades)},1 % 26)"
"({(colour,black),(rank,J),(suit,clubs)},1 % 26)"
...
"({(colour,red),(rank,9),(suit,hearts)},1 % 26)"
"({(colour,red),(rank,10),(suit,diamonds)},1 % 26)"
"({(colour,red),(rank,10),(suit,hearts)},1 % 26)"
rpln $ inv tt'
"({(3,1)},{({(1,1),(2,1)},1 % 1),({(1,1),(2,2)},1 % 1),({(1,1),(2,3)},1 % 1),({(1,3),(2,3)},1 % 1)})"
"({(3,2)},{({(1,2),(2,1)},1 % 1),({(1,2),(2,2)},1 % 1),({(1,2),(2,3)},1 % 1),({(1,3),(2,1)},1 % 1),({(1,3),(2,2)},1 % 1)})"
rpln $ aall $ foldl1 add [sunit rr `mul` norm cc | (rr,cc) <- inv tt']
"({(1,1),(2,1),(3,1)},1 % 4)"
"({(1,1),(2,2),(3,1)},1 % 4)"
"({(1,1),(2,3),(3,1)},1 % 4)"
"({(1,2),(2,1),(3,2)},1 % 5)"
"({(1,2),(2,2),(3,2)},1 % 5)"
"({(1,2),(2,3),(3,2)},1 % 5)"
"({(1,3),(2,1),(3,2)},1 % 5)"
"({(1,3),(2,2),(3,2)},1 % 5)"
"({(1,3),(2,3),(3,1)},1 % 4)"
Given a histogram $A \in \mathcal{A}$ in the underlying variables, $\mathrm{vars}(A) = V$, the naturalisation is the application of the natural converse transform to the derived histogram, $A * T * T^{\dagger}$,
rpln $ aall $ aa `tmul` ttv `tmul` nat ttv
"({(rank,A),(suit,clubs)},1 % 1)"
"({(rank,A),(suit,diamonds)},1 % 1)"
"({(rank,A),(suit,hearts)},1 % 1)"
"({(rank,A),(suit,spades)},1 % 1)"
"({(rank,J),(suit,clubs)},1 % 1)"
"({(rank,J),(suit,diamonds)},1 % 1)"
...
"({(rank,9),(suit,hearts)},1 % 1)"
"({(rank,9),(suit,spades)},1 % 1)"
"({(rank,10),(suit,clubs)},1 % 1)"
"({(rank,10),(suit,diamonds)},1 % 1)"
"({(rank,10),(suit,hearts)},1 % 1)"
"({(rank,10),(suit,spades)},1 % 1)"
A histogram is natural when it equals its naturalisation, $A = A * T * T^{\dagger}$, so the deck of cards histogram is natural,
aa `tmul` ttv `tmul` nat ttv == aa
True
The cartesian is always natural, $V^{\mathrm{C}} = V^{\mathrm{C}} * T * T^{\dagger}$, so $T’$ applied to the cartesian is natural,
rpln $ aall $ regcart 3 2 `tmul` tt' `tmul` nat tt'
"({(1,1),(2,1)},1 % 1)"
"({(1,1),(2,2)},1 % 1)"
"({(1,1),(2,3)},1 % 1)"
"({(1,2),(2,1)},1 % 1)"
"({(1,2),(2,2)},1 % 1)"
"({(1,2),(2,3)},1 % 1)"
"({(1,3),(2,1)},1 % 1)"
"({(1,3),(2,2)},1 % 1)"
"({(1,3),(2,3)},1 % 1)"
regcart 3 2 `tmul` tt' `tmul` nat tt' == regcart 3 2
True
but $T’$ applied to the diagonal is not,
rpln $ aall $ regdiag 3 2 `tmul` tt' `tmul` nat tt'
"({(1,1),(2,1)},1 % 2)"
"({(1,1),(2,2)},1 % 2)"
"({(1,1),(2,3)},1 % 2)"
"({(1,2),(2,1)},1 % 5)"
"({(1,2),(2,2)},1 % 5)"
"({(1,2),(2,3)},1 % 5)"
"({(1,3),(2,1)},1 % 5)"
"({(1,3),(2,2)},1 % 5)"
"({(1,3),(2,3)},1 % 2)"
regdiag 3 2 `tmul` tt' `tmul` nat tt' == regdiag 3 2
False
The naturalisation can be rewritten $A * X~\%~W * X~/~(X\%W)~\%~V$,
aa `mul` ttaa ttv `ared` der ttv `mul` ttaa ttv `divide` (ttaa ttv `ared` der ttv) `ared` vv == aa `tmul` ttv `tmul` nat ttv
True
The naturalisation is in the underlying variables, $\mathrm{vars}(A * T * T^{\dagger}) = V$,
rp $ vars $ aa `tmul` ttv `tmul` nat ttv
"{rank,suit}"
The size is conserved, $\mathrm{size}(A * T * T^{\dagger}) = \mathrm{size}(A)$,
size (aa `tmul` ttv `tmul` nat ttv) == size aa
True
The naturalisation derived equals the derived, $A * T * T^{\dagger} * T = A * T$,
aa `tmul` ttv `tmul` nat ttv `tmul` ttv == aa `tmul` ttv
True
The naturalisation equals the sum of the scaled components, \[ \begin{eqnarray} A * T * T^{\dagger} &=& \sum_{(R,C) \in T^{-1}} \mathrm{scalar}( (A * T)_R) * \hat{C} \\ &=& \sum_{(R,C) \in T^{-1}} A * T * \{R\}^{\mathrm{U}} * \hat{C}~\%~V \end{eqnarray} \]
aa `tmul` ttv `tmul` nat ttv == foldl1 add [scalar (aa `tmul` ttv `aat` rr) `mul` norm cc | (rr,cc) <- inv ttv]
True
aa `tmul` ttv `tmul` nat ttv == foldl1 add [aa `tmul` ttv `mul` sunit rr `mul` norm cc `ared` vv | (rr,cc) <- inv ttv]
True
So each component is uniform, \[ \forall (R,C) \in T^{-1}~(|\mathrm{ran}(A * T * T^{\dagger} * C)| ~=~ 1) \]
let isunif = histogramsIsUniform
[isunif (aa `tmul` ttv `tmul` nat ttv `mul` cc) | (rr,cc) <- inv ttv]
[True,True]
The naturalisation of the unary partition transform, $T_{\mathrm{u}} = \{V^{\mathrm{CS}}\}^{\mathrm{T}}$, is the sized cartesian, $A * T_{\mathrm{u}} * T_{\mathrm{u}}^{\dagger} = V_z^{\mathrm{C}}$, where $z=\mathrm{size}(A)$,
let unary uu vv = pptt $ fromJust $ systemsSetVarsPartitionUnary uu vv
aa `tmul` (unary uu vv) `tmul` nat (unary uu vv) == resize (size aa) (unit (cart uu vv))
True
The naturalisation of the self partition transform, $T_{\mathrm{s}} = V^{\mathrm{CS}\{\}\mathrm{T}}$, is the histogram, $A * T_{\mathrm{s}} * T_{\mathrm{s}}^{\dagger} = A$,
let self uu vv = pptt $ fromJust $ systemsSetVarsPartitionSelf uu vv
aa `tmul` (self uu vv) `tmul` nat (self uu vv) == aa
True
Sample converse
Given a one functional transform $T \in \mathcal{T}_{U,\mathrm{f},1}$ with underlying variables $V = \mathrm{und}(T)$, and a histogram $A \in \mathcal{A}$ in the same variables, $\mathrm{vars}(A) = V$, the sample converse is \[ \begin{eqnarray} (\hat{A} * X,V) \end{eqnarray} \] where $X = \mathrm{his}(T)$. The sample converse for the deck of cards example is
let tta = trans (norm aa `mul` ttaa ttv) (vars aa)
rpln $ aall $ ttaa tta
"({(colour,black),(rank,A),(suit,clubs)},1 % 52)"
"({(colour,black),(rank,A),(suit,spades)},1 % 52)"
"({(colour,black),(rank,J),(suit,clubs)},1 % 52)"
"({(colour,black),(rank,J),(suit,spades)},1 % 52)"
"({(colour,black),(rank,K),(suit,clubs)},1 % 52)"
"({(colour,black),(rank,K),(suit,spades)},1 % 52)"
...
"({(colour,red),(rank,8),(suit,diamonds)},1 % 52)"
"({(colour,red),(rank,8),(suit,hearts)},1 % 52)"
"({(colour,red),(rank,9),(suit,diamonds)},1 % 52)"
"({(colour,red),(rank,9),(suit,hearts)},1 % 52)"
"({(colour,red),(rank,10),(suit,diamonds)},1 % 52)"
"({(colour,red),(rank,10),(suit,hearts)},1 % 52)"
rp $ der tta
"{rank,suit}"
rp $ und tta
"{colour}"
Actual converse
Related to the sample converse, the actual converse is defined as the summed normalised application of the components to the sample histogram, \[ \begin{eqnarray} T^{\odot A} &:=& (\sum_{(R,C) \in T^{-1}} {R}^{\mathrm{U}} * (A * C)^{\wedge},~V) \end{eqnarray} \]
histogramsTransformsConverseActual :: Histogram -> Transform -> Maybe Transform
In the deck of cards example, the actual converse of the expanded suit-colour transform is
let act tt aa = fromJust $ histogramsTransformsConverseActual aa tt
rpln $ aall $ ttaa $ act ttv aa
"({(colour,black),(rank,A),(suit,clubs)},1 % 26)"
"({(colour,black),(rank,A),(suit,spades)},1 % 26)"
"({(colour,black),(rank,J),(suit,clubs)},1 % 26)"
...
"({(colour,red),(rank,9),(suit,hearts)},1 % 26)"
"({(colour,red),(rank,10),(suit,diamonds)},1 % 26)"
"({(colour,red),(rank,10),(suit,hearts)},1 % 26)"
rp $ der $ act ttv aa
"{rank,suit}"
rp $ und $ act ttv aa
"{colour}"
Another example is $T’$,
let tt' = cdtt [1,2,3] [[1,1,1],[1,2,1],[1,3,1],[2,1,2],[2,2,2],[2,3,2],[3,1,2],[3,2,2],[3,3,1]]
rpln $ aall $ ttaa $ act tt' (regcart 3 2)
"({(1,1),(2,1),(3,1)},1 % 4)"
"({(1,1),(2,2),(3,1)},1 % 4)"
"({(1,1),(2,3),(3,1)},1 % 4)"
"({(1,2),(2,1),(3,2)},1 % 5)"
"({(1,2),(2,2),(3,2)},1 % 5)"
"({(1,2),(2,3),(3,2)},1 % 5)"
"({(1,3),(2,1),(3,2)},1 % 5)"
"({(1,3),(2,2),(3,2)},1 % 5)"
"({(1,3),(2,3),(3,1)},1 % 4)"
rp $ der $ act tt' (regcart 3 2)
"{1,2}"
rpln $ aall $ ttaa $ act tt' (regdiag 3 2)
"({(1,1),(2,1),(3,1)},1 % 2)"
"({(1,2),(2,2),(3,2)},1 % 1)"
"({(1,3),(2,3),(3,1)},1 % 2)"
rp $ der $ act tt' (regdiag 3 2)
"{1,2}"
The actual converse may be expressed in terms of components,
rpln $ aall $ foldl1 add [sunit rr `mul` norm (aa `mul` cc) | (rr,cc) <- inv ttv]
"({(colour,black),(rank,A),(suit,clubs)},1 % 26)"
"({(colour,black),(rank,A),(suit,spades)},1 % 26)"
"({(colour,black),(rank,J),(suit,clubs)},1 % 26)"
...
"({(colour,red),(rank,9),(suit,hearts)},1 % 26)"
"({(colour,red),(rank,10),(suit,diamonds)},1 % 26)"
"({(colour,red),(rank,10),(suit,hearts)},1 % 26)"
rpln $ aall $ foldl1 add [sunit rr `mul` norm (regcart 3 2 `mul` cc) | (rr,cc) <- inv tt']
"({(1,1),(2,1),(3,1)},1 % 4)"
"({(1,1),(2,2),(3,1)},1 % 4)"
"({(1,1),(2,3),(3,1)},1 % 4)"
"({(1,2),(2,1),(3,2)},1 % 5)"
"({(1,2),(2,2),(3,2)},1 % 5)"
"({(1,2),(2,3),(3,2)},1 % 5)"
"({(1,3),(2,1),(3,2)},1 % 5)"
"({(1,3),(2,2),(3,2)},1 % 5)"
"({(1,3),(2,3),(3,1)},1 % 4)"
rpln $ aall $ foldl1 add [sunit rr `mul` norm (regdiag 3 2 `mul` cc) | (rr,cc) <- inv tt']
"({(1,1),(2,1),(3,1)},1 % 2)"
"({(1,2),(2,2),(3,2)},1 % 1)"
"({(1,3),(2,3),(3,1)},1 % 2)"
The application of the actual converse transform to the derived histogram equals the histogram, $A * T * T^{\odot A} = A$,
aa `tmul` ttv `tmul` act ttv aa == aa
True
regcart 3 2 `tmul` tt' `tmul` act tt' (regcart 3 2) == regcart 3 2
True
regdiag 3 2 `tmul` tt' `tmul` act tt' (regdiag 3 2) == regdiag 3 2
True
Independent converse
Given a one functional transform $T \in \mathcal{T}_{U,\mathrm{f},1}$ with underlying variables $V = \mathrm{und}(T)$, and a histogram $A \in \mathcal{A}$ in the same variables, $\mathrm{vars}(A) = V$, the independent converse is defined as the summed normalised independent application of the components to the sample histogram, \[ \begin{eqnarray} T^{\dagger A} &:=& (\sum_{(R,C) \in T^{-1}} \{R\}^{\mathrm{U}} * (A * C)^{\wedge\mathrm{X}},~V) \end{eqnarray} \]
histogramsTransformsConverseIndependent :: Histogram -> Transform -> Maybe Transform
In the deck of cards example, the independent converse of the expanded suit-colour transform is
let idl tt aa = fromJust $ histogramsTransformsConverseIndependent aa tt
rpln $ aall $ ttaa $ idl ttv aa
"({(colour,black),(rank,A),(suit,clubs)},1 % 26)"
"({(colour,black),(rank,A),(suit,spades)},1 % 26)"
"({(colour,black),(rank,J),(suit,clubs)},1 % 26)"
...
"({(colour,red),(rank,9),(suit,hearts)},1 % 26)"
"({(colour,red),(rank,10),(suit,diamonds)},1 % 26)"
"({(colour,red),(rank,10),(suit,hearts)},1 % 26)"
rp $ der $ idl ttv aa
"{rank,suit}"
rp $ und $ idl ttv aa
"{colour}"
Another example is $T’$,
let tt' = cdtt [1,2,3] [[1,1,1],[1,2,1],[1,3,1],[2,1,2],[2,2,2],[2,3,2],[3,1,2],[3,2,2],[3,3,1]]
rpln $ aall $ ttaa $ idl tt' (regcart 3 2)
"({(1,1),(2,1),(3,1)},3 % 16)"
"({(1,1),(2,2),(3,1)},3 % 16)"
"({(1,1),(2,3),(3,1)},3 % 8)"
"({(1,2),(2,1),(3,2)},6 % 25)"
"({(1,2),(2,2),(3,2)},6 % 25)"
"({(1,2),(2,3),(3,2)},3 % 25)"
"({(1,3),(2,1),(3,1)},1 % 16)"
"({(1,3),(2,1),(3,2)},4 % 25)"
"({(1,3),(2,2),(3,1)},1 % 16)"
"({(1,3),(2,2),(3,2)},4 % 25)"
"({(1,3),(2,3),(3,1)},1 % 8)"
"({(1,3),(2,3),(3,2)},2 % 25)"
rp $ der $ idl tt' (regcart 3 2)
"{1,2}"
rpln $ aall $ ttaa $ idl tt' (regdiag 3 2)
"({(1,1),(2,1),(3,1)},1 % 4)"
"({(1,1),(2,3),(3,1)},1 % 4)"
"({(1,2),(2,2),(3,2)},1 % 1)"
"({(1,3),(2,1),(3,1)},1 % 4)"
"({(1,3),(2,3),(3,1)},1 % 4)"
rp $ der $ idl tt' (regdiag 3 2)
"{1,2}"
The independent converse may be expressed in terms of components,
rpln $ aall $ foldl1 add [sunit rr `mul` ind (norm (aa `mul` cc)) | (rr,cc) <- inv ttv]
"({(colour,black),(rank,A),(suit,clubs)},1 % 26)"
"({(colour,black),(rank,A),(suit,spades)},1 % 26)"
"({(colour,black),(rank,J),(suit,clubs)},1 % 26)"
...
"({(colour,red),(rank,9),(suit,hearts)},1 % 26)"
"({(colour,red),(rank,10),(suit,diamonds)},1 % 26)"
"({(colour,red),(rank,10),(suit,hearts)},1 % 26)"
rpln $ aall $ foldl1 add [sunit rr `mul` ind (norm (regcart 3 2 `mul` cc)) | (rr,cc) <- inv tt']
"({(1,1),(2,1),(3,1)},3 % 16)"
"({(1,1),(2,2),(3,1)},3 % 16)"
"({(1,1),(2,3),(3,1)},3 % 8)"
"({(1,2),(2,1),(3,2)},6 % 25)"
"({(1,2),(2,2),(3,2)},6 % 25)"
"({(1,2),(2,3),(3,2)},3 % 25)"
"({(1,3),(2,1),(3,1)},1 % 16)"
"({(1,3),(2,1),(3,2)},4 % 25)"
"({(1,3),(2,2),(3,1)},1 % 16)"
"({(1,3),(2,2),(3,2)},4 % 25)"
"({(1,3),(2,3),(3,1)},1 % 8)"
"({(1,3),(2,3),(3,2)},2 % 25)"
rpln $ aall $ foldl1 add [sunit rr `mul` ind (norm (regdiag 3 2 `mul` cc)) | (rr,cc) <- inv tt']
"({(1,1),(2,1),(3,1)},1 % 4)"
"({(1,1),(2,3),(3,1)},1 % 4)"
"({(1,2),(2,2),(3,2)},1 % 1)"
"({(1,3),(2,1),(3,1)},1 % 4)"
"({(1,3),(2,3),(3,1)},1 % 4)"
The idealisation is the application of the independent converse transform to the derived histogram, $A * T * T^{\dagger A}$,
rpln $ aall $ aa `tmul` ttv `tmul` idl ttv aa
"({(rank,A),(suit,clubs)},1 % 1)"
"({(rank,A),(suit,diamonds)},1 % 1)"
"({(rank,A),(suit,hearts)},1 % 1)"
"({(rank,A),(suit,spades)},1 % 1)"
"({(rank,J),(suit,clubs)},1 % 1)"
"({(rank,J),(suit,diamonds)},1 % 1)"
...
"({(rank,9),(suit,hearts)},1 % 1)"
"({(rank,9),(suit,spades)},1 % 1)"
"({(rank,10),(suit,clubs)},1 % 1)"
"({(rank,10),(suit,diamonds)},1 % 1)"
"({(rank,10),(suit,hearts)},1 % 1)"
"({(rank,10),(suit,spades)},1 % 1)"
rpln $ aall $ regcart 3 2 `tmul` tt' `tmul` idl tt' (regcart 3 2)
"({(1,1),(2,1)},3 % 4)"
"({(1,1),(2,2)},3 % 4)"
"({(1,1),(2,3)},3 % 2)"
"({(1,2),(2,1)},6 % 5)"
"({(1,2),(2,2)},6 % 5)"
"({(1,2),(2,3)},3 % 5)"
"({(1,3),(2,1)},21 % 20)"
"({(1,3),(2,2)},21 % 20)"
"({(1,3),(2,3)},9 % 10)"
rpln $ aall $ regdiag 3 2 `tmul` tt' `tmul` idl tt' (regdiag 3 2)
"({(1,1),(2,1)},1 % 2)"
"({(1,1),(2,3)},1 % 2)"
"({(1,2),(2,2)},1 % 1)"
"({(1,3),(2,1)},1 % 2)"
"({(1,3),(2,3)},1 % 2)"
A histogram is ideal when it equals its idealisation, $A = A * T * T^{\dagger A}$, so the deck of cards histogram is ideal,
aa `tmul` ttv `tmul` idl ttv aa == aa
True
$T’$ applied to the cartesian is not ideal,
regcart 3 2 `tmul` tt' `tmul` idl tt' (regcart 3 2) == regcart 3 2
False
nor is the application to the diagonal,
regdiag 3 2 `tmul` tt' `tmul` idl tt' (regdiag 3 2) == regdiag 3 2
False
The idealisation is in the underlying variables, $\mathrm{vars}(A * T * T^{\dagger A}) = V$,
rp $ vars $ aa `tmul` ttv `tmul` idl ttv aa
"{rank,suit}"
The size is conserved, $\mathrm{size}(A * T * T^{\dagger A}) = \mathrm{size}(A)$,
size (aa `tmul` ttv `tmul` idl ttv aa) == size aa
True
The idealisation derived equals the derived, $A * T * T^{\dagger A} * T = A * T$,
aa `tmul` ttv `tmul` idl ttv aa `tmul` ttv == aa `tmul` ttv
True
The idealisation equals the sum of the independent components, \[ \begin{eqnarray} A * T * T^{\dagger A} &=& \sum_{(R,C) \in T^{-1}} (A * C)^{\mathrm{X}} \\ &=& \sum_{(R,C) \in T^{-1}} A * T * \{R\}^{\mathrm{U}} * (A * C)^{\wedge\mathrm{X}}~\%~V \end{eqnarray} \]
aa `tmul` ttv `tmul` idl ttv aa == foldl1 add [ind (aa `mul` cc) | (rr,cc) <- inv ttv]
True
aa `tmul` ttv `tmul` idl ttv aa == foldl1 add [aa `tmul` ttv `mul` sunit rr `mul` norm (ind (aa `mul` cc)) `ared` vv | (rr,cc) <- inv ttv]
True
So each component is independent, \[ \forall (R,C) \in T^{-1}~(A * T * T^{\dagger A} * C = (A * T * T^{\dagger A} * C)^{\mathrm{X}} = (A * C)^{\mathrm{X}}) \]
[aa `tmul` ttv `tmul` idl ttv aa `mul` cc == ind (aa `mul` cc) | (rr,cc) <- inv ttv]
[True,True]
The idealisation of the unary partition transform, $T_{\mathrm{u}} = \{V^{\mathrm{CS}}\}^{\mathrm{T}}$, is the sized cartesian, $A * T_{\mathrm{u}} * T_{\mathrm{u}}^{\dagger A} = V_z^{\mathrm{C}}$,
let unary uu vv = pptt $ fromJust $ systemsSetVarsPartitionUnary uu vv
aa `tmul` (unary uu vv) `tmul` idl (unary uu vv) aa == resize (size aa) (unit (cart uu vv))
True
The idealisation of the self partition transform, $T_{\mathrm{s}} = V^{\mathrm{CS}\{\}\mathrm{T}}$, is the histogram, $A * T_{\mathrm{s}} * T_{\mathrm{s}}^{\dagger A} = A$,
let self uu vv = pptt $ fromJust $ systemsSetVarsPartitionSelf uu vv
aa `tmul` (self uu vv) `tmul` idl (self uu vv) aa == aa
True
The idealisation independent equals the independent, $(A * T * T^{\dagger A})^{\mathrm{X}} = A^{\mathrm{X}}$,
ind (aa `tmul` ttv `tmul` idl ttv aa) == ind aa
True
ind (regcart 3 2 `tmul` tt' `tmul` idl tt' (regcart 3 2)) == ind (regcart 3 2)
True
ind (regdiag 3 2 `tmul` tt' `tmul` idl tt' (regdiag 3 2)) == ind (regdiag 3 2)
True
The idealisation formal equals the formal, $(A * T * T^{\dagger A})^{\mathrm{X}} * T = A^{\mathrm{X}} * T$,
ind (aa `tmul` ttv `tmul` idl ttv aa) `tmul` ttv == ind aa `tmul` ttv
True
ind (regcart 3 2 `tmul` tt' `tmul` idl tt' (regcart 3 2)) `tmul` tt' == ind (regcart 3 2) `tmul` tt'
True
ind (regdiag 3 2 `tmul` tt' `tmul` idl tt' (regdiag 3 2)) `tmul` tt'== ind (regdiag 3 2) `tmul` tt'
True
Transforms as models
The sense in which a transform is a simple model can be seen by considering queries on a sample histogram. Let histogram $A$ have a set of variables $V = \mathrm{vars}(A)$ which is partitioned into query variables $K \subset V$ and label variables $V \setminus K$. Let $T = (X,W)$ be a one functional transform having underlying variables equal to the query variables, $\mathrm{und}(T) = K$. Given a query state $Q \in K^{\mathrm{CS}}$ that may be ineffective in the sample, $Q \notin (A\%K)^{\mathrm{FS}}$, but is effective in the sample derived, $R \in (A * T)^{\mathrm{FS}}$ where $\{R\} = (\{Q\}^{\mathrm{U}} * T)^{\mathrm{FS}}$, the probability histogram for the label is \[ \begin{eqnarray} (\{Q\}^{\mathrm{U}} * T * (\hat{A} * X,V))^{\wedge}~\%~(V \setminus K) &\in& \mathcal{A} \cap \mathcal{P} \end{eqnarray} \] where the sample converse transform is $(\hat{A} * X,V)$. This can be expressed more simply in terms of the actual converse, \[ \begin{eqnarray} \{Q\}^{\mathrm{U}} * T * T^{\odot A}~\%~(V \setminus K) &\in& \mathcal{A} \cap \mathcal{P} \end{eqnarray} \] The query of the sample via model can also be written without the transforms, $(\{Q\}^{\mathrm{U}} * X~\%~W * X * A)^{\wedge}~\%~(V \setminus K)$. In the deck of cards example, the model of the colours of the suits does not tell us anything about the rank given the suit in the case where the histogram is the entire deck,
let qq = unit (Set.singleton (llss [(suit,clubs)]))
let vk = Set.fromList [rank]
rpln $ aall $ norm $ qq `tmul` tt `mul` xx `mul` aa `ared` vk
"({(rank,A)},1 % 13)"
"({(rank,J)},1 % 13)"
"({(rank,K)},1 % 13)"
"({(rank,Q)},1 % 13)"
"({(rank,2)},1 % 13)"
"({(rank,3)},1 % 13)"
"({(rank,4)},1 % 13)"
"({(rank,5)},1 % 13)"
"({(rank,6)},1 % 13)"
"({(rank,7)},1 % 13)"
"({(rank,8)},1 % 13)"
"({(rank,9)},1 % 13)"
"({(rank,10)},1 % 13)"
If, however, we consider a game of cards which has a special deck such that spades and clubs are pip cards and hearts and diamonds are face cards, the suit and the rank are no longer independent,
let bb = unit $ Set.fromList $
[llss [(suit,s),(rank,r)] | s <- [spades,clubs], r <- ace : map ValInt [2..10]] ++
[llss [(suit,s),(rank,r)] | s <- [hearts,diamonds], r <- [jack,queen,king]]
rpln $ aall bb
"({(rank,A),(suit,clubs)},1 % 1)"
"({(rank,A),(suit,spades)},1 % 1)"
"({(rank,J),(suit,diamonds)},1 % 1)"
"({(rank,J),(suit,hearts)},1 % 1)"
"({(rank,K),(suit,diamonds)},1 % 1)"
"({(rank,K),(suit,hearts)},1 % 1)"
"({(rank,Q),(suit,diamonds)},1 % 1)"
"({(rank,Q),(suit,hearts)},1 % 1)"
"({(rank,2),(suit,clubs)},1 % 1)"
"({(rank,2),(suit,spades)},1 % 1)"
"({(rank,3),(suit,clubs)},1 % 1)"
"({(rank,3),(suit,spades)},1 % 1)"
"({(rank,4),(suit,clubs)},1 % 1)"
"({(rank,4),(suit,spades)},1 % 1)"
"({(rank,5),(suit,clubs)},1 % 1)"
"({(rank,5),(suit,spades)},1 % 1)"
"({(rank,6),(suit,clubs)},1 % 1)"
"({(rank,6),(suit,spades)},1 % 1)"
"({(rank,7),(suit,clubs)},1 % 1)"
"({(rank,7),(suit,spades)},1 % 1)"
"({(rank,8),(suit,clubs)},1 % 1)"
"({(rank,8),(suit,spades)},1 % 1)"
"({(rank,9),(suit,clubs)},1 % 1)"
"({(rank,9),(suit,spades)},1 % 1)"
"({(rank,10),(suit,clubs)},1 % 1)"
"({(rank,10),(suit,spades)},1 % 1)"
algn bb
4.502579805228009
Now our model aligns the suit to the rank via colour, so a query on clubs is always a pip card,
rpln $ aall $ norm $ qq `tmul` tt `mul` xx `mul` bb `ared` vk
"({(rank,A)},1 % 10)"
"({(rank,2)},1 % 10)"
"({(rank,3)},1 % 10)"
"({(rank,4)},1 % 10)"
"({(rank,5)},1 % 10)"
"({(rank,6)},1 % 10)"
"({(rank,7)},1 % 10)"
"({(rank,8)},1 % 10)"
"({(rank,9)},1 % 10)"
"({(rank,10)},1 % 10)"
A query on hearts is always a face card,
let qq = unit (Set.singleton (llss [(suit,hearts)]))
rpln $ aall $ norm $ qq `tmul` tt `mul` xx `mul` bb `ared` vk
"({(rank,J)},1 % 3)"
"({(rank,K)},1 % 3)"
"({(rank,Q)},1 % 3)"
Of course, in this example the model is not very interesting because we can simply query the sample directly,
rpln $ aall $ norm $ qq `mul` bb `ared` vk
"({(rank,J)},1 % 3)"
"({(rank,K)},1 % 3)"
"({(rank,Q)},1 % 3)"
Usually models are more useful when the size of the sample is much smaller than the underlying volume, $z \ll v$, where $z = \mathrm{size}(A)$ and $v = |V^{\mathrm{C}}|$, but not the derived volume, $z \ge w$, where $w = |W^{\mathrm{C}}|$. In these cases the sample itself does not contain the query, $\{Q\}^{\mathrm{U}} * A = \emptyset$, but the sample derived does contain the query derived, $\{R\}^{\mathrm{U}} * (A * T) \neq \emptyset$, and so the resultant labels are those of the corresponding effective component, $A * C~\%~(V \setminus K)$, where $(R,C) \in T^{-1}$.
Substrate structures
The set of substrate transforms $\mathcal{T}_{U,V}$ is the subset of one functional transforms, $\mathcal{T}_{U,V} \subset \mathcal{T}_{U,\mathrm{f},1}$, that have underlying variables $V$ and derived variables which are partitions, \[ \begin{eqnarray} \mathcal{T}_{U,V} &=& \{(\prod_{(X,\cdot) \in F} X, \bigcup_{(\cdot,W) \in F} W) : F \subseteq \{P^{\mathrm{T}} : P \in \mathrm{B}(V^{\mathrm{CS}})\}\} \end{eqnarray} \]
systemsSetVarsSetTransformSubstrate :: System -> Set.Set Variable -> Maybe (Set.Set Transform)
systemsSetVarsSetTransformSubstrateCardinality :: System -> Set.Set Variable -> Maybe Integer
For example,
let ttvv uu = fromJust $ systemsSetVarsSetTransformSubstrate uu (uvars uu)
let ttvvcd uu = fromJust $ systemsSetVarsSetTransformSubstrateCardinality uu (uvars uu)
ttvvcd $ sysreg 1 1
2
rpln $ Set.toList $ ttvv $ sysreg 1 1
"({},{})"
"({({(1,1),({ { {(1,1)} } },{ {(1,1)} })},1 % 1)},{ { { {(1,1)} } } })"
ttvvcd $ sysreg 2 1
4
rpln $ Set.toList $ ttvv $ sysreg 2 1
"({},{})"
"({({(1,1),({ { {(1,1)} },{ {(1,2)} } },{ {(1,1)} })},1 % 1),({(1,2),({ { {(1,1)} },{ {(1,2)} } },{ {(1,2)} })},1 % 1)},{ { { {(1,1)} },{ {(1,2)} } } })"
"({({(1,1),({ { {(1,1)} },{ {(1,2)} } },{ {(1,1)} }),({ { {(1,1)},{(1,2)} } },{ {(1,1)},{(1,2)} })},1 % 1),({(1,2),({ { {(1,1)} },{ {(1,2)} } },{ {(1,2)} }),({ { {(1,1)},{(1,2)} } },{ {(1,1)},{(1,2)} })},1 % 1)},{ { { {(1,1)} },{ {(1,2)} } },{ { {(1,1)},{(1,2)} } } })"
"({({(1,1),({ { {(1,1)},{(1,2)} } },{ {(1,1)},{(1,2)} })},1 % 1),({(1,2),({ { {(1,1)},{(1,2)} } },{ {(1,1)},{(1,2)} })},1 % 1)},{ { { {(1,1)},{(1,2)} } } })"
ttvvcd $ sysreg 1 2
2
rpln $ Set.toList $ ttvv $ sysreg 1 2
"({},{})"
"({({(1,1),(2,1),({ { {(1,1),(2,1)} } },{ {(1,1),(2,1)} })},1 % 1)},{ { { {(1,1),(2,1)} } } })"
ttvvcd $ sysreg 2 2
32768
ttvvcd (sysreg 2 3) > 10^1246
True
ttvvcd (sysreg 3 2) > 10^6365
True
Example - a weather forecast
Some of the concepts above regarding transforms can be demonstrated with the sample of some weather measurements created in States, histories and histograms,
let lluu ll = fromJust $ listsSystem [(v,Set.fromList ww) | (v,ww) <- ll]
llhh vv ev = fromJust $ listsHistory [(IdInt i, llss (zip vv ll)) | (i,ll) <- ev]
red aa ll = setVarsHistogramsReduce (Set.fromList ll) aa
ssplit ll aa = Set.toList (setVarsSetStatesSplit (Set.fromList ll) (states aa))
let [pressure,cloud,wind,rain] = map VarStr ["pressure","cloud","wind","rain"]
let [low,medium,high,none,light,heavy,strong] = map ValStr ["low","medium","high","none","light","heavy","strong"]
let uu = lluu [
(pressure, [low,medium,high]),
(cloud, [none,light,heavy]),
(wind, [none,light,strong]),
(rain, [none,light,heavy])]
let vv = uvars uu
let hh = llhh [pressure,cloud,wind,rain] [
(1,[high,none,none,none]),
(2,[medium,light,none,light]),
(3,[high,none,light,none]),
(4,[low,heavy,strong,heavy]),
(5,[low,none,light,light]),
(6,[medium,none,light,light]),
(7,[low,heavy,light,heavy]),
(8,[high,none,light,none]),
(9,[medium,light,strong,heavy]),
(10,[medium,light,light,light]),
(11,[high,light,light,heavy]),
(12,[medium,none,none,none]),
(13,[medium,light,none,none]),
(14,[high,light,strong,light]),
(15,[medium,none,light,light]),
(16,[low,heavy,strong,heavy]),
(17,[low,heavy,light,heavy]),
(18,[high,none,none,none]),
(19,[low,light,none,light]),
(20,[high,none,none,none])]
let aa = hhaa hh
rp uu
"{(cloud,{heavy,light,none}),(pressure,{high,low,medium}),(rain,{heavy,light,none}),(wind,{light,none,strong})}"
rp vv
"{cloud,pressure,rain,wind}"
rpln $ aall aa
"({(cloud,heavy),(pressure,low),(rain,heavy),(wind,light)},2 % 1)"
"({(cloud,heavy),(pressure,low),(rain,heavy),(wind,strong)},2 % 1)"
"({(cloud,light),(pressure,high),(rain,heavy),(wind,light)},1 % 1)"
"({(cloud,light),(pressure,high),(rain,light),(wind,strong)},1 % 1)"
"({(cloud,light),(pressure,low),(rain,light),(wind,none)},1 % 1)"
"({(cloud,light),(pressure,medium),(rain,heavy),(wind,strong)},1 % 1)"
"({(cloud,light),(pressure,medium),(rain,light),(wind,light)},1 % 1)"
"({(cloud,light),(pressure,medium),(rain,light),(wind,none)},1 % 1)"
"({(cloud,light),(pressure,medium),(rain,none),(wind,none)},1 % 1)"
"({(cloud,none),(pressure,high),(rain,none),(wind,light)},2 % 1)"
"({(cloud,none),(pressure,high),(rain,none),(wind,none)},3 % 1)"
"({(cloud,none),(pressure,low),(rain,light),(wind,light)},1 % 1)"
"({(cloud,none),(pressure,medium),(rain,light),(wind,light)},2 % 1)"
"({(cloud,none),(pressure,medium),(rain,none),(wind,none)},1 % 1)"
size aa
20 % 1
Consider the case where we know the pressure
, cloud
and wind
, and wish to predict the rain
.
That is, the singleton set of rain
is set of the label variables, $V \setminus K$, and pressure
, cloud
and wind
together form the query variables, $K$.
In Entropy and alignment the alignments of various reductions were calculated,
algn $ resize 20 $ regdiag 3 4
31.485060248779213
algn aa
11.850852273417695
algn $ aa `red` [pressure,rain]
4.27876667992199
algn $ aa `red` [cloud,rain]
6.415037968300277
algn $ aa `red` [wind,rain]
3.9301313052733455
algn $ aa `red` [cloud,wind,rain]
8.93504831268134
We can see that pressure
and rain
are aligned but not causal,
algn $ aa `red` [pressure,rain]
4.27876667992199
rpln $ ssplit [pressure] (aa `red` [pressure,rain])
"({(pressure,high)},{(rain,heavy)})"
"({(pressure,high)},{(rain,light)})"
"({(pressure,high)},{(rain,none)})"
"({(pressure,low)},{(rain,heavy)})"
"({(pressure,low)},{(rain,light)})"
"({(pressure,medium)},{(rain,heavy)})"
"({(pressure,medium)},{(rain,light)})"
"({(pressure,medium)},{(rain,none)})"
histogramsIsCausal $ aa `red` [pressure,rain]
False
cloud
and rain
are more aligned,
algn $ aa `red` [cloud,rain]
6.415037968300277
rpln $ ssplit [cloud] (aa `red` [cloud,rain])
"({(cloud,heavy)},{(rain,heavy)})"
"({(cloud,light)},{(rain,heavy)})"
"({(cloud,light)},{(rain,light)})"
"({(cloud,light)},{(rain,none)})"
"({(cloud,none)},{(rain,light)})"
"({(cloud,none)},{(rain,none)})"
but cloud
, wind
and rain
are still more aligned,
algn $ aa `red` [cloud,wind,rain]
8.93504831268134
rpln $ ssplit [cloud,wind] (aa `red` [cloud,wind,rain])
"({(cloud,heavy),(wind,light)},{(rain,heavy)})"
"({(cloud,heavy),(wind,strong)},{(rain,heavy)})"
"({(cloud,light),(wind,light)},{(rain,heavy)})"
"({(cloud,light),(wind,light)},{(rain,light)})"
"({(cloud,light),(wind,none)},{(rain,light)})"
"({(cloud,light),(wind,none)},{(rain,none)})"
"({(cloud,light),(wind,strong)},{(rain,heavy)})"
"({(cloud,light),(wind,strong)},{(rain,light)})"
"({(cloud,none),(wind,light)},{(rain,light)})"
"({(cloud,none),(wind,light)},{(rain,none)})"
"({(cloud,none),(wind,none)},{(rain,none)})"
histogramsIsCausal $ aa `red` [cloud,wind,rain]
False
So consider a simple model consisting of a one functional transform $T \in \mathcal{T}_{U,\mathrm{f},1}$ with underlying variables cloud
and wind
and a derived variable of cloud_and_wind
with this relation -
cloud | wind | cloud and wind |
---|---|---|
none | none | none |
none | light | light |
none | strong | light |
light | none | light |
light | light | light |
light | strong | light |
heavy | none | strong |
heavy | light | strong |
heavy | strong | strong |
let cloud_and_wind = VarStr "cloud_and_wind"
let lltt kk ww qq = trans (unit (Set.fromList [llss (zip (kk ++ ww) ll) | ll <- qq])) (Set.fromList ww)
let tt = lltt [cloud,wind] [cloud_and_wind] [
[none, none, none],
[none, light, light],
[none, strong, light],
[light, none, light],
[light, light, light],
[light, strong, light],
[heavy, none, strong],
[heavy, light, strong],
[heavy, strong, strong]]
rpln $ aall $ ttaa tt
"({(cloud,heavy),(cloud_and_wind,strong),(wind,light)},1 % 1)"
"({(cloud,heavy),(cloud_and_wind,strong),(wind,none)},1 % 1)"
"({(cloud,heavy),(cloud_and_wind,strong),(wind,strong)},1 % 1)"
"({(cloud,light),(cloud_and_wind,light),(wind,light)},1 % 1)"
"({(cloud,light),(cloud_and_wind,light),(wind,none)},1 % 1)"
"({(cloud,light),(cloud_and_wind,light),(wind,strong)},1 % 1)"
"({(cloud,none),(cloud_and_wind,light),(wind,light)},1 % 1)"
"({(cloud,none),(cloud_and_wind,light),(wind,strong)},1 % 1)"
"({(cloud,none),(cloud_and_wind,none),(wind,none)},1 % 1)"
rpln $ ssplit [cloud,wind] (ttaa tt)
"({(cloud,heavy),(wind,light)},{(cloud_and_wind,strong)})"
"({(cloud,heavy),(wind,none)},{(cloud_and_wind,strong)})"
"({(cloud,heavy),(wind,strong)},{(cloud_and_wind,strong)})"
"({(cloud,light),(wind,light)},{(cloud_and_wind,light)})"
"({(cloud,light),(wind,none)},{(cloud_and_wind,light)})"
"({(cloud,light),(wind,strong)},{(cloud_and_wind,light)})"
"({(cloud,none),(wind,light)},{(cloud_and_wind,light)})"
"({(cloud,none),(wind,none)},{(cloud_and_wind,none)})"
"({(cloud,none),(wind,strong)},{(cloud_and_wind,light)})"
rp $ und tt
"{cloud,wind}"
rp $ der tt
"{cloud_and_wind}"
histogramsIsCausal (ttaa tt)
True
rpln $ aall $ aa `tmul` tt
"({(cloud_and_wind,light)},12 % 1)"
"({(cloud_and_wind,none)},4 % 1)"
"({(cloud_and_wind,strong)},4 % 1)"
Now we calculate the alignment between the derived variable, cloud_and_wind
, and the rain
,
algn $ aa `mul` ttaa tt `red` [cloud_and_wind,rain]
6.743705970350529
rpln $ ssplit [cloud_and_wind] (aa `mul` ttaa tt `red` [cloud_and_wind,rain])
"({(cloud_and_wind,light)},{(rain,heavy)})"
"({(cloud_and_wind,light)},{(rain,light)})"
"({(cloud_and_wind,light)},{(rain,none)})"
"({(cloud_and_wind,none)},{(rain,none)})"
"({(cloud_and_wind,strong)},{(rain,heavy)})"
So cloud_and_wind
is more aligned with rain
than any of cloud
, wind
or pressure
.
Now consider a query which is ineffective in the sample, $Q \notin (A\%K)^{\mathrm{FS}}$, but is effective in the sample derived, $R \in (A * T)^{\mathrm{FS}}$ where $\{R\} = (\{Q\}^{\mathrm{U}} * T)^{\mathrm{FS}}$,
let qq = hhaa $ llhh [pressure,cloud,wind] [(1,[medium,heavy,light])]
qq `leq` eff (aa `red` [pressure,cloud,wind])
False
rpln $ aall $ qq `tmul` tt
"({(cloud_and_wind,strong)},1 % 1)"
let rr = hhaa $ llhh [cloud_and_wind] [(1,[strong])]
rr `leq` eff (aa `tmul` tt)
True
The forecast for rain
is heavy
,
let aarr aa = map (\(ss,c) -> (ss,fromRational c)) (histogramsList aa) :: [(State,Double)]
let query qq tt aa ll = norm (qq `tmul` tt `mul` ttaa tt `mul` aa `red` ll)
rpln $ aarr $ query qq tt aa [rain]
"({(rain,heavy)},1.0)"
We can calculate the resultant label histogram for all $3^3 = 27$ queries,
let kk = Set.fromList [pressure,cloud,wind]
rpln [(ss, query qq tt aa [rain]) | ss <- Set.toList (cart uu kk), let qq = unit (Set.singleton ss)]
"({(cloud,heavy),(pressure,high),(wind,light)},{({(rain,heavy)},1 % 1)})"
"({(cloud,heavy),(pressure,high),(wind,none)},{({(rain,heavy)},1 % 1)})"
"({(cloud,heavy),(pressure,high),(wind,strong)},{({(rain,heavy)},1 % 1)})"
"({(cloud,heavy),(pressure,low),(wind,light)},{({(rain,heavy)},1 % 1)})"
"({(cloud,heavy),(pressure,low),(wind,none)},{({(rain,heavy)},1 % 1)})"
"({(cloud,heavy),(pressure,low),(wind,strong)},{({(rain,heavy)},1 % 1)})"
"({(cloud,heavy),(pressure,medium),(wind,light)},{({(rain,heavy)},1 % 1)})"
"({(cloud,heavy),(pressure,medium),(wind,none)},{({(rain,heavy)},1 % 1)})"
"({(cloud,heavy),(pressure,medium),(wind,strong)},{({(rain,heavy)},1 % 1)})"
"({(cloud,light),(pressure,high),(wind,light)},{({(rain,heavy)},1 % 6),({(rain,light)},7 % 12),({(rain,none)},1 % 4)})"
"({(cloud,light),(pressure,high),(wind,none)},{({(rain,heavy)},1 % 6),({(rain,light)},7 % 12),({(rain,none)},1 % 4)})"
"({(cloud,light),(pressure,high),(wind,strong)},{({(rain,heavy)},1 % 6),({(rain,light)},7 % 12),({(rain,none)},1 % 4)})"
"({(cloud,light),(pressure,low),(wind,light)},{({(rain,heavy)},1 % 6),({(rain,light)},7 % 12),({(rain,none)},1 % 4)})"
"({(cloud,light),(pressure,low),(wind,none)},{({(rain,heavy)},1 % 6),({(rain,light)},7 % 12),({(rain,none)},1 % 4)})"
"({(cloud,light),(pressure,low),(wind,strong)},{({(rain,heavy)},1 % 6),({(rain,light)},7 % 12),({(rain,none)},1 % 4)})"
"({(cloud,light),(pressure,medium),(wind,light)},{({(rain,heavy)},1 % 6),({(rain,light)},7 % 12),({(rain,none)},1 % 4)})"
"({(cloud,light),(pressure,medium),(wind,none)},{({(rain,heavy)},1 % 6),({(rain,light)},7 % 12),({(rain,none)},1 % 4)})"
"({(cloud,light),(pressure,medium),(wind,strong)},{({(rain,heavy)},1 % 6),({(rain,light)},7 % 12),({(rain,none)},1 % 4)})"
"({(cloud,none),(pressure,high),(wind,light)},{({(rain,heavy)},1 % 6),({(rain,light)},7 % 12),({(rain,none)},1 % 4)})"
"({(cloud,none),(pressure,high),(wind,none)},{({(rain,none)},1 % 1)})"
"({(cloud,none),(pressure,high),(wind,strong)},{({(rain,heavy)},1 % 6),({(rain,light)},7 % 12),({(rain,none)},1 % 4)})"
"({(cloud,none),(pressure,low),(wind,light)},{({(rain,heavy)},1 % 6),({(rain,light)},7 % 12),({(rain,none)},1 % 4)})"
"({(cloud,none),(pressure,low),(wind,none)},{({(rain,none)},1 % 1)})"
"({(cloud,none),(pressure,low),(wind,strong)},{({(rain,heavy)},1 % 6),({(rain,light)},7 % 12),({(rain,none)},1 % 4)})"
"({(cloud,none),(pressure,medium),(wind,light)},{({(rain,heavy)},1 % 6),({(rain,light)},7 % 12),({(rain,none)},1 % 4)})"
"({(cloud,none),(pressure,medium),(wind,none)},{({(rain,none)},1 % 1)})"
"({(cloud,none),(pressure,medium),(wind,strong)},{({(rain,heavy)},1 % 6),({(rain,light)},7 % 12),({(rain,none)},1 % 4)})"
For some queries the model is ambiguous. For example, when the pressure is low, but there is no cloud and winds are light, the forecast is usually for light rain, but not always,
let qq2 = hhaa $ llhh [pressure,cloud,wind] [(1,[low,none,light])]
rpln $ aarr $ query qq2 tt aa [rain]
"({(rain,heavy)},0.16666666666666666)"
"({(rain,light)},0.5833333333333334)"
"({(rain,none)},0.25)"
Although this manually created model, $T$, is a one functional transform, $\mathcal{T}_{U,\mathrm{f},1}$, rather than a substrate transform, $\mathcal{T}_{U,V}$, there is a substrate transform that corresponds to it,
partitionsTransformVarPartition :: Partition -> Transform
transformsSetPartition :: Transform -> SetPartition
For example,
let pptt = partitionsTransformVarPartition
ttpp = Set.findMax . transformsSetPartition
pll (VarPartition pp) = Set.toList (partitionsSetComponent pp)
let tt' = pptt (ttpp tt)
rpln $ pll $ Set.findMax $ der tt'
"{ {(cloud,heavy),(wind,light)},{(cloud,heavy),(wind,none)},{(cloud,heavy),(wind,strong)} }"
"{ {(cloud,light),(wind,light)},{(cloud,light),(wind,none)},{(cloud,light),(wind,strong)},{(cloud,none),(wind,light)},{(cloud,none),(wind,strong)} }"
"{ {(cloud,none),(wind,none)} }"
The weather forecast example continues in Transform entropy.