Terminology,

This page describes Typescript functions that are the building blocks for logic used in Vertex. In order to call Live-deployed models from within Functions on objects, refer to Functions on models.

Create Model Functions

Functions can be used to write a Model Function, which is logic within a model that estimates a set of outputs based on some inputs. This ModelFunction may be used throughout Vertex, Objectives, Scenarios, and the rest of the Foundry platform.

Model Functions are used to estimate some set of values based on an input set. These functions are pure functions, where evaluating the Model Function multiple times with the same inputs will always result in the same output values. Model Functions do not load data and the computation can be done entirely based on the set of inputs provided.

Terminology

The following are some terms that have specific meanings when using a Model Function:

  • Model - A Model is a set of logic that estimates some object properties based on others. This is considered to be a prediction of how values will change, rather than changes that will be enacted by the user.
  • Model Function – A Function that estimates a set of primitive outputs based on some primitive inputs. These functions have no side effects and load no data.

Usage of Model Functions

Model Functions have the following uses in Foundry:

  • Scenarios - Scenarios is the usage of Actions, overwrites, and Models to predict how changes may have effects throughout the Ontology. It enables the creation and comparison of "what-if" analyses using the objects in the Ontology and the ontological concept of a model. Any Model Function can be used as a model within a scenario.
  • Vertex - Vertex is a Foundry application used for systems modeling and simulation to predict how values will change. It allows the visualizing of object graphs when running simulations. Any Model Function can be configured and used to simulate values within Vertex.
  • Modeling Objectives - Modeling Objectives are a set of Models, data, and context used to solve specific organizational problem statements and operationalized outcomes. These are defined to run a model over some set of objects and will apply the model to each individual object. A Model Function can be used to apply the model to the objects.

How to write a Model Function

Model Functions differ from standard Functions in two key ways:

  • They are decorated with @ModelFunction() imported from @foundry/functions-api (rather than @Function())
  • The input and output types are limited to a subset of the types allowed in standard Functions

Any actions that can be performed on a standard Function can be performed on a Model Function, for example, testing in Live Preview, tagging and publishing. The Model Function can also be used in any contexts that a standard Function can be used.

model-functions-decorator

Supported inputs to Model Functions

Model Functions only support a subset of the available Functions types. The allowed types are primitive types, such as all Scalars, Optionals, and Collections. For Collection types, all objects within the collection must also be one of the allowed types. Notably, Model Functions do not support Aggregations, Ontology Types, or Notifications. In order to use values from an Object within a Model Function, you should have an input parameter for each property which you would like to use. When using this Model Function within another Foundry app, you will be able to specify which properties from an Object correspond to each parameter. This will be covered further in the tutorials below.

Supported outputs from Model Functions

Model Functions must output an anonymous custom type where each of the fields is one of the supported primitive types described above.

If a Model Function is written using a disallowed type, you will receive an error and the function will not be published:

model-functions-error

How to submit a Model to Modeling Objectives

This tutorial outlines how to submit a Model to Modeling Objectives.

How to configure a Model to be used in Vertex

This tutorial outlines how to configure a Model to be used in Vertex.