Hello,
I have a demand forecast implementation with the following code to determine the dispersion and also to predict the future demand based on the probability distribution of the past demand.
///Dispersion calculation-------------------------------------------------------------------------
ItemsWeek.IsPast = ItemsWeek.Monday < monday(todayForecast)
ItemsWeek.FutureWeekRank = 0
where not ItemsWeek.IsPast
ItemsWeek.FutureWeekRank = rank() by Items.Sku scan - ItemsWeek.Monday
ItemsWeek.One = dirac(1)
Items.Baseline = avg(ItemsWeek.Baseline) when (ItemsWeek.FutureWeekRank > 0)
Items.Alpha = if Items.Baseline < 10 then 0 else 0.05
ItemsWeek.RatioOfError = if ItemsWeek.Baseline != 0 then (ItemsWeek.Baseline - ItemsWeek.DemandQty) ^ 2 /. ItemsWeek.Baseline else 0
Items.AvgErrorRatio = avg(ItemsWeek.RatioOfError) when (ItemsWeek.IsPast)
Items.Dispersion = max(Items.AvgErrorRatio/2, 1)
And follow by the actionrwd.segment implementation for the future weeks prediction:
where ItemsWeek.FutureWeekRank > 0
Items.SLTDemand = actionrwd.segment(
TimeIndex: ItemsWeek.FutureWeekRank
BaseLine: ItemsWeek.Baseline
Dispersion: Items.Dispersion
Alpha: 0.05
Start: dirac(1)
Duration: Items.ActRwdSLT
Samples : 1500)
Items.WOODemand = actionrwd.segment(
TimeIndex: ItemsWeek.FutureWeekRank
BaseLine: ItemsWeek.Baseline
Dispersion: Items.Dispersion
Alpha: 0.05
Start: dirac(1)
Duration: dirac(Items.ActRwdReorderLeadTime)
Samples : 1500)
Items.TotalDemand = actionrwd.segment(
TimeIndex: ItemsWeek.FutureWeekRank
BaseLine: ItemsWeek.Baseline
Dispersion: Items.Dispersion
Alpha: 0.05
Start: dirac(1)
Duration: dirac(Items.ActRwdReorderLeadTime) + Items.ActRwdSLT
Samples : 1500)
What will cause the actionrwd.segment function to have dispersion value that is unreasonably high error? And what is the limit of the dispersion value that Envision allows?
Thank you and please let me know if you need more information to assist with this question.
Code before dispersion:
Continuing from the previous comment - For the same SKU, the values for SeasonalityModel, Profile1, level changed between two runs on different days. I am unsure what caused the change in these values - the input data remained the same.
Remark: I have edited your posts to add the Envision code formatting syntax, https://news.lokad.com/static/formatting
Envision is deterministic. You should not be able to re-run twice the same code over the same data and get different results.
Then, there is pseudo-randomness involved in functions like
actionrwd
. Thus, the seeding tend to be quite dependent on the exact fine-print of the code. If you change filters, for example, you are most likely going to end-up with different results.Thus, even seemingly "minor" code change can lead to a re-seeding behavior.
As a rule of thumb, if the logic breaks due to re-seeding, then the logic is friable and must be adjusted so that its validity does not depend on being lucky during the seeding of the random generators.
The dispersion of
actionrwd.foo
is controlled byDispersion:
. At line 13, in your script I see:This line implies that if there is 1 item (and only 1) that happens to have a super-large value, then, it will be applied for all items. This seems to be the root cause behind the high dispersion values that you are observing.
In particular,
Above,
ItemsWeek.RatioOfError
can get very very large. If the baseline is small, like 0.01, and the demand qty is 1, then this value can be 100+.Thus, my recommendations would be:
max
for the dispersionHope it helps.