Added simple interface files

This commit is contained in:
Ozzie Gooen 2022-03-28 08:39:07 -04:00
parent 04abeb7cd1
commit 6f11e87c0a
6 changed files with 70 additions and 21 deletions

View File

@ -1,9 +1,10 @@
//TODO: multimodal, add interface, test somehow, track performance, refactor sampleSet, refactor ASTEvaluator.res. //TODO: multimodal, add interface, test somehow, track performance, refactor sampleSet, refactor ASTEvaluator.res.
type genericDist = GenericDist_Types.genericDist type t = GenericDist_Types.genericDist
type error = GenericDist_Types.error type error = GenericDist_Types.error
type toPointSetFn = genericDist => result<PointSetTypes.pointSetDist, error> type toPointSetFn = t => result<PointSetTypes.pointSetDist, error>
type toSampleSetFn = genericDist => result<array<float>, error> type toSampleSetFn = t => result<array<float>, error>
type t = genericDist type scaleMultiplyFn = (t, float) => result<t, error>
type pointwiseAddFn = (t, t) => result<t, error>
let sampleN = (n, t: t) => let sampleN = (n, t: t) =>
switch t { switch t {
@ -28,7 +29,7 @@ let normalize = (t: t) =>
| #SampleSet(_) => t | #SampleSet(_) => t
} }
let operationToFloat = (toPointSet: toPointSetFn, fnName, t: genericDist): result<float, error> => { let operationToFloat = (toPointSet: toPointSetFn, fnName, t) => {
let symbolicSolution = switch t { let symbolicSolution = switch t {
| #Symbolic(r) => | #Symbolic(r) =>
switch SymbolicDist.T.operate(fnName, r) { switch SymbolicDist.T.operate(fnName, r) {
@ -220,9 +221,9 @@ let pointwiseCombinationFloat = (
} }
let mixture = ( let mixture = (
scaleMultiply: (genericDist, float) => result<genericDist, error>, scaleMultiply: scaleMultiplyFn,
pointwiseAdd: (genericDist, genericDist) => result<genericDist, error>, pointwiseAdd: pointwiseAddFn,
values: array<(genericDist, float)>, values: array<(t, float)>,
) => { ) => {
if E.A.length(values) == 0 { if E.A.length(values) == 0 {
Error(GenericDist_Types.Other("mixture must have at least 1 element")) Error(GenericDist_Types.Other("mixture must have at least 1 element"))

View File

@ -0,0 +1,44 @@
type t = GenericDist_Types.genericDist
type error = GenericDist_Types.error
type toPointSetFn = t => result<PointSetTypes.pointSetDist, error>
type toSampleSetFn = t => result<array<float>, error>
type scaleMultiplyFn = (t, float) => result<t, error>
type pointwiseAddFn = (t, t) => result<t, error>
let sampleN: (int, t) => result<array<float>, error>
let fromFloat: float => t
let toString: t => string
let normalize: t => t
let operationToFloat: (toPointSetFn, Operation.distToFloatOperation, t) => result<float, error>
let toPointSet: (int, t) => result<PointSetTypes.pointSetDist, error>
let truncate: (toPointSetFn, option<float>, option<float>, t) => result<t, error>
let algebraicCombination: (
toPointSetFn,
toSampleSetFn,
GenericDist_Types.Operation.arithmeticOperation,
t,
t,
) => result<t, error>
let pointwiseCombination: (
toPointSetFn,
GenericDist_Types.Operation.arithmeticOperation,
t,
t,
) => result<t, error>
let pointwiseCombinationFloat: (
toPointSetFn,
GenericDist_Types.Operation.arithmeticOperation,
float,
t,
) => result<t, error>
let mixture: (scaleMultiplyFn, pointwiseAddFn, array<(t, float)>) => result<t, error>

View File

@ -1,4 +1,4 @@
type operation = GenericDist_Types.Operation.genericFunction type operation = GenericDist_Types.Operation.genericFunctionCall
type genericDist = GenericDist_Types.genericDist type genericDist = GenericDist_Types.genericDist
type error = GenericDist_Types.error type error = GenericDist_Types.error
@ -9,14 +9,6 @@ type params = {
xyPointLength: int, xyPointLength: int,
} }
let genericParams = {
sampleCount: 1000,
xyPointLength: 1000,
}
type wrapped = (genericDist, params)
let wrapWithParams = (g: genericDist, f: params): wrapped => (g, f)
type outputType = [ type outputType = [
| #Dist(genericDist) | #Dist(genericDist)
| #Error(error) | #Error(error)
@ -82,7 +74,7 @@ let rec run = (extra, fnName: operation): outputType => {
| #toDist(#normalize) => dist |> GenericDist.normalize |> (r => #Dist(r)) | #toDist(#normalize) => dist |> GenericDist.normalize |> (r => #Dist(r))
| #toDist(#truncate(left, right)) => | #toDist(#truncate(left, right)) =>
dist dist
|> GenericDist.Truncate.run(toPointSet, left, right) |> GenericDist.truncate(toPointSet, left, right)
|> E.R.fmap(r => #Dist(r)) |> E.R.fmap(r => #Dist(r))
|> fromResult |> fromResult
| #toDist(#toPointSet) => | #toDist(#toPointSet) =>
@ -95,7 +87,7 @@ let rec run = (extra, fnName: operation): outputType => {
| #toDistCombination(#Algebraic, _, #Float(_)) => #Error(NotYetImplemented) | #toDistCombination(#Algebraic, _, #Float(_)) => #Error(NotYetImplemented)
| #toDistCombination(#Algebraic, operation, #Dist(dist2)) => | #toDistCombination(#Algebraic, operation, #Dist(dist2)) =>
dist dist
|> GenericDist.AlgebraicCombination.run(toPointSet, toSampleSet, operation, dist2) |> GenericDist.algebraicCombination(toPointSet, toSampleSet, operation, dist2)
|> E.R.fmap(r => #Dist(r)) |> E.R.fmap(r => #Dist(r))
|> fromResult |> fromResult
| #toDistCombination(#Pointwise, operation, #Dist(dist2)) => | #toDistCombination(#Pointwise, operation, #Dist(dist2)) =>

View File

@ -0,0 +1,13 @@
type params = {
sampleCount: int,
xyPointLength: int,
}
type outputType = [
| #Dist(GenericDist_Types.genericDist)
| #Error(GenericDist_Types.error)
| #Float(float)
| #String(string)
]
let run: (params, GenericDist_Types.Operation.genericFunctionCall) => outputType

View File

@ -61,7 +61,7 @@ module Operation = {
| #toString | #toString
] ]
type genericFunction = [ type genericFunctionCall = [
| #fromDist(fromDist, genericDist) | #fromDist(fromDist, genericDist)
| #fromFloat(fromDist, float) | #fromFloat(fromDist, float)
| #mixture(array<(genericDist, float)>) | #mixture(array<(genericDist, float)>)

View File

@ -33,7 +33,6 @@ graph TD
## Todo ## Todo
- [ ] Lots of cleanup - [ ] Lots of cleanup
- [ ] Add interface files
- [ ] Simple test story - [ ] Simple test story
- [ ] Provide decent stack traces for key calls in GenericOperation. This could be very useful for debugging. - [ ] Provide decent stack traces for key calls in GenericOperation. This could be very useful for debugging.
- [ ] Cleanup Sample Set library - [ ] Cleanup Sample Set library