Foretold->Squiggle

This commit is contained in:
Ozzie Gooen 2022-02-18 17:42:55 -05:00
parent 8a0e84bb5b
commit 3940f53a0c
9 changed files with 49 additions and 49 deletions

View File

@ -39,7 +39,7 @@
"@rescript/react", "@rescript/react",
"bs-css", "bs-css",
"bs-css-emotion", "bs-css-emotion",
"@foretold-app/squiggle", "@squiggle/lang",
"rationale", "rationale",
"bs-moment", "bs-moment",
"reschema" "reschema"

View File

@ -13,7 +13,7 @@
<script> <script>
window.$docsify = { window.$docsify = {
name: 'Squiggle', name: 'Squiggle',
repo: 'foretold-app/squiggle', repo: 'squiggle/lang',
loadSidebar: true loadSidebar: true
} }
</script> </script>

View File

@ -1,5 +1,5 @@
{ {
"name": "@foretold-app/squiggle-playground", "name": "@squiggle/playground",
"version": "0.1.0", "version": "0.1.0",
"homepage": "https://foretold-app.github.io/estiband/", "homepage": "https://foretold-app.github.io/estiband/",
"scripts": { "scripts": {
@ -61,7 +61,7 @@
"react-vega": "^7.4.4", "react-vega": "^7.4.4",
"reschema": "^2.2.0", "reschema": "^2.2.0",
"rescript": "^9.1.4", "rescript": "^9.1.4",
"@foretold-app/squiggle": "^0.1.9", "@squiggle/lang": "^0.1.9",
"tailwindcss": "1.2.0", "tailwindcss": "1.2.0",
"vega": "*", "vega": "*",
"vega-embed": "6.6.0", "vega-embed": "6.6.0",

View File

@ -100,7 +100,7 @@ module DemoDist = {
<div> <div>
{switch options { {switch options {
| Some(options) => | Some(options) =>
let inputs1 = ForetoldAppSquiggle.ProgramEvaluator.Inputs.make( let inputs1 = SquiggleLang.ProgramEvaluator.Inputs.make(
~samplingInputs={ ~samplingInputs={
sampleCount: Some(options.sampleCount), sampleCount: Some(options.sampleCount),
outputXYPoints: Some(options.outputXYPoints), outputXYPoints: Some(options.outputXYPoints),
@ -117,15 +117,15 @@ module DemoDist = {
(), (),
) )
let distributionList = ForetoldAppSquiggle.ProgramEvaluator.evaluateProgram(inputs1) let distributionList = SquiggleLang.ProgramEvaluator.evaluateProgram(inputs1)
let renderExpression = response1 => let renderExpression = response1 =>
switch response1 { switch response1 {
| #DistPlus(distPlus1) => <DistPlusPlot distPlus={ForetoldAppSquiggle.DistPlus.T.normalize(distPlus1)} /> | #DistPlus(distPlus1) => <DistPlusPlot distPlus={SquiggleLang.DistPlus.T.normalize(distPlus1)} />
| #Float(f) => <NumberShower number=f precision=3 /> | #Float(f) => <NumberShower number=f precision=3 />
| #Function((f, a), env) => | #Function((f, a), env) =>
// Problem: When it gets the function, it doesn't save state about previous commands // Problem: When it gets the function, it doesn't save state about previous commands
let foo: ForetoldAppSquiggle.ProgramEvaluator.Inputs.inputs = { let foo: SquiggleLang.ProgramEvaluator.Inputs.inputs = {
squiggleString: squiggleString, squiggleString: squiggleString,
samplingInputs: inputs1.samplingInputs, samplingInputs: inputs1.samplingInputs,
environment: env, environment: env,
@ -133,13 +133,13 @@ module DemoDist = {
let results = let results =
E.A.Floats.range(options.diagramStart, options.diagramStop, options.diagramCount) E.A.Floats.range(options.diagramStart, options.diagramStop, options.diagramCount)
|> E.A.fmap(r => |> E.A.fmap(r =>
ForetoldAppSquiggle.ProgramEvaluator.evaluateFunction( SquiggleLang.ProgramEvaluator.evaluateFunction(
foo, foo,
(f, a), (f, a),
[#SymbolicDist(#Float(r))], [#SymbolicDist(#Float(r))],
) |> E.R.bind(_, a => ) |> E.R.bind(_, a =>
switch a { switch a {
| #DistPlus(d) => Ok((r, ForetoldAppSquiggle.DistPlus.T.normalize(d))) | #DistPlus(d) => Ok((r, SquiggleLang.DistPlus.T.normalize(d)))
| n => | n =>
Js.log2("Error here", n) Js.log2("Error here", n)
Error("wrong type") Error("wrong type")

View File

@ -1,7 +1,7 @@
open DistPlusPlotReducer open DistPlusPlotReducer
let plotBlue = #hex("1860ad") let plotBlue = #hex("1860ad")
let showAsForm = (distPlus: ForetoldAppSquiggle.PointSetTypes.distPlus) => let showAsForm = (distPlus: SquiggleLang.PointSetTypes.distPlus) =>
<div> <Antd.Input value={distPlus.squiggleString |> E.O.default("")} /> </div> <div> <Antd.Input value={distPlus.squiggleString |> E.O.default("")} /> </div>
let showFloat = (~precision=3, number) => <NumberShower number precision /> let showFloat = (~precision=3, number) => <NumberShower number precision />
@ -23,27 +23,27 @@ let table = (distPlus, x) =>
<td className="px-4 py-2 border"> {x |> E.Float.toString |> React.string} </td> <td className="px-4 py-2 border"> {x |> E.Float.toString |> React.string} </td>
<td className="px-4 py-2 border "> <td className="px-4 py-2 border ">
{distPlus {distPlus
|> ForetoldAppSquiggle.DistPlus.T.xToY(x) |> SquiggleLang.DistPlus.T.xToY(x)
|> ForetoldAppSquiggle.PointSetTypes.MixedPoint.toDiscreteValue |> SquiggleLang.PointSetTypes.MixedPoint.toDiscreteValue
|> Js.Float.toPrecisionWithPrecision(_, ~digits=7) |> Js.Float.toPrecisionWithPrecision(_, ~digits=7)
|> React.string} |> React.string}
</td> </td>
<td className="px-4 py-2 border "> <td className="px-4 py-2 border ">
{distPlus {distPlus
|> ForetoldAppSquiggle.DistPlus.T.xToY(x) |> SquiggleLang.DistPlus.T.xToY(x)
|> ForetoldAppSquiggle.PointSetTypes.MixedPoint.toContinuousValue |> SquiggleLang.PointSetTypes.MixedPoint.toContinuousValue
|> Js.Float.toPrecisionWithPrecision(_, ~digits=7) |> Js.Float.toPrecisionWithPrecision(_, ~digits=7)
|> React.string} |> React.string}
</td> </td>
<td className="px-4 py-2 border "> <td className="px-4 py-2 border ">
{distPlus {distPlus
|> ForetoldAppSquiggle.DistPlus.T.Integral.xToY(x) |> SquiggleLang.DistPlus.T.Integral.xToY(x)
|> E.Float.with2DigitsPrecision |> E.Float.with2DigitsPrecision
|> React.string} |> React.string}
</td> </td>
<td className="px-4 py-2 border "> <td className="px-4 py-2 border ">
{distPlus {distPlus
|> ForetoldAppSquiggle.DistPlus.T.Integral.sum |> SquiggleLang.DistPlus.T.Integral.sum
|> E.Float.with2DigitsPrecision |> E.Float.with2DigitsPrecision
|> React.string} |> React.string}
</td> </td>
@ -61,16 +61,16 @@ let table = (distPlus, x) =>
<tr> <tr>
<td className="px-4 py-2 border"> <td className="px-4 py-2 border">
{distPlus {distPlus
|> ForetoldAppSquiggle.DistPlus.T.toContinuous |> SquiggleLang.DistPlus.T.toContinuous
|> E.O.fmap(ForetoldAppSquiggle.Continuous.T.Integral.sum) |> E.O.fmap(SquiggleLang.Continuous.T.Integral.sum)
|> E.O.fmap(E.Float.with2DigitsPrecision) |> E.O.fmap(E.Float.with2DigitsPrecision)
|> E.O.default("") |> E.O.default("")
|> React.string} |> React.string}
</td> </td>
<td className="px-4 py-2 border "> <td className="px-4 py-2 border ">
{distPlus {distPlus
|> ForetoldAppSquiggle.DistPlus.T.toDiscrete |> SquiggleLang.DistPlus.T.toDiscrete
|> E.O.fmap(ForetoldAppSquiggle.Discrete.T.Integral.sum) |> E.O.fmap(SquiggleLang.Discrete.T.Integral.sum)
|> E.O.fmap(E.Float.with2DigitsPrecision) |> E.O.fmap(E.Float.with2DigitsPrecision)
|> E.O.default("") |> E.O.default("")
|> React.string} |> React.string}
@ -97,28 +97,28 @@ let percentiles = distPlus =>
<tbody> <tbody>
<tr> <tr>
<td className="px-4 py-2 border"> <td className="px-4 py-2 border">
{distPlus |> ForetoldAppSquiggle.DistPlus.T.Integral.yToX(0.01) |> showFloat} {distPlus |> SquiggleLang.DistPlus.T.Integral.yToX(0.01) |> showFloat}
</td> </td>
<td className="px-4 py-2 border"> <td className="px-4 py-2 border">
{distPlus |> ForetoldAppSquiggle.DistPlus.T.Integral.yToX(0.05) |> showFloat} {distPlus |> SquiggleLang.DistPlus.T.Integral.yToX(0.05) |> showFloat}
</td> </td>
<td className="px-4 py-2 border"> <td className="px-4 py-2 border">
{distPlus |> ForetoldAppSquiggle.DistPlus.T.Integral.yToX(0.25) |> showFloat} {distPlus |> SquiggleLang.DistPlus.T.Integral.yToX(0.25) |> showFloat}
</td> </td>
<td className="px-4 py-2 border"> <td className="px-4 py-2 border">
{distPlus |> ForetoldAppSquiggle.DistPlus.T.Integral.yToX(0.5) |> showFloat} {distPlus |> SquiggleLang.DistPlus.T.Integral.yToX(0.5) |> showFloat}
</td> </td>
<td className="px-4 py-2 border"> <td className="px-4 py-2 border">
{distPlus |> ForetoldAppSquiggle.DistPlus.T.Integral.yToX(0.75) |> showFloat} {distPlus |> SquiggleLang.DistPlus.T.Integral.yToX(0.75) |> showFloat}
</td> </td>
<td className="px-4 py-2 border"> <td className="px-4 py-2 border">
{distPlus |> ForetoldAppSquiggle.DistPlus.T.Integral.yToX(0.95) |> showFloat} {distPlus |> SquiggleLang.DistPlus.T.Integral.yToX(0.95) |> showFloat}
</td> </td>
<td className="px-4 py-2 border"> <td className="px-4 py-2 border">
{distPlus |> ForetoldAppSquiggle.DistPlus.T.Integral.yToX(0.99) |> showFloat} {distPlus |> SquiggleLang.DistPlus.T.Integral.yToX(0.99) |> showFloat}
</td> </td>
<td className="px-4 py-2 border"> <td className="px-4 py-2 border">
{distPlus |> ForetoldAppSquiggle.DistPlus.T.Integral.yToX(0.99999) |> showFloat} {distPlus |> SquiggleLang.DistPlus.T.Integral.yToX(0.99999) |> showFloat}
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -133,11 +133,11 @@ let percentiles = distPlus =>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td className="px-4 py-2 border"> {distPlus |> ForetoldAppSquiggle.DistPlus.T.mean |> showFloat} </td> <td className="px-4 py-2 border"> {distPlus |> SquiggleLang.DistPlus.T.mean |> showFloat} </td>
<td className="px-4 py-2 border"> <td className="px-4 py-2 border">
{distPlus |> ForetoldAppSquiggle.DistPlus.T.variance |> (r => r ** 0.5) |> showFloat} {distPlus |> SquiggleLang.DistPlus.T.variance |> (r => r ** 0.5) |> showFloat}
</td> </td>
<td className="px-4 py-2 border"> {distPlus |> ForetoldAppSquiggle.DistPlus.T.variance |> showFloat} </td> <td className="px-4 py-2 border"> {distPlus |> SquiggleLang.DistPlus.T.variance |> showFloat} </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -155,11 +155,11 @@ let adjustBoth = discreteProbabilityMassFraction => {
module DistPlusChart = { module DistPlusChart = {
@react.component @react.component
let make = (~distPlus: ForetoldAppSquiggle.PointSetTypes.distPlus, ~config: chartConfig, ~onHover) => { let make = (~distPlus: SquiggleLang.PointSetTypes.distPlus, ~config: chartConfig, ~onHover) => {
open ForetoldAppSquiggle.DistPlus open SquiggleLang.DistPlus
let discrete = distPlus |> T.toDiscrete |> E.O.fmap(ForetoldAppSquiggle.Discrete.getShape) let discrete = distPlus |> T.toDiscrete |> E.O.fmap(SquiggleLang.Discrete.getShape)
let continuous = distPlus |> T.toContinuous |> E.O.fmap(ForetoldAppSquiggle.Continuous.getShape) let continuous = distPlus |> T.toContinuous |> E.O.fmap(SquiggleLang.Continuous.getShape)
// // We subtract a bit from the range to make sure that it fits. Maybe this should be done in d3 instead. // // We subtract a bit from the range to make sure that it fits. Maybe this should be done in d3 instead.
// let minX = // let minX =
@ -176,7 +176,7 @@ module DistPlusChart = {
let maxX = distPlus |> T.Integral.yToX(0.99999) let maxX = distPlus |> T.Integral.yToX(0.99999)
let timeScale = distPlus.unit |> ForetoldAppSquiggle.PointSetTypes.DistributionUnit.toJson let timeScale = distPlus.unit |> SquiggleLang.PointSetTypes.DistributionUnit.toJson
let discreteProbabilityMassFraction = distPlus |> T.toDiscreteProbabilityMassFraction let discreteProbabilityMassFraction = distPlus |> T.toDiscreteProbabilityMassFraction
let (yMaxDiscreteDomainFactor, yMaxContinuousDomainFactor) = adjustBoth( let (yMaxDiscreteDomainFactor, yMaxContinuousDomainFactor) = adjustBoth(
@ -202,13 +202,13 @@ module DistPlusChart = {
module IntegralChart = { module IntegralChart = {
@react.component @react.component
let make = (~distPlus: ForetoldAppSquiggle.PointSetTypes.distPlus, ~config: chartConfig, ~onHover) => { let make = (~distPlus: SquiggleLang.PointSetTypes.distPlus, ~config: chartConfig, ~onHover) => {
let integral = distPlus.integralCache let integral = distPlus.integralCache
let continuous = integral |> ForetoldAppSquiggle.Continuous.toLinear |> E.O.fmap(ForetoldAppSquiggle.Continuous.getShape) let continuous = integral |> SquiggleLang.Continuous.toLinear |> E.O.fmap(SquiggleLang.Continuous.getShape)
let minX = distPlus |> ForetoldAppSquiggle.DistPlus.T.Integral.yToX(0.00001) let minX = distPlus |> SquiggleLang.DistPlus.T.Integral.yToX(0.00001)
let maxX = distPlus |> ForetoldAppSquiggle.DistPlus.T.Integral.yToX(0.99999) let maxX = distPlus |> SquiggleLang.DistPlus.T.Integral.yToX(0.99999)
let timeScale = distPlus.unit |> ForetoldAppSquiggle.PointSetTypes.DistributionUnit.toJson let timeScale = distPlus.unit |> SquiggleLang.PointSetTypes.DistributionUnit.toJson
<DistributionPlot <DistributionPlot
xScale={config.xLog ? "log" : "linear"} xScale={config.xLog ? "log" : "linear"}
yScale={config.yLog ? "log" : "linear"} yScale={config.yLog ? "log" : "linear"}
@ -225,7 +225,7 @@ module IntegralChart = {
module Chart = { module Chart = {
@react.component @react.component
let make = (~distPlus: ForetoldAppSquiggle.PointSetTypes.distPlus, ~config: chartConfig, ~onHover) => { let make = (~distPlus: SquiggleLang.PointSetTypes.distPlus, ~config: chartConfig, ~onHover) => {
let chart = React.useMemo2( let chart = React.useMemo2(
() => () =>
config.isCumulative config.isCumulative
@ -246,7 +246,7 @@ module Chart = {
let button = "bg-gray-300 hover:bg-gray-500 text-grey-darkest text-xs px-4 py-1" let button = "bg-gray-300 hover:bg-gray-500 text-grey-darkest text-xs px-4 py-1"
@react.component @react.component
let make = (~distPlus: ForetoldAppSquiggle.PointSetTypes.distPlus) => { let make = (~distPlus: SquiggleLang.PointSetTypes.distPlus) => {
let (x, setX) = React.useState(() => 0.) let (x, setX) = React.useState(() => 0.)
let (state, dispatch) = React.useReducer(DistPlusPlotReducer.reducer, DistPlusPlotReducer.init) let (state, dispatch) = React.useReducer(DistPlusPlotReducer.reducer, DistPlusPlotReducer.init)

View File

@ -95,12 +95,12 @@ let make = (
?xScale ?xScale
?yScale ?yScale
?timeScale ?timeScale
discrete={discrete |> E.O.fmap(ForetoldAppSquiggle.XYShape.T.toJs)} discrete={discrete |> E.O.fmap(SquiggleLang.XYShape.T.toJs)}
height height
marginBottom=50 marginBottom=50
marginTop=0 marginTop=0
onHover onHover
continuous={continuous |> E.O.fmap(ForetoldAppSquiggle.XYShape.T.toJs)} continuous={continuous |> E.O.fmap(SquiggleLang.XYShape.T.toJs)}
showDistributionLines showDistributionLines
showDistributionYAxis showDistributionYAxis
showVerticalLine showVerticalLine

View File

@ -1,4 +1,4 @@
open ForetoldAppSquiggle open SquiggleLang
@module("./PercentilesChart.js") @module("./PercentilesChart.js")
external percentilesChart: React.element = "PercentilesChart" external percentilesChart: React.element = "PercentilesChart"

View File

@ -1,5 +1,5 @@
{ {
"name": "@foretold-app/squiggle", "name": "@squiggle/lang",
"reason": {}, "reason": {},
"sources": [ "sources": [
{ {

View File

@ -1,5 +1,5 @@
{ {
"name": "@foretold-app/squiggle", "name": "@squiggle/lang",
"version": "0.1.9", "version": "0.1.9",
"homepage": "https://foretold-app.github.io/estiband/", "homepage": "https://foretold-app.github.io/estiband/",
"private": false, "private": false,