Skip to content

[AINode] Add Holt-Winters algorithm and fix related bugs #15584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,26 @@ public void ModelOperationTest() {
}
}

@Test
public void callInferenceTest2() {
String sql =
"CALL INFERENCE(_holtwinters, \"select s0 from root.AI.data\", predict_length=6, generateTime=true)";
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
try (ResultSet resultSet = statement.executeQuery(sql)) {
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
checkHeader(resultSetMetaData, "Time,output0");
int count = 0;
while (resultSet.next()) {
count++;
}
assertEquals(6, count);
}
} catch (SQLException e) {
fail(e.getMessage());
}
}

@Test
public void callInferenceTest() {
String sql =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,11 +537,12 @@ public void testInformationSchema() throws SQLException {
"model_id,",
new HashSet<>(
Arrays.asList(
"_timerxl,",
"_STLForecaster,",
"_NaiveForecaster,",
"_ARIMA,",
"_ExponentialSmoothing,")));
"_HoltWinters,",
"_TimerXL,",
"_ExponentialSmoothing,",
"_ARIMA,")));

TestUtils.assertResultSetEqual(
statement.executeQuery(
Expand Down Expand Up @@ -658,9 +659,10 @@ public void testInformationSchema() throws SQLException {
"model_id,",
new HashSet<>(
Arrays.asList(
"_timerxl,",
"_TimerXL,",
"_STLForecaster,",
"_NaiveForecaster,",
"_HoltWinters,",
"_ARIMA,",
"_ExponentialSmoothing,")));

Expand Down
1 change: 1 addition & 0 deletions iotdb-core/ainode/ainode/core/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class ModelInputName(Enum):
class BuiltInModelType(Enum):
# forecast models
ARIMA = "_arima"
HOLTWINTERS = "_holtwinters"
EXPONENTIAL_SMOOTHING = "_exponentialsmoothing"
NAIVE_FORECASTER = "_naiveforecaster"
STL_FORECASTER = "_stlforecaster"
Expand Down
4 changes: 2 additions & 2 deletions iotdb-core/ainode/ainode/core/model/built_in_model_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_model_attributes(model_id: str):
attribute_map = arima_attribute_map
elif model_id == BuiltInModelType.NAIVE_FORECASTER.value:
attribute_map = naive_forecaster_attribute_map
elif model_id == BuiltInModelType.EXPONENTIAL_SMOOTHING.value:
elif model_id == BuiltInModelType.EXPONENTIAL_SMOOTHING.value or model_id == BuiltInModelType.HOLTWINTERS.value:
attribute_map = exponential_smoothing_attribute_map
elif model_id == BuiltInModelType.STL_FORECASTER.value:
attribute_map = stl_forecaster_attribute_map
Expand Down Expand Up @@ -85,7 +85,7 @@ def fetch_built_in_model(model_id, inference_attributes):
# build the built-in model
if model_id == BuiltInModelType.ARIMA.value:
model = ArimaModel(attributes)
elif model_id == BuiltInModelType.EXPONENTIAL_SMOOTHING.value:
elif model_id == BuiltInModelType.EXPONENTIAL_SMOOTHING.value or model_id == BuiltInModelType.HOLTWINTERS.value:
model = ExponentialSmoothingModel(attributes)
elif model_id == BuiltInModelType.NAIVE_FORECASTER.value:
model = NaiveForecasterModel(attributes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,14 @@ public class ModelInfo implements SnapshotProcessor {

private static final Set<String> builtInAnomalyDetectionModel = new HashSet<>();

private static final int timerXLInputLength = 2880;

static {
builtInForecastModel.add("_timerxl");
builtInForecastModel.add("_TimerXL");
builtInForecastModel.add("_ARIMA");
builtInForecastModel.add("_NaiveForecaster");
builtInForecastModel.add("_STLForecaster");
builtInForecastModel.add("_HoltWinters");
builtInForecastModel.add("_ExponentialSmoothing");
builtInAnomalyDetectionModel.add("_GaussianHMM");
builtInAnomalyDetectionModel.add("_GMMHMM");
Expand Down Expand Up @@ -269,6 +272,9 @@ public GetModelInfoResp getModelInfo(GetModelInfoPlan plan) {
// check if it's a built-in model
if ((modelType = checkModelType(modelName)) != ModelType.USER_DEFINED) {
modelInformation = new ModelInformation(modelType, modelName);
if (modelName.equalsIgnoreCase("_timerxl")) {
modelInformation.setInputLength(timerXLInputLength);
}
} else {
modelInformation = modelTable.getModelInformationById(modelName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public TableFunctionAnalysis analyze(Map<String, Argument> arguments) {
}
}
} else {
String[] predictedColumnsArray = predicatedColumns.split(",");
String[] predictedColumnsArray = predicatedColumns.split(";");
Map<String, Integer> inputColumnIndexMap = new HashMap<>();
for (int i = 0, size = allInputColumnsName.size(); i < size; i++) {
Optional<String> fieldName = allInputColumnsName.get(i);
Expand Down
Loading