tweak: save intermediary state

This commit is contained in:
NunoSempere 2022-09-05 20:52:23 +02:00
parent 8bdfa03799
commit 70d9a5c9f3

View File

@ -279,7 +279,7 @@ module Internals = {
optimalAllocationResult optimalAllocationResult
} }
let diminishingMarginalReturnsForManyFunctions = ( let diminishingMarginalReturnsForManyFunctions = (
innerLambdas, lambdas,
funds, funds,
approximateIncrement, approximateIncrement,
environment, environment,
@ -290,19 +290,7 @@ module Internals = {
1. O(n): Iterate through value on next n dollars. At each step, only compute the new marginal return of the function which is spent 1. O(n): Iterate through value on next n dollars. At each step, only compute the new marginal return of the function which is spent
2. O(n*m): Iterate through all possible spending combinations. Fun is, it doesn't assume that the returns of marginal spending are diminishing. 2. O(n*m): Iterate through all possible spending combinations. Fun is, it doesn't assume that the returns of marginal spending are diminishing.
*/ */
let individuallyWrappedLambdas = E.A.fmap(possibleLambda => let applyFunctionAtFloatToFloatOption = (lambda, point: float) => {
switch possibleLambda {
| ReducerInterface_InternalExpressionValue.IEvLambda(lambda) => Ok(lambda)
| _ =>
Error(
"Error in diminishingMarginalReturnsForManyFunctions: One of the elements in the function array is not a function",
)
}
, innerLambdas)
let collectivelyWrappedLambdas = E.A.R.firstErrorOrOpen(individuallyWrappedLambdas)
let result = switch collectivelyWrappedLambdas {
| Ok(lambdas) => {
let applyFunctionAtFloatToFloatOption = (lambda, point: float) => {
// Defined here so that it has access to environment, reducer // Defined here so that it has access to environment, reducer
let pointAsInternalExpression = castFloatToInternalNumber(point) let pointAsInternalExpression = castFloatToInternalNumber(point)
let resultAsInternalExpression = Reducer_Expression_Lambda.doLambdaCall( let resultAsInternalExpression = Reducer_Expression_Lambda.doLambdaCall(
@ -321,6 +309,8 @@ module Internals = {
} }
result result
} }
/*
let numDivisions = Js.Math.round(funds /. approximateIncrement) let numDivisions = Js.Math.round(funds /. approximateIncrement)
let numDivisionsInt = Belt.Float.toInt(numDivisions) let numDivisionsInt = Belt.Float.toInt(numDivisions)
let increment = funds /. numDivisions let increment = funds /. numDivisions
@ -378,13 +368,9 @@ module Internals = {
| Ok(inner) => Ok(castArrayOfFloatsToInternalArrayOfInternals(inner.optimalAllocations)) | Ok(inner) => Ok(castArrayOfFloatsToInternalArrayOfInternals(inner.optimalAllocations))
| Error(b) => Error(b) | Error(b) => Error(b)
} }
optimalAllocationResult // optimalAllocationResult
/*let result = [0.0, 0.0]->castArrayOfFloatsToInternalArrayOfInternals->Ok */
result*/ let result = [0.0, 0.0]->castArrayOfFloatsToInternalArrayOfInternals->Ok
}
| Error(b) => Error(b)
}
result result
} }
} }
@ -600,22 +586,42 @@ let library = [
~output=EvtArray, ~output=EvtArray,
~requiresNamespace=false, ~requiresNamespace=false,
~examples=[ ~examples=[
`Danger.diminishingMarginalReturnsForManyFunctions([{|x| x+1}, {|y| 10} , {|z| 20 - 2*z}], 100, 0.01)`, `Danger.diminishingMarginalReturnsForManyFunctions([{|x| x+1}, {|y| 10}], 100, 0.01)`,
], ],
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
~name="diminishingMarginalReturnsForManyFunctions", ~name="diminishingMarginalReturnsForManyFunctions",
~inputs=[FRTypeArray(FRTypeLambda), FRTypeNumber, FRTypeNumber], ~inputs=[FRTypeArray(FRTypeLambda), FRTypeNumber, FRTypeNumber],
~run=(inputs, _, env, reducer) => ~run=(inputs, _, environment, reducer) =>
switch inputs { switch inputs {
| [IEvArray(innerlambdas), IEvNumber(funds), IEvNumber(approximateIncrement)] => | [IEvArray(innerlambdas), IEvNumber(funds), IEvNumber(approximateIncrement)] => {
Internals.diminishingMarginalReturnsForManyFunctions( /*let individuallyWrappedLambdas = E.A.fmap(innerLambda => {
innerlambdas, switch innerLambda {
funds, | ReducerInterface_InternalExpressionValue.IEvLambda(lambda) => Ok(lambda)
approximateIncrement, | _ =>
env, Error(
reducer, "Error in Danger.diminishingMarginalReturnsForManyFunctions. A member of the array wasn't a function",
) )
}
}, innerlambdas)
let wrappedLambdas = E.A.R.firstErrorOrOpen(individuallyWrappedLambdas)
let result = switch wrappedLambdas {
| Ok(lambdas) => {
let result = Internals.diminishingMarginalReturnsForManyFunctions(
lambdas,
funds,
approximateIncrement,
environment,
reducer,
)
result
}
| Error(b) => Error(b)
}
result
*/
Error("wtf man")
}
| _ => Error("Error in Danger.diminishingMarginalReturnsForTwoFunctions") | _ => Error("Error in Danger.diminishingMarginalReturnsForTwoFunctions")
}, },
(), (),
@ -623,4 +629,39 @@ let library = [
], ],
(), (),
), ),
/*
Function.make(
~name="diminishingMarginalReturnsForManyFunctions",
~nameSpace,
~output=EvtArray,
~requiresNamespace=false,
~examples=[
`Danger.diminishingMarginalReturnsForManyFunctions([{|x| x+1}, {|y| 10}, {|z| 20 - 2*z}], 100, 0.01)`,
],
~definitions=[
FnDefinition.make(
~name="diminishingMarginalReturnsForManyFunctions",
~inputs=[FRTypeArray(FRTypeLambda), FRTypeNumber, FRTypeNumber],
~run=(inputs, _, env, reducer) =>
switch inputs {
| [IEvArray(innerlambdas), IEvNumber(funds), IEvNumber(approximateIncrement)] => {
let result = [0.0, 0.0]->Internals.castArrayOfFloatsToInternalArrayOfInternals->Ok
result
}
/*
Internals.diminishingMarginalReturnsForManyFunctions(
innerlambdas,
funds,
approximateIncrement,
env,
reducer,
)*/
| _ => Error("Error in Danger.diminishingMarginalReturnsForManyFunctions")
},
(),
),
],
(),
),*/
] ]