Function Variables

For more information, see the online learning platform

Function Variables help create new features based on existing variables.

All variables can’t be measured or won’t exist in the data set. The use of function variables will help to bring additional information into the data set. There are many options, so be creative!

For example, if you want to transform a numerical KPI into a symbolic representation, such as quality levels: low, medium, high.

You can also define thresholds, for example if the variable Temp1 is greater than 25 degrees, it is Hot, otherwise Cold. This would be defined in the JavaScript editor as:

if (val("Temp1") > 25) { "Hot"} else {"Cold"}

To create a function variable:

  1. Click TransformFunction variable in the menu.

  2. Enter a function Name for the new function variable, for example: Temperature-Average.

  3. Enter a Title. If there is a title the function name is displayed as: Function Name - Title. 

  4. Enter a Unit, for example: deg. C. 

  5. Select the appropriate Output type: Numeric or Symbolic.

  6. Select Language for the script. Options: JavaScript, Common Lisp, R or Python. 

  7. Enter a function Script and add variable from the list as required (Item selection) and click on the Arrow to put them in the script area. 

    The standard Script is executed for each row, the result is the last evaluated expression.

  8. Click on Template and select from the list of template functions. On the left part of the window, you can see the function. Then click Insert  and the script example will be written on the script area. The templates are only available in Javascript

  9. Click Save.

Function Initializer

The Function Initializer is executed only once, and is intended to put some calculations available for each row such as global counter.

 

Here there are some of the templates available on the Function Variable.

var a = val("VAR1"); var b = val("VAR2"); a + b + 200;

 

var a = val("VAR1"); var b = val("VAR2"); a - b - 200;

 

val("VAR1") * val("VAR2") * 1000

val("VAR1") / val("VAR2") / 1000

 

Lisp Language

Function variables can be written in Common Lisp in the editor. For more information on Common Lisp, see Common Lisp.

Javascript language

Function variables can be written in JavaScript in the editor. Several template examples are shown above. For more information on Javascript, see JavaScript.

Note: Some model (linear regression and decision trees, for example) can be exported as function variables.

Python language

Function variables can be written in Python in the editor. For more information on Python, see Python.

R language

Function variables can be written in R in the editor. For more information on R, see R.

Note: val (& valEx) method are available in the 3 languages and return the specified variable value of the current row

External libraries 

In order to compute function variables, several external libraries are included in DATAmaestro Analytics. IF97 is used to compute steam/water properties and CoolProp library is used to computes properties of fluid and humid air.

IF97 library

This library provides steam tables for industrial use according to the international standard for the properties of water and steam, the IAPWS-IF97 formulation and the international standards for transport and other properties. 

Example of IF97 code

The if97 library uses the Engineering units system. Units that are commonly used in process engineering practice. There is also the possibility of using the library if97_IMP that uses the British Imperial system of units. For more information about the Refer Unit System, see IF97.UnitSystem

For more information, see Javadoc IF97 library

Check some of the templates below:

 

Coolprop library

CoolProp is an open-source database of fluid and humid air properties, formulated based on the most accurate formulations in open literature. It has been validated against the most accurate data available from the relevant references.

CoolProp is a library that implements:

Example of Coolprop code

Other examples on how to use the "Coolprop" library are available here  Examples of using CoolProp library

A paper covering CoolProp has been published in the Journal Industrial & Engineering Chemistry Research (link to paper) with an OpenAccess license.