Added to index.ts
This commit is contained in:
parent
57196c568b
commit
e065a57a66
|
@ -8,13 +8,39 @@ import type {
|
|||
export type { SamplingInputs, exportEnv, exportDistribution };
|
||||
export type { t as DistPlus } from "../rescript/OldInterpreter/DistPlus.gen";
|
||||
import type { Operation_genericFunctionCallInfo } from "../rescript/Distributions/GenericDist/GenericDist_Types.gen";
|
||||
import { genericDist } from "../rescript/TSInterface.gen";
|
||||
import {
|
||||
run as runR,
|
||||
genericDist,
|
||||
resultDist,
|
||||
resultFloat,
|
||||
resultString,
|
||||
} from "../rescript/TSInterface.gen";
|
||||
import {
|
||||
env,
|
||||
outputType,
|
||||
Constructors_UsingDists_mean,
|
||||
Constructors_UsingDists_sample,
|
||||
Constructors_UsingDists_pdf,
|
||||
Constructors_UsingDists_cdf,
|
||||
Constructors_UsingDists_inv,
|
||||
Constructors_UsingDists_normalize,
|
||||
Constructors_UsingDists_toPointSet,
|
||||
Constructors_UsingDists_toSampleSet,
|
||||
Constructors_UsingDists_truncate,
|
||||
Constructors_UsingDists_inspect,
|
||||
Constructors_UsingDists_toString,
|
||||
Constructors_UsingDists_toSparkline,
|
||||
Constructors_UsingDists_algebraicAdd,
|
||||
Constructors_UsingDists_algebraicMultiply,
|
||||
Constructors_UsingDists_algebraicDivide,
|
||||
Constructors_UsingDists_algebraicSubtract,
|
||||
Constructors_UsingDists_algebraicLogarithm,
|
||||
Constructors_UsingDists_algebraicExponentiate,
|
||||
Constructors_UsingDists_pointwiseAdd,
|
||||
Constructors_UsingDists_pointwiseMultiply,
|
||||
Constructors_UsingDists_pointwiseDivide,
|
||||
Constructors_UsingDists_pointwiseSubtract,
|
||||
Constructors_UsingDists_pointwiseLogarithm,
|
||||
Constructors_UsingDists_pointwiseExponentiate,
|
||||
} from "../rescript/Distributions/DistributionOperation/DistributionOperation.gen";
|
||||
import { add } from "lodash";
|
||||
|
||||
export let defaultSamplingInputs: SamplingInputs = {
|
||||
sampleCount: 10000,
|
||||
|
@ -42,140 +68,152 @@ class GenericDist {
|
|||
this.t = t;
|
||||
}
|
||||
|
||||
mean(): outputType {
|
||||
return runR(
|
||||
{ env: this.env },
|
||||
{ tag: "FromDist", value: [{ tag: "ToFloat", value: "Mean" }, this.t] }
|
||||
);
|
||||
mean(): resultFloat {
|
||||
return Constructors_UsingDists_mean({ env: this.env }, this.t);
|
||||
}
|
||||
|
||||
pdf(n: number): outputType {
|
||||
return runR(
|
||||
{ env: this.env },
|
||||
{
|
||||
tag: "FromDist",
|
||||
value: [{ tag: "ToFloat", value: { NAME: "Pdf", VAL: n } }, this.t],
|
||||
}
|
||||
);
|
||||
sample(): resultFloat {
|
||||
return Constructors_UsingDists_sample({ env: this.env }, this.t);
|
||||
}
|
||||
|
||||
cdf(n: number): outputType {
|
||||
return runR(
|
||||
{ env: this.env },
|
||||
{
|
||||
tag: "FromDist",
|
||||
value: [{ tag: "ToFloat", value: { NAME: "Pdf", VAL: n } }, this.t],
|
||||
}
|
||||
);
|
||||
pdf(n: number): resultFloat {
|
||||
return Constructors_UsingDists_pdf({ env: this.env }, this.t, n);
|
||||
}
|
||||
|
||||
inv(n: number): outputType {
|
||||
return runR(
|
||||
{ env: this.env },
|
||||
{
|
||||
tag: "FromDist",
|
||||
value: [{ tag: "ToFloat", value: { NAME: "Pdf", VAL: n } }, this.t],
|
||||
}
|
||||
);
|
||||
cdf(n: number): resultFloat {
|
||||
return Constructors_UsingDists_cdf({ env: this.env }, this.t, n);
|
||||
}
|
||||
|
||||
normalize(n: number): outputType {
|
||||
return runR(
|
||||
{ env: this.env },
|
||||
{
|
||||
tag: "FromDist",
|
||||
value: [{ tag: "ToDist", value: "Normalize" }, this.t],
|
||||
}
|
||||
);
|
||||
inv(n: number): resultFloat {
|
||||
return Constructors_UsingDists_inv({ env: this.env }, this.t, n);
|
||||
}
|
||||
|
||||
toPointSet(): outputType {
|
||||
return runR(
|
||||
{ env: this.env },
|
||||
{
|
||||
tag: "FromDist",
|
||||
value: [{ tag: "ToDist", value: "ToPointSet" }, this.t],
|
||||
}
|
||||
);
|
||||
normalize(): resultDist {
|
||||
return Constructors_UsingDists_normalize({ env: this.env }, this.t);
|
||||
}
|
||||
|
||||
inspect(): outputType {
|
||||
return runR(
|
||||
{ env: this.env },
|
||||
{ tag: "FromDist", value: [{ tag: "ToDist", value: "Inspect" }, this.t] }
|
||||
);
|
||||
toPointSet(): resultDist {
|
||||
return Constructors_UsingDists_toPointSet({ env: this.env }, this.t);
|
||||
}
|
||||
|
||||
toSampleSet(n: number): outputType {
|
||||
return runR(
|
||||
toSampleSet(n: number): resultDist {
|
||||
return Constructors_UsingDists_toSampleSet({ env: this.env }, this.t, n);
|
||||
}
|
||||
|
||||
truncate(left: number, right: number): resultDist {
|
||||
return Constructors_UsingDists_truncate(
|
||||
{ env: this.env },
|
||||
{
|
||||
tag: "FromDist",
|
||||
value: [
|
||||
{ tag: "ToDist", value: { tag: "ToSampleSet", value: n } },
|
||||
this.t,
|
||||
],
|
||||
}
|
||||
left,
|
||||
right
|
||||
);
|
||||
}
|
||||
|
||||
truncate(
|
||||
left: null | undefined | number,
|
||||
right: null | undefined | number
|
||||
): outputType {
|
||||
return runR(
|
||||
inspect(): resultDist {
|
||||
return Constructors_UsingDists_inspect({ env: this.env }, this.t);
|
||||
}
|
||||
|
||||
toString(): resultString {
|
||||
return Constructors_UsingDists_toString({ env: this.env }, this.t);
|
||||
}
|
||||
|
||||
toSparkline(n: number): resultString {
|
||||
return Constructors_UsingDists_toSparkline({ env: this.env }, this.t, n);
|
||||
}
|
||||
|
||||
algebraicAdd(d2: GenericDist): resultDist {
|
||||
return Constructors_UsingDists_algebraicAdd(
|
||||
{ env: this.env },
|
||||
{
|
||||
tag: "FromDist",
|
||||
value: [
|
||||
{ tag: "ToDist", value: { tag: "Truncate", value: [left, right] } },
|
||||
this.t,
|
||||
],
|
||||
}
|
||||
d2.t
|
||||
);
|
||||
}
|
||||
|
||||
toString(): outputType {
|
||||
return runR(
|
||||
algebraicMultiply(d2: GenericDist): resultDist {
|
||||
return Constructors_UsingDists_algebraicMultiply(
|
||||
{ env: this.env },
|
||||
{
|
||||
tag: "FromDist",
|
||||
value: [{ tag: "ToString", value: "ToString" }, this.t],
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
toSparkline(n: number): outputType {
|
||||
return runR(
|
||||
{ env: this.env },
|
||||
{
|
||||
tag: "FromDist",
|
||||
value: [
|
||||
{ tag: "ToString", value: { tag: "ToSparkline", value: n } },
|
||||
this.t,
|
||||
],
|
||||
}
|
||||
d2.t
|
||||
);
|
||||
}
|
||||
|
||||
add(g2: genericDist): outputType {
|
||||
return runR(
|
||||
algebraicDivide(d2: GenericDist): resultDist {
|
||||
return Constructors_UsingDists_algebraicDivide(
|
||||
{ env: this.env },
|
||||
{
|
||||
tag: "FromDist",
|
||||
value: [
|
||||
{
|
||||
tag: "ToDistCombination",
|
||||
value: [
|
||||
{
|
||||
tag: "ToDistCombination",
|
||||
value: ["Algebraic", "Add", { NAME: "Dist", VAL: g2 }],
|
||||
},
|
||||
],
|
||||
},
|
||||
this.t,
|
||||
],
|
||||
d2.t
|
||||
);
|
||||
}
|
||||
|
||||
algebraicSubtract(d2: GenericDist): resultDist {
|
||||
return Constructors_UsingDists_algebraicSubtract(
|
||||
{ env: this.env },
|
||||
this.t,
|
||||
d2.t
|
||||
);
|
||||
}
|
||||
|
||||
algebraicLogarithm(d2: GenericDist): resultDist {
|
||||
return Constructors_UsingDists_algebraicLogarithm(
|
||||
{ env: this.env },
|
||||
this.t,
|
||||
d2.t
|
||||
);
|
||||
}
|
||||
|
||||
algebraicExponentiate(d2: GenericDist): resultDist {
|
||||
return Constructors_UsingDists_algebraicExponentiate(
|
||||
{ env: this.env },
|
||||
this.t,
|
||||
d2.t
|
||||
);
|
||||
}
|
||||
|
||||
pointwiseAdd(d2: GenericDist): resultDist {
|
||||
return Constructors_UsingDists_pointwiseAdd(
|
||||
{ env: this.env },
|
||||
this.t,
|
||||
d2.t
|
||||
);
|
||||
}
|
||||
|
||||
pointwiseMultiply(d2: GenericDist): resultDist {
|
||||
return Constructors_UsingDists_pointwiseMultiply(
|
||||
{ env: this.env },
|
||||
this.t,
|
||||
d2.t
|
||||
);
|
||||
}
|
||||
|
||||
pointwiseDivide(d2: GenericDist): resultDist {
|
||||
return Constructors_UsingDists_pointwiseDivide(
|
||||
{ env: this.env },
|
||||
this.t,
|
||||
d2.t
|
||||
);
|
||||
}
|
||||
|
||||
pointwiseSubtract(d2: GenericDist): resultDist {
|
||||
return Constructors_UsingDists_pointwiseSubtract(
|
||||
{ env: this.env },
|
||||
this.t,
|
||||
d2.t
|
||||
);
|
||||
}
|
||||
|
||||
pointwiseLogarithm(d2: GenericDist): resultDist {
|
||||
return Constructors_UsingDists_pointwiseLogarithm(
|
||||
{ env: this.env },
|
||||
this.t,
|
||||
d2.t
|
||||
);
|
||||
}
|
||||
|
||||
pointwiseExponentiate(d2: GenericDist): resultDist {
|
||||
return Constructors_UsingDists_pointwiseExponentiate(
|
||||
{ env: this.env },
|
||||
this.t,
|
||||
d2.t
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -190,10 +190,7 @@ module Constructors = {
|
|||
module UsingDists = {
|
||||
module C = GenericDist_Types.Constructors.UsingDists
|
||||
open OutputLocal
|
||||
type dist = GenericDist_Types.genericDist
|
||||
type fResult = result<float, GenericDist_Types.error>
|
||||
type dResult = result<dist, GenericDist_Types.error>
|
||||
type sResult = result<string, GenericDist_Types.error>
|
||||
type floatResult= result<float, error>
|
||||
|
||||
let mean = (~env, dist) => run(~env, C.mean(dist))->toFloatR
|
||||
let sample = (~env, dist) => run(~env, C.sample(dist))->toFloatR
|
||||
|
|
|
@ -4,19 +4,21 @@ type env = {
|
|||
xyPointLength: int,
|
||||
}
|
||||
|
||||
open GenericDist_Types
|
||||
|
||||
@genType
|
||||
type outputType =
|
||||
| Dist(GenericDist_Types.genericDist)
|
||||
| Dist(genericDist)
|
||||
| Float(float)
|
||||
| String(string)
|
||||
| GenDistError(GenericDist_Types.error)
|
||||
| GenDistError(error)
|
||||
|
||||
@genType
|
||||
let run: (~env: env, GenericDist_Types.Operation.genericFunctionCallInfo) => outputType
|
||||
let runFromDist: (
|
||||
~env: env,
|
||||
~functionCallInfo: GenericDist_Types.Operation.fromDist,
|
||||
GenericDist_Types.genericDist,
|
||||
genericDist,
|
||||
) => outputType
|
||||
let runFromFloat: (
|
||||
~env: env,
|
||||
|
@ -26,45 +28,70 @@ let runFromFloat: (
|
|||
|
||||
module Output: {
|
||||
type t = outputType
|
||||
let toDist: t => option<GenericDist_Types.genericDist>
|
||||
let toDistR: t => result<GenericDist_Types.genericDist, GenericDist_Types.error>
|
||||
let toDist: t => option<genericDist>
|
||||
let toDistR: t => result<genericDist, error>
|
||||
let toFloat: t => option<float>
|
||||
let toFloatR: t => result<float, GenericDist_Types.error>
|
||||
let toFloatR: t => result<float, error>
|
||||
let toString: t => option<string>
|
||||
let toStringR: t => result<string, GenericDist_Types.error>
|
||||
let toError: t => option<GenericDist_Types.error>
|
||||
let toStringR: t => result<string, error>
|
||||
let toError: t => option<error>
|
||||
let fmap: (~env: env, t, GenericDist_Types.Operation.singleParamaterFunction) => t
|
||||
}
|
||||
|
||||
module Constructors: {
|
||||
module UsingDists: {
|
||||
type dist = GenericDist_Types.genericDist
|
||||
type fResult = result<float, GenericDist_Types.error>
|
||||
type dResult = result<dist, GenericDist_Types.error>
|
||||
type sResult = result<string, GenericDist_Types.error>
|
||||
let mean: (~env: env, dist) => fResult
|
||||
let sample: (~env: env, dist) => fResult
|
||||
let cdf: (~env: env, dist, float) => fResult
|
||||
let inv: (~env: env, dist, float) => fResult
|
||||
let pdf: (~env: env, dist, float) => fResult
|
||||
let normalize: (~env: env, dist) => dResult
|
||||
let toPointSet: (~env: env, dist) => dResult
|
||||
let toSampleSet: (~env: env, dist, int) => dResult
|
||||
let truncate: (~env: env, dist, option<float>, option<float>) => dResult
|
||||
let inspect: (~env: env, dist) => dResult
|
||||
let toString: (~env: env, dist) => sResult
|
||||
let toSparkline: (~env: env, dist, int) => sResult
|
||||
let algebraicAdd: (~env: env, dist, dist) => dResult
|
||||
let algebraicMultiply: (~env: env, dist, dist) => dResult
|
||||
let algebraicDivide: (~env: env, dist, dist) => dResult
|
||||
let algebraicSubtract: (~env: env, dist, dist) => dResult
|
||||
let algebraicLogarithm: (~env: env, dist, dist) => dResult
|
||||
let algebraicExponentiate: (~env: env, dist, dist) => dResult
|
||||
let pointwiseAdd: (~env: env, dist, dist) => dResult
|
||||
let pointwiseMultiply: (~env: env, dist, dist) => dResult
|
||||
let pointwiseDivide: (~env: env, dist, dist) => dResult
|
||||
let pointwiseSubtract: (~env: env, dist, dist) => dResult
|
||||
let pointwiseLogarithm: (~env: env, dist, dist) => dResult
|
||||
let pointwiseExponentiate: (~env: env, dist, dist) => dResult
|
||||
@genType
|
||||
let mean: (~env: env, genericDist) => result<float, error>
|
||||
@genType
|
||||
let sample: (~env: env, genericDist) => result<float, error>
|
||||
@genType
|
||||
let cdf: (~env: env, genericDist, float) => result<float, error>
|
||||
@genType
|
||||
let inv: (~env: env, genericDist, float) => result<float, error>
|
||||
@genType
|
||||
let pdf: (~env: env, genericDist, float) => result<float, error>
|
||||
@genType
|
||||
let normalize: (~env: env, genericDist) => result<genericDist, error>
|
||||
@genType
|
||||
let toPointSet: (~env: env, genericDist) => result<genericDist, error>
|
||||
@genType
|
||||
let toSampleSet: (~env: env, genericDist, int) => result<genericDist, error>
|
||||
@genType
|
||||
let truncate: (
|
||||
~env: env,
|
||||
genericDist,
|
||||
option<float>,
|
||||
option<float>,
|
||||
) => result<genericDist, error>
|
||||
@genType
|
||||
let inspect: (~env: env, genericDist) => result<genericDist, error>
|
||||
@genType
|
||||
let toString: (~env: env, genericDist) => result<string, error>
|
||||
@genType
|
||||
let toSparkline: (~env: env, genericDist, int) => result<string, error>
|
||||
@genType
|
||||
let algebraicAdd: (~env: env, genericDist, genericDist) => result<genericDist, error>
|
||||
@genType
|
||||
let algebraicMultiply: (~env: env, genericDist, genericDist) => result<genericDist, error>
|
||||
@genType
|
||||
let algebraicDivide: (~env: env, genericDist, genericDist) => result<genericDist, error>
|
||||
@genType
|
||||
let algebraicSubtract: (~env: env, genericDist, genericDist) => result<genericDist, error>
|
||||
@genType
|
||||
let algebraicLogarithm: (~env: env, genericDist, genericDist) => result<genericDist, error>
|
||||
@genType
|
||||
let algebraicExponentiate: (~env: env, genericDist, genericDist) => result<genericDist, error>
|
||||
@genType
|
||||
let pointwiseAdd: (~env: env, genericDist, genericDist) => result<genericDist, error>
|
||||
@genType
|
||||
let pointwiseMultiply: (~env: env, genericDist, genericDist) => result<genericDist, error>
|
||||
@genType
|
||||
let pointwiseDivide: (~env: env, genericDist, genericDist) => result<genericDist, error>
|
||||
@genType
|
||||
let pointwiseSubtract: (~env: env, genericDist, genericDist) => result<genericDist, error>
|
||||
@genType
|
||||
let pointwiseLogarithm: (~env: env, genericDist, genericDist) => result<genericDist, error>
|
||||
@genType
|
||||
let pointwiseExponentiate: (~env: env, genericDist, genericDist) => result<genericDist, error>
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,3 +164,63 @@ module Constructors = {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
module DistVariant = {
|
||||
type t =
|
||||
| Mean(genericDist)
|
||||
| Sample(genericDist)
|
||||
| Cdf(genericDist, float)
|
||||
| Inv(genericDist, float)
|
||||
| Pdf(genericDist, float)
|
||||
| Normalize(genericDist)
|
||||
| ToPointSet(genericDist)
|
||||
| ToSampleSet(genericDist, int)
|
||||
| Truncate(genericDist, option<float>, option<float>)
|
||||
| Inspect(genericDist)
|
||||
| ToString(genericDist)
|
||||
| ToSparkline(genericDist, int)
|
||||
| AlgebraicAdd(genericDist, genericDist)
|
||||
| AlgebraicMultiply(genericDist, genericDist)
|
||||
| AlgebraicDivide(genericDist, genericDist)
|
||||
| AlgebraicSubtract(genericDist, genericDist)
|
||||
| AlgebraicLogarithm(genericDist, genericDist)
|
||||
| AlgebraicExponentiate(genericDist, genericDist)
|
||||
| PointwiseAdd(genericDist, genericDist)
|
||||
| PointwiseMultiply(genericDist, genericDist)
|
||||
| PointwiseDivide(genericDist, genericDist)
|
||||
| PointwiseSubtract(genericDist, genericDist)
|
||||
| PointwiseLogarithm(genericDist, genericDist)
|
||||
| PointwiseExponentiate(genericDist, genericDist)
|
||||
|
||||
let toGenericFunctionCallInfo = (t: t) =>
|
||||
switch t {
|
||||
| Mean(d) => Operation.FromDist(ToFloat(#Mean), d)
|
||||
| Sample(d) => FromDist(ToFloat(#Mean), d)
|
||||
| Cdf(d, f) => FromDist(ToFloat(#Cdf(f)), d)
|
||||
| Inv(d, f) => FromDist(ToFloat(#Inv(f)), d)
|
||||
| Pdf(d, f) => FromDist(ToFloat(#Pdf(f)), d)
|
||||
| Normalize(d) => FromDist(ToDist(Normalize), d)
|
||||
| ToPointSet(d) => FromDist(ToDist(ToPointSet), d)
|
||||
| ToSampleSet(d, r) => FromDist(ToDist(ToSampleSet(r)), d)
|
||||
| Truncate(d, left, right) => FromDist(ToDist(Truncate(left, right)), d)
|
||||
| Inspect(d) => FromDist(ToDist(Inspect), d)
|
||||
| ToString(d) => FromDist(ToString(ToString), d)
|
||||
| ToSparkline(d, n) => FromDist(ToString(ToSparkline(n)), d)
|
||||
| AlgebraicAdd(d1, d2) => FromDist(ToDistCombination(Algebraic, #Add, #Dist(d2)), d1)
|
||||
| AlgebraicMultiply(d1, d2) => FromDist(ToDistCombination(Algebraic, #Multiply, #Dist(d2)), d1)
|
||||
| AlgebraicDivide(d1, d2) => FromDist(ToDistCombination(Algebraic, #Divide, #Dist(d2)), d1)
|
||||
| AlgebraicSubtract(d1, d2) => FromDist(ToDistCombination(Algebraic, #Subtract, #Dist(d2)), d1)
|
||||
| AlgebraicLogarithm(d1, d2) =>
|
||||
FromDist(ToDistCombination(Algebraic, #Logarithm, #Dist(d2)), d1)
|
||||
| AlgebraicExponentiate(d1, d2) =>
|
||||
FromDist(ToDistCombination(Algebraic, #Exponentiate, #Dist(d2)), d1)
|
||||
| PointwiseAdd(d1, d2) => FromDist(ToDistCombination(Pointwise, #Add, #Dist(d2)), d1)
|
||||
| PointwiseMultiply(d1, d2) => FromDist(ToDistCombination(Pointwise, #Multiply, #Dist(d2)), d1)
|
||||
| PointwiseDivide(d1, d2) => FromDist(ToDistCombination(Pointwise, #Divide, #Dist(d2)), d1)
|
||||
| PointwiseSubtract(d1, d2) => FromDist(ToDistCombination(Pointwise, #Subtract, #Dist(d2)), d1)
|
||||
| PointwiseLogarithm(d1, d2) =>
|
||||
FromDist(ToDistCombination(Pointwise, #Logarithm, #Dist(d2)), d1)
|
||||
| PointwiseExponentiate(d1, d2) =>
|
||||
FromDist(ToDistCombination(Pointwise, #Exponentiate, #Dist(d2)), d1)
|
||||
}
|
||||
}
|
|
@ -12,3 +12,10 @@ type error = GenericDist_Types.error;
|
|||
|
||||
@genType
|
||||
let runDistributionOperation = DistributionOperation.run;
|
||||
|
||||
@genType
|
||||
type resultDist = result<genericDist, error>
|
||||
@genType
|
||||
type resultFloat = result<float, error>
|
||||
@genType
|
||||
type resultString = result<string, error>
|
Loading…
Reference in New Issue
Block a user