Initial valueCluster setup
This commit is contained in:
parent
294965a19a
commit
d034e2a96f
|
@ -13,6 +13,39 @@ let makeHelpers = (combo): formState => {
|
||||||
{combo, setCombo, setInputValue};
|
{combo, setCombo, setInputValue};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let propValue = (t: Prop.Value.t) => {
|
||||||
|
switch (t) {
|
||||||
|
| SelectSingle(r) => r |> ReasonReact.string
|
||||||
|
| ConditionalArray(r) => "Array" |> ReasonReact.string
|
||||||
|
| GenericDistribution(r) =>
|
||||||
|
let newDistribution =
|
||||||
|
GenericDistribution.renderIfNeeded(~sampleCount=1000, r);
|
||||||
|
switch (newDistribution) {
|
||||||
|
| Some({
|
||||||
|
generationSource:
|
||||||
|
Shape(
|
||||||
|
Mixed({
|
||||||
|
continuous: n,
|
||||||
|
discrete: d,
|
||||||
|
discreteProbabilityMassFraction: f,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
}) =>
|
||||||
|
<div>
|
||||||
|
<Chart height=100 data={n |> Shape.Continuous.toJs} />
|
||||||
|
{d |> Shape.Discrete.scaleYToTotal(f) |> Shape.Discrete.render}
|
||||||
|
</div>
|
||||||
|
| None => "Something went wrong" |> ReasonReact.string
|
||||||
|
| _ => <div />
|
||||||
|
};
|
||||||
|
| FloatCdf(_) => <div />
|
||||||
|
| Probability(r) =>
|
||||||
|
(r *. 100. |> Js.Float.toFixed) ++ "%" |> ReasonReact.string
|
||||||
|
| DateTime(r) => r |> MomentRe.Moment.defaultFormat |> ReasonReact.string
|
||||||
|
| FloatPoint(r) => r |> Js.Float.toFixed |> ReasonReact.string
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
module ModelForm = {
|
module ModelForm = {
|
||||||
let handleChange = (handleChange, event) =>
|
let handleChange = (handleChange, event) =>
|
||||||
handleChange(ReactEvent.Form.target(event)##value);
|
handleChange(ReactEvent.Form.target(event)##value);
|
||||||
|
@ -51,7 +84,7 @@ module ModelForm = {
|
||||||
)
|
)
|
||||||
|> ReasonReact.array}
|
|> ReasonReact.array}
|
||||||
<div className="bg-green-100 p-2 rounded-sm mt-6 text-lg">
|
<div className="bg-green-100 p-2 rounded-sm mt-6 text-lg">
|
||||||
{model.run(formState.combo) |> E.O.React.fmapOrNull(Value.display)}
|
{model.run(formState.combo) |> E.O.React.fmapOrNull(propValue)}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>;
|
</div>;
|
||||||
|
|
|
@ -1,84 +1,88 @@
|
||||||
module Value = {
|
module Value = {
|
||||||
type binaryConditional =
|
|
||||||
| Selected(bool)
|
|
||||||
| Unselected;
|
|
||||||
|
|
||||||
type conditional = {
|
type conditional = {
|
||||||
name: string,
|
name: string,
|
||||||
truthValue: bool,
|
truthValue: bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
type t =
|
type t =
|
||||||
| BinaryConditional(binaryConditional)
|
|
||||||
| SelectSingle(string)
|
| SelectSingle(string)
|
||||||
| DateTime(MomentRe.Moment.t)
|
| DateTime(MomentRe.Moment.t)
|
||||||
| FloatPoint(float)
|
| FloatPoint(float)
|
||||||
| Probability(float)
|
| Probability(float)
|
||||||
| Conditional(conditional)
|
|
||||||
| GenericDistribution(DistributionTypes.genericDistribution)
|
| GenericDistribution(DistributionTypes.genericDistribution)
|
||||||
| ConditionalArray(array(conditional))
|
| ConditionalArray(array(conditional))
|
||||||
| FloatCdf(string);
|
| FloatCdf(string);
|
||||||
|
|
||||||
let to_string = (t: t) => {
|
|
||||||
switch (t) {
|
|
||||||
| BinaryConditional(binaryConditional) =>
|
|
||||||
switch (binaryConditional) {
|
|
||||||
| Selected(r) => r ? "True" : "False"
|
|
||||||
| Unselected => ""
|
|
||||||
}
|
|
||||||
| SelectSingle(r) => r
|
|
||||||
| FloatCdf(r) => r
|
|
||||||
| GenericDistribution(_) => ""
|
|
||||||
| Probability(r) => (r *. 100. |> Js.Float.toFixed) ++ "%"
|
|
||||||
| DateTime(r) => r |> MomentRe.Moment.defaultFormat
|
|
||||||
| FloatPoint(r) => r |> Js.Float.toFixed
|
|
||||||
| Conditional(r) => r.name
|
|
||||||
| ConditionalArray(r) =>
|
|
||||||
r |> E.A.fmap(r => r.name) |> Js.Array.joinWith(",")
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let display = (t: t) => {
|
module ValueCombination = {
|
||||||
switch (t) {
|
type pointsToEvenlySample = int;
|
||||||
| BinaryConditional(binaryConditional) =>
|
|
||||||
(
|
type dateTimeRange = {
|
||||||
switch (binaryConditional) {
|
startTime: MomentRe.Moment.t,
|
||||||
| Selected(r) => r ? "True" : "False"
|
endTime: MomentRe.Moment.t,
|
||||||
| Unselected => ""
|
pointsWithin: int,
|
||||||
}
|
};
|
||||||
|
|
||||||
|
type floatPointRange = {
|
||||||
|
startTime: float,
|
||||||
|
endTime: float,
|
||||||
|
pointsWithin: int,
|
||||||
|
};
|
||||||
|
|
||||||
|
type range('a) = {
|
||||||
|
beginning: 'a,
|
||||||
|
ending: 'a,
|
||||||
|
pointsToEvenlySample,
|
||||||
|
};
|
||||||
|
|
||||||
|
type t =
|
||||||
|
| SelectSingle
|
||||||
|
| DateTime(range(MomentRe.Moment.t))
|
||||||
|
| FloatPoint(range(MomentRe.Moment.t))
|
||||||
|
| Probability(pointsToEvenlySample);
|
||||||
|
};
|
||||||
|
|
||||||
|
module ValueCluster = {
|
||||||
|
type conditional = {
|
||||||
|
name: string,
|
||||||
|
truthValue: bool,
|
||||||
|
};
|
||||||
|
|
||||||
|
type pointsToEvenlySample = int;
|
||||||
|
|
||||||
|
type dateTimeRange = {
|
||||||
|
startTime: MomentRe.Moment.t,
|
||||||
|
endTime: MomentRe.Moment.t,
|
||||||
|
pointsWithin: int,
|
||||||
|
};
|
||||||
|
|
||||||
|
type floatPointRange = {
|
||||||
|
startTime: float,
|
||||||
|
endTime: float,
|
||||||
|
pointsWithin: int,
|
||||||
|
};
|
||||||
|
|
||||||
|
type range('a) = {
|
||||||
|
beginning: 'a,
|
||||||
|
ending: 'a,
|
||||||
|
pointsToEvenlySample,
|
||||||
|
};
|
||||||
|
|
||||||
|
type t =
|
||||||
|
| SelectSingle([ | `combination | `item(string)])
|
||||||
|
| DateTime(
|
||||||
|
[
|
||||||
|
| `combination(range(MomentRe.Moment.t))
|
||||||
|
| `item(MomentRe.Moment.t)
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|> ReasonReact.string
|
| FloatPoint(
|
||||||
| SelectSingle(r) => r |> ReasonReact.string
|
[ | `combination(range(MomentRe.Moment.t)) | `item(string)],
|
||||||
| ConditionalArray(r) => "Array" |> ReasonReact.string
|
)
|
||||||
| Conditional(r) => r.name |> ReasonReact.string
|
| Probability([ | `item(string)])
|
||||||
| GenericDistribution(r) =>
|
| GenericDistribution([ | `item(DistributionTypes.genericDistribution)])
|
||||||
let newDistribution =
|
| ConditionalArray([ | `item(array(conditional))])
|
||||||
GenericDistribution.renderIfNeeded(~sampleCount=1000, r);
|
| FloatCdf([ | `item(string)]);
|
||||||
switch (newDistribution) {
|
|
||||||
| Some({
|
|
||||||
generationSource:
|
|
||||||
Shape(
|
|
||||||
Mixed({
|
|
||||||
continuous: n,
|
|
||||||
discrete: d,
|
|
||||||
discreteProbabilityMassFraction: f,
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
}) =>
|
|
||||||
<div>
|
|
||||||
<Chart height=100 data={n |> Shape.Continuous.toJs} />
|
|
||||||
{d |> Shape.Discrete.scaleYToTotal(f) |> Shape.Discrete.render}
|
|
||||||
</div>
|
|
||||||
| None => "Something went wrong" |> ReasonReact.string
|
|
||||||
| _ => <div />
|
|
||||||
};
|
|
||||||
| FloatCdf(_) => <div />
|
|
||||||
| Probability(r) =>
|
|
||||||
(r *. 100. |> Js.Float.toFixed) ++ "%" |> ReasonReact.string
|
|
||||||
| DateTime(r) => r |> MomentRe.Moment.defaultFormat |> ReasonReact.string
|
|
||||||
| FloatPoint(r) => r |> Js.Float.toFixed |> ReasonReact.string
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module Type = {
|
module Type = {
|
||||||
|
@ -113,7 +117,6 @@ module Type = {
|
||||||
type withDefault('a) = {default: option('a)};
|
type withDefault('a) = {default: option('a)};
|
||||||
|
|
||||||
type t =
|
type t =
|
||||||
| BinaryConditional
|
|
||||||
| SelectSingle(selectSingle)
|
| SelectSingle(selectSingle)
|
||||||
| FloatPoint(withDefaultMinMax(float))
|
| FloatPoint(withDefaultMinMax(float))
|
||||||
| Probability(withDefault(float))
|
| Probability(withDefault(float))
|
||||||
|
@ -124,7 +127,6 @@ module Type = {
|
||||||
|
|
||||||
let default = (t: t) =>
|
let default = (t: t) =>
|
||||||
switch (t) {
|
switch (t) {
|
||||||
| BinaryConditional => Some(Value.BinaryConditional(Unselected))
|
|
||||||
| Conditionals(s) => Some(Value.ConditionalArray(s.defaults))
|
| Conditionals(s) => Some(Value.ConditionalArray(s.defaults))
|
||||||
| Year(r) => r.default->Belt.Option.map(p => Value.FloatPoint(p))
|
| Year(r) => r.default->Belt.Option.map(p => Value.FloatPoint(p))
|
||||||
| FloatPoint(r) => r.default->Belt.Option.map(p => Value.FloatPoint(p))
|
| FloatPoint(r) => r.default->Belt.Option.map(p => Value.FloatPoint(p))
|
||||||
|
@ -152,6 +154,22 @@ module ValueMap = {
|
||||||
let fromOptionalArray = (r): t => MS.fromArray(r) |> fromOptionalMap;
|
let fromOptionalArray = (r): t => MS.fromArray(r) |> fromOptionalMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module ValueClusterMap = {
|
||||||
|
module MS = Belt.Map.String;
|
||||||
|
type t = MS.t(ValueCluster.t);
|
||||||
|
let get = (t: t, s) => MS.get(t, s);
|
||||||
|
let keys = MS.keysToArray;
|
||||||
|
let map = MS.map;
|
||||||
|
let fromArray = (r): t => MS.fromArray(r);
|
||||||
|
let values = (t: t) => t |> MS.valuesToArray;
|
||||||
|
let update = (t, k, v) => MS.update(t, k, _ => v);
|
||||||
|
let toArray = MS.toArray;
|
||||||
|
let fromOptionalMap = (t: MS.t(option(ValueCluster.t))): t =>
|
||||||
|
MS.keep(t, (_, d) => E.O.isSome(d))
|
||||||
|
->MS.map(d => E.O.toExn("This should not have happened", d));
|
||||||
|
let fromOptionalArray = (r): t => MS.fromArray(r) |> fromOptionalMap;
|
||||||
|
};
|
||||||
|
|
||||||
module TypeWithMetadata = {
|
module TypeWithMetadata = {
|
||||||
// TODO: Figure out a better name for assumptionType
|
// TODO: Figure out a better name for assumptionType
|
||||||
type assumptionType =
|
type assumptionType =
|
||||||
|
|
|
@ -127,36 +127,6 @@ let make =
|
||||||
}
|
}
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
| (BinaryConditional, Some(BinaryConditional(r))) =>
|
|
||||||
switch (r) {
|
|
||||||
| Unselected =>
|
|
||||||
<div
|
|
||||||
onClick={_ => onChange(Some(BinaryConditional(Selected(true))))}>
|
|
||||||
{"Select" |> ReasonReact.string}
|
|
||||||
</div>
|
|
||||||
| Selected(true) =>
|
|
||||||
<div>
|
|
||||||
{"YES!" |> ReasonReact.string}
|
|
||||||
<div
|
|
||||||
onClick={_ => onChange(Some(BinaryConditional(Selected(false))))}>
|
|
||||||
{"No" |> ReasonReact.string}
|
|
||||||
</div>
|
|
||||||
<div onClick={_ => onChange(Some(BinaryConditional(Unselected)))}>
|
|
||||||
{"Deselect" |> ReasonReact.string}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
| Selected(false) =>
|
|
||||||
<div>
|
|
||||||
{"NO!" |> ReasonReact.string}
|
|
||||||
<div
|
|
||||||
onClick={_ => onChange(Some(BinaryConditional(Selected(true))))}>
|
|
||||||
{"Yes" |> ReasonReact.string}
|
|
||||||
</div>
|
|
||||||
<div onClick={_ => onChange(Some(BinaryConditional(Unselected)))}>
|
|
||||||
{"Deselect" |> ReasonReact.string}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
| (Year(_), _)
|
| (Year(_), _)
|
||||||
| (FloatPoint(_), _) => <input type_="number" value="" />
|
| (FloatPoint(_), _) => <input type_="number" value="" />
|
||||||
| (SelectSingle(t), Some(SelectSingle(r))) =>
|
| (SelectSingle(t), Some(SelectSingle(r))) =>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user