Skip to content

LightModel

heavylight.LightModel ¤

Inheriting from this class causes functions starting with a lowercase letter to be cached. The caches can be cleared to rerun the same instance with different data. This model can be memory optimized to reduce the memory requirements of the model without impacting results or performance.

cache property ¤

This is the cache of the model. It is a dictionary of dictionaries. The outer dictionary is keyed by the function name and the inner dictionary is keyed by the arguments.

cache_agg property ¤

The cache property with the agg_function applied to the results.

df property ¤

A dataframe with the cache values of all functions that have a single parameter t.

df_agg property ¤

The df property dataframe with the agg_function applied to the results.

__init__(agg_function: Union[Callable, None] = default_agg_function) ¤

Arguments

agg_function: Aggregation function for storing results. This function is applied to the return values of each method. In memory optimized models the cache is cleared but the aggregated results are stored for reporting. If agg_function is not provided, the default aggregation function is used. If agg_function is None, no aggregated results will be provided unless overridden at a method level with agg.

The implementation of the default aggregation function is as follows:

def default_agg_function(x: Any):
    if isinstance(x, np.ndarray) and issubclass(x.dtype.type, np.number):
        return np.sum(x)
    return x

RunModel(proj_len: int) ¤

Arguments

  • proj_len: Projection length. All single parameter timestep functions will be run for each timestep in range(proj_len + 1).

Clear() ¤

Clears the cache. If the model was memory optimized, it is no longer memory optimized.

ClearOptimize() ¤

Clears the cache. The model is memory optimized after this function is called.

heavylight.agg(agg_function: Union[Callable, None]) ¤

Register the storage function of a method.

Used for storing aggregated results before cache eviction to reduce memory consumption.