# How should I inverse of the Normal loss function L(z) to be able to implement this in software?

I have a question related to this question:

How to inverse loss function L(z) to normal standard distribution (z)

The question wasn't answered since it wasn't clear what was asked. However I know what the person tried to ask:

In inventory management, the fill rate is a very common measure of service level. When one wants to calculate a safety stock based on this measure and historical/forecasted data, one has to find the safety factor z for which:

L(z) = EOQ*(1−Target fill rate)/σ

Usually in companies, the target fill rate is determined first, and then the safety factor is calculated, because in contracts there are service level agreements.

However for the Normal loss function L(z), there exist no explicit inverse. So how can I find a value for z that satisfies my target fill rate?

One solution can be to estimate the value of z using tables with pre-calculated values using interpolation just like the table here: In this table, the vertical axis shows the first integer and decimal of z, and the horizontal axis represents the second decimal.

Another solution I could think of is to try to create some kind of goal-seeking algorithm that uses the Normal loss function and with an arbitrary number of iterations tries to determine z while it approaches the target fill rate. Obviously computation time here is a limiting factor.

Does anyone have any alternative solutions?

• NB: it appears that the "Normal loss function" may be intended to mean $$L(z)=\phi(z)-z(1-\Phi(z))$$ where $\Phi$ is the standard Normal distribution and $\phi$ is its density. Inverting such (monotonic, smooth) functions is routine: it's called root finding. The good news is you don't have to create any kind of "goal-seeking algorithm," because many accurate and efficient ones have been invented, described, and embodied in software. – whuber Jun 16 '17 at 14:05
• @whuber this is exactly what I am looking for! Thanks a lot – user3707455 Jun 17 '17 at 14:50

You can see a full solution in the Numerical Approximation of the Inverse Standardized Loss Function for Inventory Control Subject to Uncertain Demand paper published at Canadian Operations Research Society Conference 2016. Since there is no direct inverse solution, you can curve fit, and in this case a log transformed polynomial is used with better performance than other estimation techniques:  Here is an implementation in Python:

import numpy as np
import math as mt
coefficients = [ 4.41738119e-09, 1.79200966e-07, 3.01634229e-06,
2.63537452e-05, 1.12381749e-04,   5.71289020e-06,
-2.64198510e-03,  -1.59986142e-02, -5.60399292e-02,
-1.48968884e-01, -3.68776346e-01, -1.22551895e+00,
-8.99375602e-01]
def inverse_standard_loss(L):
x = mt.log(L)
z = np.polyval(coefficients, x)
return z


The full iterative solution in Python:

import scipy.stats as st
#Initialize Intermediate variables Qinter = 0
Rinter = 0
Rafter = 1
#Estimate Q with EOQ
Qafter = mt.sqrt(2.0*K*lamb/h)
while (round(Qinter)!= round(Qafter)
and round(Rinter)!= round(Rafter)): #Set n(R)
n_R = (1-beta)*Qafter #Calculate L(z)
L_z = n_R/sigma
#Find Z-score
Zn = inverse_standard_loss(L_z) #Find 1-F(z)
One_F = 1-st.norm.cdf(Zn) #Store previous R and Q
Rinter = Rafter
Qinter = Qafter
#Find new R
Rafter = sigma * Zn + mu #Find new Q
Qafter = n_R/One_F + mt.sqrt(2*K*lamb/h+(n_R/One_F)*(n_R/One_F))
#Display Results
print "R optimal = " + str(round(Rafter))
print "Q optimal = " + str(round(Qafter))


use the following formula: 4.85-(L(z)^1.3)*0.3924-(L(z)^0.135)5.359 in excel. This will yield the z-value from the L(z) value (=Q(1-s)/sigma*sqrt(leadtime))