跳转至

Function-backed time series(函数支持的时间序列(Function-backed time series))

:::callout{theme="neutral" title="Beta"} Function-backed time series are in the beta phase of development and may not be available on your enrollment. Functionality may change during active development. Contact Palantir Support to request access to Function-backed time series. :::

Function-backed time series enable you to generate and transform numeric time series using Python logic defined in a function. Foundry treats the function's output as a time series without the need to define a time series sync.

Capabilities

  • Custom analytics: Write Python functions that generate numeric time series. Use any libraries, such as statsmodels or Prophet, or use proprietary code to perform advanced analytics.
  • Direct integration in Foundry: Leverage function outputs directly in Quiver and apply operations such as resampling, formulas, joins, and time series search while ensuring compatibility and composability.
  • On-demand data access: Easily incorporate data from external APIs or services without pre-materializing data to enable rapid prototyping and dynamic analysis.
  • Parameterized scenarios: Pass custom inputs such as control settings or forecast horizons to compare multiple generated series side by side.
  • Scalable production workflow: Benefit from built-in result caching and streaming execution for handling large outputs while keeping interactions responsive.

In the example below, a function-backed time series is used in a Workshop module to compute weekly forecasts in real-time. An operator is able to simulate different scenarios for how changing a machine's controls affects the predicted performance forecast.

An animated demonstration of a function-backed time series being used in a forecasting and simulations Workshop module.

How it works

Function-backed time series require a Python Foundry function that returns a serialized numeric time series. When you query data, Quiver invokes your function with the specified parameters, dynamically generating the time series at query time. This output is then treated as a first-class time series within Foundry, allowing you to apply further operations and visualizations.

This integration makes it easy to incorporate custom models and on-the-fly analytics into your dashboards, enabling flexible and modular time series workflows.

Example use cases

  • Forecasting and simulation: Generate forecasts using the libraries of your choice, such as Prophet or statsmodels, or use models built in Foundry to analyze future trends and perform scenario planning.
  • Multivariate analysis: Combine outputs from several sensors or metrics to enable comprehensive time series analysis.
  • Rapid model iteration: Quickly iterate on custom models without managing intermediate datasets or data pipelines.

Example: Use Prophet for forecasting

The example below demonstrates how to use Prophet ↗ with function-backed time series for forecasting.

from functions.api import function
from timeseries_sdk.types import TimeSeries
from ontology_sdk.ontology.objects import Machine
from prophet import Prophet

@function
def performance_prophet_forecast(
    machine: Machine,
    periods: int = 96,      # number of future steps
    freq: str = "15min",    # sampling frequency
) -> list[bytes]:
    """
    Forecast a machine's performance_score using Prophet.
    """
    df = machine.performance_score.to_pandas(all_time=True)
    if df.empty:
        return TimeSeries.serialize(df)

    df = df.rename(columns={"timestamp": "ds", "value": "y"}).sort_values("ds")
    model = Prophet().fit(df)
    future = model.make_future_dataframe(periods=periods, freq=freq, include_history=True)
    forecast = model.predict(future)
    out = forecast[["ds", "yhat"]].rename(columns={"ds": "timestamp", "yhat": "value"})
    return TimeSeries.serialize(out)

中文翻译


函数支持的时间序列(Function-backed time series)

:::callout{theme="neutral" title="Beta"} 函数支持的时间序列目前处于 beta 开发阶段,您的实例可能尚未支持此功能。在活跃开发期间,功能可能会发生变化。请联系 Palantir 支持团队申请访问函数支持的时间序列。 :::

函数支持的时间序列(Function-backed time series)使您能够通过 函数 中定义的 Python 逻辑生成和转换数值型时间序列。Foundry 会将函数的输出视为时间序列,无需额外定义时间序列同步。

功能特性

  • 自定义分析: 编写 Python 函数生成数值型时间序列。可使用 statsmodels 或 Prophet 等任意库,或使用专有代码执行高级分析。
  • 与 Foundry 直接集成: 在 Quiver 中直接使用函数输出,并应用重采样、公式计算、连接和时间序列搜索等操作,同时确保兼容性和可组合性。
  • 按需数据访问: 轻松集成外部 API 或服务的数据,无需预先物化数据,从而实现快速原型开发和动态分析。
  • 参数化场景: 传入自定义输入(如控制参数或预测时间范围),并排比较多个生成的时间序列。
  • 可扩展的生产工作流: 利用内置的结果缓存和流式执行机制处理大规模输出,同时保持交互响应速度。

以下示例中,函数支持的时间序列被用于 Workshop 模块,实时计算每周预测。操作员可以模拟不同场景,观察改变机器控制参数对预测性能的影响。

函数支持的时间序列在预测与模拟 Workshop 模块中的动画演示。

工作原理

函数支持的时间序列需要一个返回序列化数值型时间序列的 Python Foundry 函数。当您查询数据时,Quiver 会使用指定的参数调用该函数,在查询时动态生成时间序列。该输出随后在 Foundry 中被视为一等公民时间序列,允许您应用进一步的操作和可视化。

这种集成方式使您能够轻松地将自定义模型和即时分析集成到仪表板中,实现灵活且模块化的时间序列工作流。

示例用例

  • 预测与模拟: 使用您选择的库(如 Prophet 或 statsmodels)生成预测,或使用 Foundry 中构建的模型分析未来趋势并进行场景规划。
  • 多变量分析: 组合多个传感器或指标的输出,实现全面的时间序列分析。
  • 快速模型迭代: 快速迭代自定义模型,无需管理中间数据集或数据管道。

示例:使用 Prophet 进行预测

以下示例演示了如何将 Prophet ↗ 与函数支持的时间序列结合用于预测。

from functions.api import function
from timeseries_sdk.types import TimeSeries
from ontology_sdk.ontology.objects import Machine
from prophet import Prophet

@function
def performance_prophet_forecast(
    machine: Machine,
    periods: int = 96,      # 未来步数
    freq: str = "15min",    # 采样频率
) -> list[bytes]:
    """
    使用 Prophet 预测机器的 performance_score。
    """
    df = machine.performance_score.to_pandas(all_time=True)
    if df.empty:
        return TimeSeries.serialize(df)

    df = df.rename(columns={"timestamp": "ds", "value": "y"}).sort_values("ds")
    model = Prophet().fit(df)
    future = model.make_future_dataframe(periods=periods, freq=freq, include_history=True)
    forecast = model.predict(future)
    out = forecast[["ds", "yhat"]].rename(columns={"ds": "timestamp", "yhat": "value"})
    return TimeSeries.serialize(out)