In the following code how can I keep the DynamicModule from computing values if the input values are not all filled? If I don't specify default values it will show the code used to compute the values instead of blank values.
Thanks.
backingAgreementValue[w_, σ_,
a_] := σ /Sqrt[2 π] Exp[ -(w - a)^2/(2 σ^2)] +
w CDF[NormalDistribution[0, 1], (w - a)/σ]
DynamicModule[{w = 40, σ = 600, a = 0, n = 100, horseCut = 0.5,
backingValue, expectation, backerValue, horseValue,
horseExpectationPercentage, values},
Deploy[Style[
Panel[Grid[
Transpose[{{Style["Mean", Blue],
Style["Standard Deviation", Blue], Style["Threshold", Blue],
Style["N", Blue], Style["Player Cut", Blue],
Style["Backing Agreement Value", Orange],
Style["Expectation", Orange], Style["Player Value", Orange],
Style["Player Expectation Percentage", Orange],
Style["Backer Value", Darker[Magenta]]}, {InputField[
Dynamic[w], Number], InputField[Dynamic[σ], Number],
InputField[Dynamic[a], Number],
InputField[Dynamic[n], Number],
InputField[Dynamic[horseCut], Number],
Dynamic[
Style[backingValue =
backingAgreementValue[expectation, σ Sqrt[n], a] //
N, If[backingValue >= 0, Darker[Green], Red]]],
Dynamic[
Style[expectation = w n // N,
If[expectation >= 0, Darker[Green], Red]]],
Dynamic[
Style[horseValue = horseCut backingValue // N,
If[horseValue >= 0, Darker[Green], Red]]],
Dynamic[
Style[horseExpectationPercentage =
horseCut backingValue/expectation // N,
If[horseExpectationPercentage >= 0.5, Darker[Green], Red]]],
Dynamic[
Style[backerValue = (expectation -
backingValue + (1 - horseCut) backingValue) // N,
If[backerValue >= 0, Darker[Green], Red]]]}}],
Alignment -> Left], ImageMargins -> 10],
DefaultOptions -> {InputField -> {ContinuousAction -> True,
FieldSize -> {{5, 30}, {1, Infinity}}}}]],
SaveDefinitions -> True]
Answer
Wrap a test around the visible code. If the test passes then display the calculation otherwise display a e.g. spacer:
If[NumberQ[σ]&&NumberQ[n]& ...etc,
Dynamic[Style[
backingValue =
backingAgreementValue[expectation, σ Sqrt[n], a] // N,
If[backingValue >= 0, Darker[Green], Red]]],
Spacer[0]
]
Comments
Post a Comment