API Reference

verify_target

monad.ui.target_function.verify_target

monad.ui.target_function.verify_target(target_fn, fm_checkpoint_path, task, data_params_overrides=None, num_percentage_entities=1, percentage_nones_allowed=90, log_every_n_steps=None, limit=None)

Validates the target function output to ensure it runs without errors and returns exactly the target its author intended, before executing the entire downstream task of scenario modeling.

Does exactly that:

  • In case of errors, it will raise one of the following types:
    • TypeError: if return types are incorrect or inconsistent.
    • ValueError: if percentage_nones_allowed evaluation returns None.
    • RuntimeError: if running the target function fails.
  • If the validation proceeds without errors, the function will return an example target.

from typing import Dict

import numpy as np

from monad.ui.module import RegressionTask
from monad.ui.target_function import Attributes, Events, verify_target

def ltv_target_fn(
    history: Events, future: Events, entity: Attributes, ctx: Dict  # pylint: disable=unused-argument
) -> np.ndarray:
    sum_purchase = future["transactions"].count()
    return np.array([sum_purchase], dtype=np.float64)

foundation_model_path = "path/to/fm"

verify_target(target_fn=ltv_target_fn, fm_checkpoint_path=foundation_model_path, task=RegressionTask)

Parameters

target_fn : Callable[[ Events, Events, Attributes, dict[str, float]], np.ndarray | tuple[np.ndarray, np.ndarray] | Sketch| tuple[Sketch, Sketch] | None]
Target function to evaluate.


fm_checkpoint_path: str | Path
Path to FM checkpoint.


task: Task
Task for which the target function will be applied.


data_params_overrides: DataParams | None
Default: None
Overrides for data parameters.


num_percentage_entities: int
Default: 1
Percentage of all entites to validate target_fn against.


percentage_nones_allowed: int
Default: 90
Allowed percentage of invalid targets.


log_every_n_steps: int | None
Default: None
Whether to print a log every log_every_n_steps evaluated entities.


limit: int | None
Default: None
If set, validation will stop after processing limit entities.

Returns

numpy.ndarray with example target if function works correctly.