利用数量构建导出分布
用 TransformedDistribution 来指定值为数量的 (quantity-valued) 函数的分布.
In[1]:=
speed = \!\(\*
NamespaceBox["LinguisticAssistant",
DynamicModuleBox[{Typeset`query$$ = "speed of sound in air",
Typeset`boxes$$ = TemplateBox[{
InterpretationBox[" ", 1],
"\"speeds of sound in dry air at 20 \[Degree]C and 1 \
atmosphere pressure\"",
"speeds of sound in dry air at 20 \[Degree]C and 1 atmosphere \
pressure", "\"SpeedOfSound\""}, "Quantity", SyntaxForm -> Mod],
Typeset`allassumptions$$ = {{
"type" -> "MultiClash", "word" -> "",
"template" -> "Assuming ${word1} is referring to ${desc1}. \
Use as ${desc2} instead. Use \"${word3}\" as ${desc3}. Use \"${word4}\
\" as ${desc4}.", "count" -> "4",
"Values" -> {{
"name" -> "Unit", "word" -> "the input", "desc" -> "a unit",
"input" -> "*MC.%7E-_*Unit-"}, {
"name" -> "Formula", "word" -> "the input",
"desc" -> "a formula", "input" -> "*MC.%7E-_*Formula-"}, {
"name" -> "Thermodynamic", "word" -> "air",
"desc" -> "a thermodynamic material",
"input" -> "*MC.%7E-_*Thermodynamic-"}, {
"name" -> "Chemical", "word" -> "air",
"desc" -> "a chemical compound",
"input" -> "*MC.%7E-_*Chemical-"}}}},
Typeset`assumptions$$ = {}, Typeset`open$$ = {1, 2},
Typeset`querystate$$ = {
"Online" -> True, "Allowed" -> True,
"mparse.jsp" -> 0.8160297`7.363250959003981,
"Messages" -> {}}},
DynamicBox[ToBoxes[
AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic,
Dynamic[Typeset`query$$],
Dynamic[Typeset`boxes$$],
Dynamic[Typeset`allassumptions$$],
Dynamic[Typeset`assumptions$$],
Dynamic[Typeset`open$$],
Dynamic[Typeset`querystate$$]], StandardForm],
ImageSizeCache->{398., {30., 18.}},
TrackedSymbols:>{
Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$,
Typeset`assumptions$$, Typeset`open$$, Typeset`querystate$$}],
DynamicModuleValues:>{},
UndoTrackedVariables:>{Typeset`open$$}],
BaseStyle->{"Deploy"},
DeleteWithContents->True,
Editable->False,
SelectWithContents->True]\);
In[2]:=
distance\[ScriptCapitalD] =
TransformedDistribution[speed*Quantity[t, "Seconds"],
t \[Distributed] UniformDistribution[{2, 4}]]
Out[2]=
把分布的单位转换成公里.
In[3]:=
UnitConvert[distance\[ScriptCapitalD], "Kilometers"]
Out[3]=
用 TransformedDistribution 把随机变量和数量组合在一起.
In[4]:=
TransformedDistribution[
Subscript[x, 0] +
v*t, {Subscript[x, 0] \[Distributed] NormalDistribution[\!\(\*
NamespaceBox["LinguisticAssistant",
DynamicModuleBox[{Typeset`query$$ = "2 m", Typeset`boxes$$ =
TemplateBox[{"2", "\"m\"", "meters", "\"Meters\""},
"Quantity", SyntaxForm -> Mod],
Typeset`allassumptions$$ = {{
"type" -> "Clash", "word" -> "m",
"template" -> "Assuming \"${word}\" is ${desc1}. Use as \
${desc2} instead", "count" -> "2",
"Values" -> {{
"name" -> "Unit", "desc" -> "a unit",
"input" -> "*C.m-_*Unit-"}, {
"name" -> "Variable", "desc" -> "a variable",
"input" -> "*C.m-_*Variable-"}}}, {
"type" -> "Unit", "word" -> "m",
"template" -> "Assuming ${desc1} for \"${word}\". Use \
${desc2} instead", "count" -> "3",
"Values" -> {{
"name" -> "Meters", "desc" -> "meters",
"input" -> "UnitClash_*m.*Meters--"}, {
"name" -> "MinimsUS", "desc" -> "US minims of volume",
"input" -> "UnitClash_*m.*MinimsUS--"}, {
"name" -> "Minutes", "desc" -> "minutes of time",
"input" -> "UnitClash_*m.*Minutes--"}}}},
Typeset`assumptions$$ = {}, Typeset`open$$ = {1, 2},
Typeset`querystate$$ = {
"Online" -> True, "Allowed" -> True,
"mparse.jsp" -> 1.4079785`7.600141016624048,
"Messages" -> {}}},
DynamicBox[ToBoxes[
AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic,
Dynamic[Typeset`query$$],
Dynamic[Typeset`boxes$$],
Dynamic[Typeset`allassumptions$$],
Dynamic[Typeset`assumptions$$],
Dynamic[Typeset`open$$],
Dynamic[Typeset`querystate$$]], StandardForm],
ImageSizeCache->{86., {8., 16.}},
TrackedSymbols:>{
Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$,
Typeset`assumptions$$, Typeset`open$$,
Typeset`querystate$$}],
DynamicModuleValues:>{},
UndoTrackedVariables:>{Typeset`open$$}],
BaseStyle->{"Deploy"},
DeleteWithContents->True,
Editable->False,
SelectWithContents->True]\), \!\(\*
NamespaceBox["LinguisticAssistant",
DynamicModuleBox[{Typeset`query$$ = "2 cm", Typeset`boxes$$ =
TemplateBox[{"2", "\"cm\"", "centimeters", "\"Centimeters\""},
"Quantity", SyntaxForm -> Mod],
Typeset`allassumptions$$ = {}, Typeset`assumptions$$ = {},
Typeset`open$$ = {1, 2}, Typeset`querystate$$ = {
"Online" -> True, "Allowed" -> True,
"mparse.jsp" -> 3.2360033`7.961553949319721,
"Messages" -> {}}},
DynamicBox[ToBoxes[
AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic,
Dynamic[Typeset`query$$],
Dynamic[Typeset`boxes$$],
Dynamic[Typeset`allassumptions$$],
Dynamic[Typeset`assumptions$$],
Dynamic[Typeset`open$$],
Dynamic[Typeset`querystate$$]], StandardForm],
ImageSizeCache->{70., {8., 16.}},
TrackedSymbols:>{
Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$,
Typeset`assumptions$$, Typeset`open$$,
Typeset`querystate$$}],
DynamicModuleValues:>{},
UndoTrackedVariables:>{Typeset`open$$}],
BaseStyle->{"Deploy"},
DeleteWithContents->True,
Editable->False,
SelectWithContents->True]\)],
v \[Distributed] RayleighDistribution[\!\(\*
NamespaceBox["LinguisticAssistant",
DynamicModuleBox[{Typeset`query$$ = "5 kmph", Typeset`boxes$$ =
TemplateBox[{"5",
RowBox[{"\"km\"", " ", "\"/\"", " ", "\"h\""}], "kilometers per hour",
FractionBox["\"Kilometers\"", "\"Hours\""]}, "Quantity",
SyntaxForm -> Mod], Typeset`allassumptions$$ = {},
Typeset`assumptions$$ = {}, Typeset`open$$ = {1, 2},
Typeset`querystate$$ = {
"Online" -> True, "Allowed" -> True,
"mparse.jsp" -> 0.3549929`7.00176466057457,
"Messages" -> {}}},
DynamicBox[ToBoxes[
AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic,
Dynamic[Typeset`query$$],
Dynamic[Typeset`boxes$$],
Dynamic[Typeset`allassumptions$$],
Dynamic[Typeset`assumptions$$],
Dynamic[Typeset`open$$],
Dynamic[Typeset`querystate$$]], StandardForm],
ImageSizeCache->{86., {8., 16.}},
TrackedSymbols:>{
Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$,
Typeset`assumptions$$, Typeset`open$$,
Typeset`querystate$$}],
DynamicModuleValues:>{},
UndoTrackedVariables:>{Typeset`open$$}],
BaseStyle->{"Deploy"},
DeleteWithContents->True,
Editable->False,
SelectWithContents->True]\)],
t \[Distributed] GammaDistribution[3, \!\(\*
NamespaceBox["LinguisticAssistant",
DynamicModuleBox[{Typeset`query$$ = "5 min", Typeset`boxes$$ =
TemplateBox[{"5", "\"min\"", "minutes", "\"Minutes\""},
"Quantity", SyntaxForm -> Mod],
Typeset`allassumptions$$ = {{
"type" -> "Clash", "word" -> "min",
"template" -> "Assuming \"${word}\" is ${desc1}. Use as \
${desc2} instead", "count" -> "3",
"Values" -> {{
"name" -> "Unit", "desc" -> "a unit",
"input" -> "*C.min-_*Unit-"}, {
"name" -> "OptimizationWord",
"desc" -> " referring to optimization",
"input" -> "*C.min-_*OptimizationWord-"}, {
"name" -> "HistoricalCountry",
"desc" -> "a historical country",
"input" -> "*C.min-_*HistoricalCountry-"}}}, {
"type" -> "Unit", "word" -> "min",
"template" -> "Assuming ${desc1} for \"${word}\". Use \
${desc2} instead", "count" -> "3",
"Values" -> {{
"name" -> "Minutes", "desc" -> "minutes of time",
"input" -> "UnitClash_*min.*Minutes--"}, {
"name" -> "MinimsUS", "desc" -> "US minims of volume",
"input" -> "UnitClash_*min.*MinimsUS--"}, {
"name" -> "ArcMinutes", "desc" -> "minutes of arc",
"input" -> "UnitClash_*min.*ArcMinutes--"}}}},
Typeset`assumptions$$ = {}, Typeset`open$$ = {1, 2},
Typeset`querystate$$ = {
"Online" -> True, "Allowed" -> True,
"mparse.jsp" -> 0.4070055`7.0611452715258896,
"Messages" -> {}}},
DynamicBox[ToBoxes[
AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic,
Dynamic[Typeset`query$$],
Dynamic[Typeset`boxes$$],
Dynamic[Typeset`allassumptions$$],
Dynamic[Typeset`assumptions$$],
Dynamic[Typeset`open$$],
Dynamic[Typeset`querystate$$]], StandardForm],
ImageSizeCache->{101., {8., 16.}},
TrackedSymbols:>{
Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$,
Typeset`assumptions$$, Typeset`open$$,
Typeset`querystate$$}],
DynamicModuleValues:>{},
UndoTrackedVariables:>{Typeset`open$$}],
BaseStyle->{"Deploy"},
DeleteWithContents->True,
Editable->False,
SelectWithContents->True]\)]}]
Out[4]=
用 TransformedDistribution 组合随机变量的数值.
In[5]:=
TransformedDistribution[QuantityMagnitude[t, "Celsius"],
t \[Distributed]
NormalDistribution[Quantity[293.15, "Kelvins"],
Quantity[5.2, "Kelvins"]]]
Out[5]=
也可以定义 Quantity[x, unit] 的分布来表明 x 指的是给定单位 unit 时随机变量的数值.
In[6]:=
TransformedDistribution[t,
Quantity[t, "Celsius"] \[Distributed]
NormalDistribution[Quantity[293.15, "Kelvins"],
Quantity[5.2, "Kelvins"]]]
Out[6]=
比如,以华氏度为单位,表达北美风寒指数的分布,假定芝加哥冬天的气温和风速服从某些分布.
In[7]:=
wcTemp\[ScriptCapitalD] =
TransformedDistribution[
35.74 + 0.6215 QuantityMagnitude[Ta,
"DegreesFahrenheit"] + (0.4275 QuantityMagnitude[Ta,
"DegreesFahrenheit"] - 35.75) QuantityMagnitude[V,
"Miles"/"Hours"]^+0.16, {V \[Distributed]
WeibullDistribution[2.81, \!\(\*
NamespaceBox["LinguisticAssistant",
DynamicModuleBox[{Typeset`query$$ = "4.846 m/s", Typeset`boxes$$ =
TemplateBox[{"4.846",
RowBox[{"\"m\"", " ", "\"/\"", " ", "\"s\""}], "meters per second",
FractionBox["\"Meters\"", "\"Seconds\""]}, "Quantity",
SyntaxForm -> Mod],
Typeset`allassumptions$$ = {{
"type" -> "MultiClash", "word" -> "",
"template" -> "Assuming ${word1} is referring to ${desc1}. \
Use \"${word2}\" as ${desc2}.", "count" -> "2",
"Values" -> {{
"name" -> "Unit", "word" -> "m/s", "desc" -> "a unit",
"input" -> "*MC.m%2Fs-_*Unit-"}, {
"name" -> "Variable", "word" -> "m",
"desc" -> "a variable",
"input" -> "*MC.m%2Fs-_*Variable-"}}}, {
"type" -> "Unit", "word" -> "m/s",
"template" -> "Assuming ${desc1} for \"${word}\". Use \
${desc2} instead", "count" -> "2",
"Values" -> {{
"name" -> "MetersPerSecond",
"desc" -> "meters per second",
"input" -> "UnitClash_*m%2Fs.*MetersPerSecond--"}, {
"name" -> "MinutesPerSecond",
"desc" -> "minutes per second",
"input" -> "UnitClash_*m%2Fs.*MinutesPerSecond--"}}}},
Typeset`assumptions$$ = {}, Typeset`open$$ = {1, 2},
Typeset`querystate$$ = {
"Online" -> True, "Allowed" -> True,
"mparse.jsp" -> 0.5190047`7.166716284243896,
"Messages" -> {}}},
DynamicBox[ToBoxes[
AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic,
Dynamic[Typeset`query$$],
Dynamic[Typeset`boxes$$],
Dynamic[Typeset`allassumptions$$],
Dynamic[Typeset`assumptions$$],
Dynamic[Typeset`open$$],
Dynamic[Typeset`querystate$$]], StandardForm],
ImageSizeCache->{133., {8., 16.}},
TrackedSymbols:>{
Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$,
Typeset`assumptions$$, Typeset`open$$,
Typeset`querystate$$}],
DynamicModuleValues:>{},
UndoTrackedVariables:>{Typeset`open$$}],
BaseStyle->{"Deploy"},
DeleteWithContents->True,
Editable->False,
SelectWithContents->True]\)],
Ta \[Distributed] TriangularDistribution[{\!\(\*
NamespaceBox["LinguisticAssistant",
DynamicModuleBox[{Typeset`query$$ = "20 Fah", Typeset`boxes$$ =
TemplateBox[{
"20", "\"\[Degree]F\"", "degrees Fahrenheit",
"\"DegreesFahrenheit\""}, "Quantity", SyntaxForm -> Mod],
Typeset`allassumptions$$ = {}, Typeset`assumptions$$ = {},
Typeset`open$$ = {1, 2}, Typeset`querystate$$ = {
"Online" -> True, "Allowed" -> True,
"mparse.jsp" -> 0.5190113`7.166721806978768,
"Messages" -> {}}},
DynamicBox[ToBoxes[
AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic,
Dynamic[Typeset`query$$],
Dynamic[Typeset`boxes$$],
Dynamic[Typeset`allassumptions$$],
Dynamic[Typeset`assumptions$$],
Dynamic[Typeset`open$$],
Dynamic[Typeset`querystate$$]], StandardForm],
ImageSizeCache->{78., {8., 16.}},
TrackedSymbols:>{
Typeset`query$$, Typeset`boxes$$,
Typeset`allassumptions$$, Typeset`assumptions$$,
Typeset`open$$, Typeset`querystate$$}],
DynamicModuleValues:>{},
UndoTrackedVariables:>{Typeset`open$$}],
BaseStyle->{"Deploy"},
DeleteWithContents->True,
Editable->False,
SelectWithContents->True]\), \!\(\*
NamespaceBox["LinguisticAssistant",
DynamicModuleBox[{Typeset`query$$ = "48 Fah", Typeset`boxes$$ =
TemplateBox[{
"48", "\"\[Degree]F\"", "degrees Fahrenheit",
"\"DegreesFahrenheit\""}, "Quantity", SyntaxForm -> Mod],
Typeset`allassumptions$$ = {}, Typeset`assumptions$$ = {},
Typeset`open$$ = {1, 2}, Typeset`querystate$$ = {
"Online" -> True, "Allowed" -> True,
"mparse.jsp" -> 1.3720224`7.588906195330978,
"Messages" -> {}}},
DynamicBox[ToBoxes[
AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic,
Dynamic[Typeset`query$$],
Dynamic[Typeset`boxes$$],
Dynamic[Typeset`allassumptions$$],
Dynamic[Typeset`assumptions$$],
Dynamic[Typeset`open$$],
Dynamic[Typeset`querystate$$]], StandardForm],
ImageSizeCache->{78., {8., 16.}},
TrackedSymbols:>{
Typeset`query$$, Typeset`boxes$$,
Typeset`allassumptions$$, Typeset`assumptions$$,
Typeset`open$$, Typeset`querystate$$}],
DynamicModuleValues:>{},
UndoTrackedVariables:>{Typeset`open$$}],
BaseStyle->{"Deploy"},
DeleteWithContents->True,
Editable->False,
SelectWithContents->True]\)}, \!\(\*
NamespaceBox["LinguisticAssistant",
DynamicModuleBox[{Typeset`query$$ = "30 Fah", Typeset`boxes$$ =
TemplateBox[{
"30", "\"\[Degree]F\"", "degrees Fahrenheit",
"\"DegreesFahrenheit\""}, "Quantity", SyntaxForm -> Mod],
Typeset`allassumptions$$ = {}, Typeset`assumptions$$ = {},
Typeset`open$$ = {1, 2}, Typeset`querystate$$ = {
"Online" -> True, "Allowed" -> True,
"mparse.jsp" -> 0.2719958`6.8861071914606615,
"Messages" -> {}}},
DynamicBox[ToBoxes[
AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic,
Dynamic[Typeset`query$$],
Dynamic[Typeset`boxes$$],
Dynamic[Typeset`allassumptions$$],
Dynamic[Typeset`assumptions$$],
Dynamic[Typeset`open$$],
Dynamic[Typeset`querystate$$]], StandardForm],
ImageSizeCache->{78., {8., 16.}},
TrackedSymbols:>{
Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$,
Typeset`assumptions$$, Typeset`open$$,
Typeset`querystate$$}],
DynamicModuleValues:>{},
UndoTrackedVariables:>{Typeset`open$$}],
BaseStyle->{"Deploy"},
DeleteWithContents->True,
Editable->False,
SelectWithContents->True]\)]}]
Out[7]=
根据人群抽样结果绘制风寒指数的平滑核密度估计.
显示完整的 Wolfram 语言输入
Out[8]=