From c0512e5eed60eefd63167adadb0ff09b4ba2c1c8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 4 May 2022 14:40:32 +0000 Subject: [PATCH 1/4] :arrow_up: Bump @testing-library/react from 13.1.1 to 13.2.0 Bumps [@testing-library/react](https://github.com/testing-library/react-testing-library) from 13.1.1 to 13.2.0. - [Release notes](https://github.com/testing-library/react-testing-library/releases) - [Changelog](https://github.com/testing-library/react-testing-library/blob/main/CHANGELOG.md) - [Commits](https://github.com/testing-library/react-testing-library/compare/v13.1.1...v13.2.0) --- updated-dependencies: - dependency-name: "@testing-library/react" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- packages/components/package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/components/package.json b/packages/components/package.json index 3ffc28af..2579668a 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -27,7 +27,7 @@ "@storybook/preset-create-react-app": "^4.1.0", "@storybook/react": "^6.4.22", "@testing-library/jest-dom": "^5.16.4", - "@testing-library/react": "^13.1.1", + "@testing-library/react": "^13.2.0", "@testing-library/user-event": "^14.1.1", "@types/jest": "^27.4.0", "@types/lodash": "^4.14.182", diff --git a/yarn.lock b/yarn.lock index 11bb1227..8753ca0d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3754,10 +3754,10 @@ lodash "^4.17.15" redent "^3.0.0" -"@testing-library/react@^13.1.1": - version "13.1.1" - resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-13.1.1.tgz#6c1635e25acca8ca5be8ee3b19ad1391681c5846" - integrity sha512-8mirlAa0OKaUvnqnZF6MdAh2tReYA2KtWVw1PKvaF5EcCZqgK5pl8iF+3uW90JdG5Ua2c2c2E2wtLdaug3dsVg== +"@testing-library/react@^13.2.0": + version "13.2.0" + resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-13.2.0.tgz#2db00bc94d71c4e90e5c25582e90a650ae2925bf" + integrity sha512-Bprbz/SZVONCJy5f7hcihNCv313IJXdYiv0nSJklIs1SQCIHHNlnGNkosSXnGZTmesyGIcBGNppYhXcc11pb7g== dependencies: "@babel/runtime" "^7.12.5" "@testing-library/dom" "^8.5.0" From e561a47d51f05d79d9d768a4e2a032ff85999318 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 4 May 2022 14:41:05 +0000 Subject: [PATCH 2/4] :arrow_up: Bump @types/jest from 27.4.1 to 27.5.0 Bumps [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) from 27.4.1 to 27.5.0. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest) --- updated-dependencies: - dependency-name: "@types/jest" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- packages/components/package.json | 2 +- packages/squiggle-lang/package.json | 2 +- yarn.lock | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/components/package.json b/packages/components/package.json index 3ffc28af..92fe4ad5 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -29,7 +29,7 @@ "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^13.1.1", "@testing-library/user-event": "^14.1.1", - "@types/jest": "^27.4.0", + "@types/jest": "^27.5.0", "@types/lodash": "^4.14.182", "@types/node": "^17.0.31", "@types/react": "^18.0.3", diff --git a/packages/squiggle-lang/package.json b/packages/squiggle-lang/package.json index 98748e63..97b710b6 100644 --- a/packages/squiggle-lang/package.json +++ b/packages/squiggle-lang/package.json @@ -46,7 +46,7 @@ "rescript-fast-check": "^1.1.1", "@glennsl/rescript-jest": "^0.9.0", "@istanbuljs/nyc-config-typescript": "^1.0.2", - "@types/jest": "^27.4.0", + "@types/jest": "^27.5.0", "babel-plugin-transform-es2015-modules-commonjs": "^6.26.2", "chalk": "^5.0.1", "codecov": "^3.8.3", diff --git a/yarn.lock b/yarn.lock index 11bb1227..55dd931a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4017,10 +4017,10 @@ dependencies: "@types/istanbul-lib-report" "*" -"@types/jest@*", "@types/jest@^27.4.0": - version "27.4.1" - resolved "https://registry.yarnpkg.com/@types/jest/-/jest-27.4.1.tgz#185cbe2926eaaf9662d340cc02e548ce9e11ab6d" - integrity sha512-23iPJADSmicDVrWk+HT58LMJtzLAnB2AgIzplQuq/bSrGaxCrlvRFjGbXmamnnk/mAmCdLStiGqggu28ocUyiw== +"@types/jest@*", "@types/jest@^27.5.0": + version "27.5.0" + resolved "https://registry.yarnpkg.com/@types/jest/-/jest-27.5.0.tgz#e04ed1824ca6b1dd0438997ba60f99a7405d4c7b" + integrity sha512-9RBFx7r4k+msyj/arpfaa0WOOEcaAZNmN+j80KFbFCoSqCJGHTz7YMAMGQW9Xmqm5w6l5c25vbSjMwlikJi5+g== dependencies: jest-matcher-utils "^27.0.0" pretty-format "^27.0.0" From 930c2d2b67b96a1374de98fa3aadecf7c9c64858 Mon Sep 17 00:00:00 2001 From: Sam Nolan Date: Wed, 4 May 2022 15:53:41 +0000 Subject: [PATCH 3/4] Add Gamma distribution --- .../ReducerInterface_Distribution_test.res | 1 + .../SymbolicDist/SymbolicDist.res | 29 +++++++++++++++++++ .../SymbolicDist/SymbolicDistTypes.res | 6 ++++ .../ReducerInterface_GenericDistribution.res | 3 +- .../src/rescript/Utility/Jstat.res | 8 +++++ 5 files changed, 46 insertions(+), 1 deletion(-) diff --git a/packages/squiggle-lang/__tests__/ReducerInterface/ReducerInterface_Distribution_test.res b/packages/squiggle-lang/__tests__/ReducerInterface/ReducerInterface_Distribution_test.res index bb330479..571a838b 100644 --- a/packages/squiggle-lang/__tests__/ReducerInterface/ReducerInterface_Distribution_test.res +++ b/packages/squiggle-lang/__tests__/ReducerInterface/ReducerInterface_Distribution_test.res @@ -30,6 +30,7 @@ describe("eval on distribution functions", () => { describe("mean", () => { testEval("mean(normal(5,2))", "Ok(5)") testEval("mean(lognormal(1,2))", "Ok(20.085536923187668)") + testEval("mean(gamma(5,5))", "Ok(25)") }) describe("toString", () => { testEval("toString(normal(5,2))", "Ok('Normal(5,2)')") diff --git a/packages/squiggle-lang/src/rescript/Distributions/SymbolicDist/SymbolicDist.res b/packages/squiggle-lang/src/rescript/Distributions/SymbolicDist/SymbolicDist.res index a4704a34..fb338ded 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/SymbolicDist/SymbolicDist.res +++ b/packages/squiggle-lang/src/rescript/Distributions/SymbolicDist/SymbolicDist.res @@ -216,6 +216,27 @@ module Uniform = { } } +module Gamma = { + type t = gamma + let make = (shape: float, scale: float) => { + if shape > 0. { + if scale > 0. { + Ok(#Gamma({shape: shape, scale: scale})) + } else { + Error("scale must be larger than 0") + } + } else { + Error("shape must be larger than 0") + } + } + let pdf = (x: float, t: t) => Jstat.Gamma.pdf(x, t.shape, t.scale) + let cdf = (x: float, t: t) => Jstat.Gamma.cdf(x, t.shape, t.scale) + let inv = (p: float, t: t) => Jstat.Gamma.inv(p, t.shape, t.scale) + let sample = (t: t) => Jstat.Gamma.sample(t.shape, t.scale) + let mean = (t: t) => Ok(Jstat.Gamma.mean(t.shape, t.scale)) + let toString = ({shape, scale}: t) => j`($shape, $scale)` +} + module Float = { type t = float let make = t => #Float(t) @@ -252,6 +273,7 @@ module T = { | #Triangular(n) => Triangular.pdf(x, n) | #Exponential(n) => Exponential.pdf(x, n) | #Cauchy(n) => Cauchy.pdf(x, n) + | #Gamma(n) => Gamma.pdf(x, n) | #Lognormal(n) => Lognormal.pdf(x, n) | #Uniform(n) => Uniform.pdf(x, n) | #Beta(n) => Beta.pdf(x, n) @@ -264,6 +286,7 @@ module T = { | #Triangular(n) => Triangular.cdf(x, n) | #Exponential(n) => Exponential.cdf(x, n) | #Cauchy(n) => Cauchy.cdf(x, n) + | #Gamma(n) => Gamma.cdf(x, n) | #Lognormal(n) => Lognormal.cdf(x, n) | #Uniform(n) => Uniform.cdf(x, n) | #Beta(n) => Beta.cdf(x, n) @@ -276,6 +299,7 @@ module T = { | #Triangular(n) => Triangular.inv(x, n) | #Exponential(n) => Exponential.inv(x, n) | #Cauchy(n) => Cauchy.inv(x, n) + | #Gamma(n) => Gamma.inv(x, n) | #Lognormal(n) => Lognormal.inv(x, n) | #Uniform(n) => Uniform.inv(x, n) | #Beta(n) => Beta.inv(x, n) @@ -288,6 +312,7 @@ module T = { | #Triangular(n) => Triangular.sample(n) | #Exponential(n) => Exponential.sample(n) | #Cauchy(n) => Cauchy.sample(n) + | #Gamma(n) => Gamma.sample(n) | #Lognormal(n) => Lognormal.sample(n) | #Uniform(n) => Uniform.sample(n) | #Beta(n) => Beta.sample(n) @@ -310,6 +335,7 @@ module T = { | #Exponential(n) => Exponential.toString(n) | #Cauchy(n) => Cauchy.toString(n) | #Normal(n) => Normal.toString(n) + | #Gamma(n) => Gamma.toString(n) | #Lognormal(n) => Lognormal.toString(n) | #Uniform(n) => Uniform.toString(n) | #Beta(n) => Beta.toString(n) @@ -323,6 +349,7 @@ module T = { | #Cauchy(n) => Cauchy.inv(minCdfValue, n) | #Normal(n) => Normal.inv(minCdfValue, n) | #Lognormal(n) => Lognormal.inv(minCdfValue, n) + | #Gamma(n) => Gamma.inv(minCdfValue, n) | #Uniform({low}) => low | #Beta(n) => Beta.inv(minCdfValue, n) | #Float(n) => n @@ -334,6 +361,7 @@ module T = { | #Exponential(n) => Exponential.inv(maxCdfValue, n) | #Cauchy(n) => Cauchy.inv(maxCdfValue, n) | #Normal(n) => Normal.inv(maxCdfValue, n) + | #Gamma(n) => Gamma.inv(maxCdfValue, n) | #Lognormal(n) => Lognormal.inv(maxCdfValue, n) | #Beta(n) => Beta.inv(maxCdfValue, n) | #Uniform({high}) => high @@ -349,6 +377,7 @@ module T = { | #Lognormal(n) => Lognormal.mean(n) | #Beta(n) => Beta.mean(n) | #Uniform(n) => Uniform.mean(n) + | #Gamma(n) => Gamma.mean(n) | #Float(n) => Float.mean(n) } diff --git a/packages/squiggle-lang/src/rescript/Distributions/SymbolicDist/SymbolicDistTypes.res b/packages/squiggle-lang/src/rescript/Distributions/SymbolicDist/SymbolicDistTypes.res index 333e2e63..7878a3bc 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/SymbolicDist/SymbolicDistTypes.res +++ b/packages/squiggle-lang/src/rescript/Distributions/SymbolicDist/SymbolicDistTypes.res @@ -31,6 +31,11 @@ type triangular = { high: float, } +type gamma = { + shape: float, + scale: float, +} + @genType type symbolicDist = [ | #Normal(normal) @@ -40,6 +45,7 @@ type symbolicDist = [ | #Exponential(exponential) | #Cauchy(cauchy) | #Triangular(triangular) + | #Gamma(gamma) | #Float(float) ] diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res index 542a54a2..b6f42697 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res @@ -154,6 +154,7 @@ module SymbolicConstructors = { | "beta" => Ok(SymbolicDist.Beta.make) | "lognormal" => Ok(SymbolicDist.Lognormal.make) | "cauchy" => Ok(SymbolicDist.Cauchy.make) + | "gamma" => Ok(SymbolicDist.Gamma.make) | "to" => Ok(SymbolicDist.From90thPercentile.make) | _ => Error("Unreachable state") } @@ -185,7 +186,7 @@ let dispatchToGenericOutput = (call: ExpressionValue.functionCall, _environment) | ("delta", [EvNumber(f)]) => SymbolicDist.Float.makeSafe(f)->SymbolicConstructors.symbolicResultToOutput | ( - ("normal" | "uniform" | "beta" | "lognormal" | "cauchy" | "to") as fnName, + ("normal" | "uniform" | "beta" | "lognormal" | "cauchy" | "gamma" | "to") as fnName, [EvNumber(f1), EvNumber(f2)], ) => SymbolicConstructors.twoFloat(fnName) diff --git a/packages/squiggle-lang/src/rescript/Utility/Jstat.res b/packages/squiggle-lang/src/rescript/Utility/Jstat.res index 03c43174..1de2e8ed 100644 --- a/packages/squiggle-lang/src/rescript/Utility/Jstat.res +++ b/packages/squiggle-lang/src/rescript/Utility/Jstat.res @@ -81,6 +81,14 @@ module Binomial = { @module("jstat") @scope("binomial") external cdf: (float, float, float) => float = "cdf" } +module Gamma = { + @module("jstat") @scope("gamma") external pdf: (float, float, float) => float = "pdf" + @module("jstat") @scope("gamma") external cdf: (float, float, float) => float = "cdf" + @module("jstat") @scope("gamma") external inv: (float, float, float) => float = "inv" + @module("jstat") @scope("gamma") external mean: (float, float) => float = "mean" + @module("jstat") @scope("gamma") external sample: (float, float) => float = "sample" +} + @module("jstat") external sum: array => float = "sum" @module("jstat") external product: array => float = "product" @module("jstat") external min: array => float = "min" From 801e4c23d180e17e2da0157d14feb2de6a48065b Mon Sep 17 00:00:00 2001 From: Sam Nolan Date: Wed, 4 May 2022 16:50:08 +0000 Subject: [PATCH 4/4] v0.2.19 --- packages/components/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/package.json b/packages/components/package.json index db097341..b7841dda 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -1,6 +1,6 @@ { "name": "@quri/squiggle-components", - "version": "0.2.17", + "version": "0.2.19", "license": "MIT", "dependencies": { "@quri/squiggle-lang": "^0.2.8",