我想实现条件期望运算符。我将使用资本epsilon E
来表示运营商。我期望至少下列输入(下划线表示下标)Mathematica中的符号条件期望
E_2[a]
E_2[x_1]
E_2[x_1 + y_5]
E_1[3 a + b - 4 + 2 x_]
E_6[x_5 x_7]
E_t[x_t]
E_t[3 x_{t - 1} x_{t + 2}]
以产生以下输出上述
a
x_1
E_2[y_5] + x_1
-4 + 3 a + b + 2 E_2[x_5]
E_6[x_7] x_5
x_t
3 E_t[x_{t + 2}] x_{t - 1}
这些实施例不应我需要产生唯一的输入/输出对,而是服务作为我喜欢的语法的测试和说明。
我有这么多。 ce
表示条件期望,其第三个组成部分是“期望传播”是否已完成(否则无限递归发生在产品规则中),mv
代表可测量变量。
Notation[Subscript[E, t_][y_] ==> ce[y_, t_, False]];
Notation[Subscript[E, t_][y_] <== ce[y_, t_, _]];
Notation[Subscript[x_, t_] <==> mv[x_, t_]];
(* Atomic Elements and Measurable Variables *)
ce[x_, t_, _] := x /; (AtomQ[x] || Head[x] === mv && 0 <= t - x[[2]]);
(* Distribution over Addition *)
ce[x_ + y__, t_, s_] := ce[x, t, s] + Plus @@ (ce[#, t, s] & /@ {y});
(* Distribution over Product *)
ce[x__Times, t_, False] := Module[{v, m, n},
(* All Variables in the Product *)
v = List @@ x;
(* Measurable Among Them *)
m = Select[v, AtomQ[#] || Head[#] === mv && 0 <= t - #[[2]] &];
(* The Rest is not Measurable *)
n = Complement[v, m];
Times[Times @@ m, ce[Times @@ n, t, True]]
];
我不认为这一切都会很有意义。如果你想让函数定义给出上面的输出给出上面的输入,你可以将第一个框设置为第二个。 'Subscript [E,0] [a] = a','Subscript [E,0] [Subscript [x,0]] = Subscript [x,0]'等等,你的例子可以工作,但它不会概括。 PS E是保留字(自然对数的基础)。 – 2011-03-23 16:50:13
下划线用于模式匹配......不要在符号名称 – 2011-03-23 17:50:57
@belisarius中使用它,但是他确实提到他将它用作'Subscript'的缩写。 – rcollyer 2011-03-23 18:01:48