Solved

Is there a transformer that will calculate the Cumulative Normal Distribution similar to the NORM.DIST() function in Excel?

  • 3 September 2020
  • 2 replies
  • 8 views

Userlevel 1
Badge +6

The Excel function takes the inputs NORM.DIST(x, mean, standard deviation) where x is the value that you want to calculate the cumulative normal distribution for. I intend to use 0 for the mean and 1 for the standard deviation (i.e. the standard normal distribution).

 

I've looked through the StatisticsCalculator as well as the Math Functions in the ExpressionEvaluator but I don't see anything like it in those transformers.

 

This is related to this post where they are attempting to do the inverse: https://community.safe.com/s/question/0D54Q000080hEk3SAE/is-there-a-function-to-calculate-inverse-normal-cumulative-distribution?t=1599138666050

 

In that post the solution was to use PythonCaller and I am planning to follow that solution but wanted to see if I could use a standard FME transformer to complete this calculation instead.

icon

Best answer by sammy 16 September 2020, 21:49

View original

2 replies

Badge

Hi @sammy​ 

From what I can tell I do not think we have any transformer that currently calculates Cumulative Normal Distribution, but this could be an interesting feature to post to the Ideas page if it gains enough support the dev team may add it to future versions of FME.

Let us know if you are successful using the PythonCaller method.

Thanks, Daragh

 

 

Userlevel 1
Badge +6

I was able to do the calculations using a PythonCaller transformer and the python norm.cdf() function from scipy stats.

 

I wanted to calculate the Standard Cumulative Normal Distribution (i.e. the Cumulative Normal Distribution with mean = 0 and standard deviation = 1) so I only had to input my value that I wanted the function calculated for. I did not need to specify the mean or the standard deviation.

 

More info if you need to specify the mean or standard deviation can be found here:

https://stackoverflow.com/questions/809362/how-to-calculate-cumulative-normal-distribution

 

 

Here are the details about the workflow - 

2020-09-16_13-46-32

 

 

ExcelReader:

  • Pulling from an Excel sheet with sample data in a column called "input"

PythonCaller:

2020-09-16_14-30-40

 

  • Left the "Class or Funtion to Process Features" as the default "processFeature" - if you change this you will need to change it on line 5 in the python script below.
  • Used norm.cdf() and selected "input" from FME Feature Attributes (to run the calculation my values from the Excel sheet).
  • Assigned the calculated value to a new attribute called "result"
  • Included "result" in Output Attributes, Attributes to Expose (so that I can use it for further calculations and/or output it).
  • Script for the PythonCaller:
import fme
import fmeobjects
from scipy.stats import norm
 
def processFeature(feature):
    result = norm.cdf(feature.getAttribute('input'))
    feature.setAttribute("result", result)
    pass

Python Compatibility:

  • In the Navigator window -> Workspace Parameters -> Scripting ->Python Compatibility; Double click and change to match the python version installed on your computer.

 

Before I ran the workflow I had to install scipy into this folder (with my username and python version number e.g. python 3.7 would be python37) - C:\Users\<username>\Documents\FME\Plugins\Python\python<major><minor> 

More instructions here:

https://docs.safe.com/fme/html/FME_Desktop_Documentation/FME_Workbench/Workbench/Installing-Python-Packages.htm

Reply