This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new b9f209f69a Add AR function in Operators-Functions/Machine-Learning
b9f209f69a is described below
commit b9f209f69ab0e6ef21002155dd7f8c96437ae534
Author: iotdb-lsmar <[email protected]>
AuthorDate: Sun Jan 29 14:06:04 2023 +0800
Add AR function in Operators-Functions/Machine-Learning
---
.../Operators-Functions/Machine-Learning.md | 84 ++++++
.../Operators-Functions/Machine-Learning.md | 85 ++++++
.../apache/iotdb/libudf/it/dlearn/DLearnIT.java | 311 +++++++++++++++++++++
.../org/apache/iotdb/library/dlearn/UDTFAR.java | 131 +++++++++
site/src/main/.vuepress/config.js | 6 +-
5 files changed, 615 insertions(+), 2 deletions(-)
diff --git a/docs/UserGuide/Operators-Functions/Machine-Learning.md
b/docs/UserGuide/Operators-Functions/Machine-Learning.md
new file mode 100644
index 0000000000..9623b772ce
--- /dev/null
+++ b/docs/UserGuide/Operators-Functions/Machine-Learning.md
@@ -0,0 +1,84 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+
+# Machine Learning
+
+## AR
+
+### Usage
+
+This function is used to learn the coefficients of the autoregressive models
for a time series.
+
+**Name:** AR
+
+**Input Series:** Only support a single input numeric series. The type is
INT32 / INT64 / FLOAT / DOUBLE.
+
+**Parameters:**
+
+- `p`: The order of the autoregressive model. Its default value is 1.
+
+**Output Series:** Output a single series. The type is DOUBLE. The first line
corresponds to the first order coefficient, and so on.
+
+**Note:**
+
+- Parameter `p` should be a positive integer.
+- Most points in the series should be sampled at a constant time interval.
+- Linear interpolation is applied for the missing points in the series.
+
+### Examples
+
+#### Assigning Model Order
+
+Input Series:
+
+```
++-----------------------------+---------------+
+| Time|root.test.d0.s0|
++-----------------------------+---------------+
+|2020-01-01T00:00:01.000+08:00| -4.0|
+|2020-01-01T00:00:02.000+08:00| -3.0|
+|2020-01-01T00:00:03.000+08:00| -2.0|
+|2020-01-01T00:00:04.000+08:00| -1.0|
+|2020-01-01T00:00:05.000+08:00| 0.0|
+|2020-01-01T00:00:06.000+08:00| 1.0|
+|2020-01-01T00:00:07.000+08:00| 2.0|
+|2020-01-01T00:00:08.000+08:00| 3.0|
+|2020-01-01T00:00:09.000+08:00| 4.0|
++-----------------------------+---------------+
+```
+
+SQL for query:
+
+```sql
+select ar(s0,"p"="2") from root.test.d0
+```
+
+Output Series:
+
+```
++-----------------------------+---------------------------+
+| Time|ar(root.test.d0.s0,"p"="2")|
++-----------------------------+---------------------------+
+|1970-01-01T08:00:00.001+08:00| 0.9429|
+|1970-01-01T08:00:00.002+08:00| -0.2571|
++-----------------------------+---------------------------+
+```
+
diff --git a/docs/zh/UserGuide/Operators-Functions/Machine-Learning.md
b/docs/zh/UserGuide/Operators-Functions/Machine-Learning.md
new file mode 100644
index 0000000000..784ae641cb
--- /dev/null
+++ b/docs/zh/UserGuide/Operators-Functions/Machine-Learning.md
@@ -0,0 +1,85 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+
+# 机器学习
+
+## AR
+
+### 函数简介
+
+本函数用于学习数据的自回归模型系数。
+
+**函数名:** AR
+
+**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。
+
+**参数:**
+
+- `p`:自回归模型的阶数。默认为1。
+
+**输出序列:** 输出单个序列,类型为 DOUBLE。第一行对应模型的一阶系数,以此类推。
+
+**提示:**
+
+- `p`应为正整数。
+
+- 序列中的大部分点为等间隔采样点。
+- 序列中的缺失点通过线性插值进行填补后用于学习过程。
+
+### 使用示例
+
+#### 指定阶数
+
+输入序列:
+
+```
++-----------------------------+---------------+
+| Time|root.test.d0.s0|
++-----------------------------+---------------+
+|2020-01-01T00:00:01.000+08:00| -4.0|
+|2020-01-01T00:00:02.000+08:00| -3.0|
+|2020-01-01T00:00:03.000+08:00| -2.0|
+|2020-01-01T00:00:04.000+08:00| -1.0|
+|2020-01-01T00:00:05.000+08:00| 0.0|
+|2020-01-01T00:00:06.000+08:00| 1.0|
+|2020-01-01T00:00:07.000+08:00| 2.0|
+|2020-01-01T00:00:08.000+08:00| 3.0|
+|2020-01-01T00:00:09.000+08:00| 4.0|
++-----------------------------+---------------+
+```
+
+用于查询的 SQL 语句:
+
+```sql
+select ar(s0,"p"="2") from root.test.d0
+```
+
+输出序列:
+
+```
++-----------------------------+---------------------------+
+| Time|ar(root.test.d0.s0,"p"="2")|
++-----------------------------+---------------------------+
+|1970-01-01T08:00:00.001+08:00| 0.9429|
+|1970-01-01T08:00:00.002+08:00| -0.2571|
++-----------------------------+---------------------------+
+```
+
diff --git
a/integration-test/src/test/java/org/apache/iotdb/libudf/it/dlearn/DLearnIT.java
b/integration-test/src/test/java/org/apache/iotdb/libudf/it/dlearn/DLearnIT.java
new file mode 100644
index 0000000000..480dff4e46
--- /dev/null
+++
b/integration-test/src/test/java/org/apache/iotdb/libudf/it/dlearn/DLearnIT.java
@@ -0,0 +1,311 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.libudf.it.dlearn;
+
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.LocalStandaloneIT;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.fail;
+
+@RunWith(IoTDBTestRunner.class)
+@Category({LocalStandaloneIT.class})
+public class DLearnIT {
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+
EnvFactory.getEnv().getConfig().getCommonConfig().setUdfMemoryBudgetInMB(5);
+ EnvFactory.getEnv().initClusterEnvironment();
+ createTimeSeries();
+ generateData();
+ registerUDF();
+ }
+
+ private static void createTimeSeries() {
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.addBatch("create database root.vehicle");
+ statement.addBatch(
+ "create timeseries root.vehicle.d1.s1 with "
+ + "datatype=int32, "
+ + "encoding=plain, "
+ + "compression=uncompressed");
+ statement.addBatch(
+ "create timeseries root.vehicle.d1.s2 with "
+ + "datatype=int64, "
+ + "encoding=plain, "
+ + "compression=uncompressed");
+ statement.addBatch(
+ "create timeseries root.vehicle.d1.s3 with "
+ + "datatype=float, "
+ + "encoding=plain, "
+ + "compression=uncompressed");
+ statement.addBatch(
+ "create timeseries root.vehicle.d1.s4 with "
+ + "datatype=double, "
+ + "encoding=plain, "
+ + "compression=uncompressed");
+ statement.addBatch(
+ "create timeseries root.vehicle.d2.s1 with "
+ + "datatype=int32, "
+ + "encoding=plain, "
+ + "compression=uncompressed");
+ statement.addBatch(
+ "create timeseries root.vehicle.d2.s2 with "
+ + "datatype=int64, "
+ + "encoding=plain, "
+ + "compression=uncompressed");
+ statement.addBatch(
+ "create timeseries root.vehicle.d2.s3 with "
+ + "datatype=float, "
+ + "encoding=plain, "
+ + "compression=uncompressed");
+ statement.addBatch(
+ "create timeseries root.vehicle.d2.s4 with "
+ + "datatype=double, "
+ + "encoding=plain, "
+ + "compression=uncompressed");
+ statement.executeBatch();
+ } catch (SQLException throwable) {
+ fail(throwable.getMessage());
+ }
+ }
+
+ private static void generateData() {
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.addBatch(
+ String.format(
+ "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4)
values(%d,%d,%d,%d,%d)",
+ 100, -4, -4, -4, -4));
+ statement.addBatch(
+ String.format(
+ "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4)
values(%d,%d,%d,%d,%d)",
+ 200, -3, -3, -3, -3));
+ statement.addBatch(
+ String.format(
+ "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4)
values(%d,%d,%d,%d,%d)",
+ 300, -2, -2, -2, -2));
+ statement.addBatch(
+ String.format(
+ "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4)
values(%d,%d,%d,%d,%d)",
+ 400, -1, -1, -1, -1));
+ statement.addBatch(
+ String.format(
+ "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4)
values(%d,%d,%d,%d,%d)",
+ 500, 0, 0, 0, 0));
+ statement.addBatch(
+ String.format(
+ "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4)
values(%d,%d,%d,%d,%d)",
+ 600, 1, 1, 1, 1));
+ statement.addBatch(
+ String.format(
+ "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4)
values(%d,%d,%d,%d,%d)",
+ 700, 2, 2, 2, 2));
+ statement.addBatch(
+ String.format(
+ "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4)
values(%d,%d,%d,%d,%d)",
+ 800, 3, 3, 3, 3));
+ statement.addBatch(
+ String.format(
+ "insert into root.vehicle.d1(timestamp,s1,s2,s3,s4)
values(%d,%d,%d,%d,%d)",
+ 900, 4, 4, 4, 4));
+
+ statement.addBatch(
+ String.format(
+ "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4)
values(%d,%d,%d,%d,%d)",
+ 100, -4, -4, -4, -4));
+ statement.addBatch(
+ String.format(
+ "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4)
values(%d,%d,%d,%d,%d)",
+ 200, -3, -3, -3, -3));
+ statement.addBatch(
+ String.format(
+ "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4)
values(%d,%d,%d,%d,%d)",
+ 300, -2, -2, -2, -2));
+ statement.addBatch(
+ String.format(
+ "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4)
values(%d,%d,%d,%d,%d)",
+ 600, 1, 1, 1, 1));
+ statement.addBatch(
+ String.format(
+ "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4)
values(%d,%d,%d,%d,%d)",
+ 700, 2, 2, 2, 2));
+ statement.addBatch(
+ String.format(
+ "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4)
values(%d,%d,%d,%d,%d)",
+ 800, 3, 3, 3, 3));
+ statement.addBatch(
+ String.format(
+ "insert into root.vehicle.d2(timestamp,s1,s2,s3,s4)
values(%d,%d,%d,%d,%d)",
+ 900, 4, 4, 4, 4));
+ statement.executeBatch();
+ } catch (SQLException throwable) {
+ fail(throwable.getMessage());
+ }
+ }
+
+ private static void registerUDF() {
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.execute("create function iqr as
'org.apache.iotdb.library.anomaly.UDTFIQR'");
+ statement.execute("create function ar as
'org.apache.iotdb.library.dlearn.UDTFAR'");
+ } catch (SQLException throwable) {
+ fail(throwable.getMessage());
+ }
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ EnvFactory.getEnv().cleanClusterEnvironment();
+ }
+
+ @Test
+ public void testAR1() {
+ String sqlStr = "select ar(d1.s1, \"p\"=\"2\") from root.vehicle";
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ ResultSet resultSet = statement.executeQuery(sqlStr);
+ resultSet.next();
+ double result1 = resultSet.getDouble(2);
+ Assert.assertEquals(0.943, result1, 0.01);
+ resultSet.next();
+ double result2 = resultSet.getDouble(2);
+ Assert.assertEquals(-0.257, result2, 0.01);
+ } catch (SQLException throwable) {
+ fail(throwable.getMessage());
+ }
+ sqlStr = "select ar(d2.s1, \"p\"=\"2\") from root.vehicle";
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ ResultSet resultSet = statement.executeQuery(sqlStr);
+ resultSet.next();
+ double result3 = resultSet.getDouble(2);
+ Assert.assertEquals(0.943, result3, 0.01);
+ resultSet.next();
+ double result4 = resultSet.getDouble(2);
+ Assert.assertEquals(-0.257, result4, 0.01);
+ } catch (SQLException throwable) {
+ fail(throwable.getMessage());
+ }
+ }
+
+ @Test
+ public void testAR2() {
+ String sqlStr = "select ar(d1.s2, \"p\"=\"2\") from root.vehicle";
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ ResultSet resultSet = statement.executeQuery(sqlStr);
+ resultSet.next();
+ double result1 = resultSet.getDouble(2);
+ Assert.assertEquals(0.943, result1, 0.01);
+ resultSet.next();
+ double result2 = resultSet.getDouble(2);
+ Assert.assertEquals(-0.257, result2, 0.01);
+ } catch (SQLException throwable) {
+ fail(throwable.getMessage());
+ }
+ sqlStr = "select ar(d2.s2, \"p\"=\"2\") from root.vehicle";
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ ResultSet resultSet = statement.executeQuery(sqlStr);
+ resultSet.next();
+ double result3 = resultSet.getDouble(2);
+ Assert.assertEquals(0.943, result3, 0.01);
+ resultSet.next();
+ double result4 = resultSet.getDouble(2);
+ Assert.assertEquals(-0.257, result4, 0.01);
+ } catch (SQLException throwable) {
+ fail(throwable.getMessage());
+ }
+ }
+
+ @Test
+ public void testAR3() {
+ String sqlStr = "select ar(d1.s3, \"p\"=\"2\") from root.vehicle";
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ ResultSet resultSet = statement.executeQuery(sqlStr);
+ resultSet.next();
+ double result1 = resultSet.getDouble(2);
+ Assert.assertEquals(0.943, result1, 0.01);
+ resultSet.next();
+ double result2 = resultSet.getDouble(2);
+ Assert.assertEquals(-0.257, result2, 0.01);
+ } catch (SQLException throwable) {
+ fail(throwable.getMessage());
+ }
+ sqlStr = "select ar(d2.s3, \"p\"=\"2\") from root.vehicle";
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ ResultSet resultSet = statement.executeQuery(sqlStr);
+ resultSet.next();
+ double result3 = resultSet.getDouble(2);
+ Assert.assertEquals(0.943, result3, 0.01);
+ resultSet.next();
+ double result4 = resultSet.getDouble(2);
+ Assert.assertEquals(-0.257, result4, 0.01);
+ } catch (SQLException throwable) {
+ fail(throwable.getMessage());
+ }
+ }
+
+ @Test
+ public void testAR4() {
+ String sqlStr = "select ar(d1.s4, \"p\"=\"2\") from root.vehicle";
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ ResultSet resultSet = statement.executeQuery(sqlStr);
+ resultSet.next();
+ double result1 = resultSet.getDouble(2);
+ Assert.assertEquals(0.943, result1, 0.01);
+ resultSet.next();
+ double result2 = resultSet.getDouble(2);
+ Assert.assertEquals(-0.257, result2, 0.01);
+ } catch (SQLException throwable) {
+ fail(throwable.getMessage());
+ }
+ sqlStr = "select ar(d2.s4, \"p\"=\"2\") from root.vehicle";
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ ResultSet resultSet = statement.executeQuery(sqlStr);
+ resultSet.next();
+ double result3 = resultSet.getDouble(2);
+ Assert.assertEquals(0.943, result3, 0.01);
+ resultSet.next();
+ double result4 = resultSet.getDouble(2);
+ Assert.assertEquals(-0.257, result4, 0.01);
+ } catch (SQLException throwable) {
+ fail(throwable.getMessage());
+ }
+ }
+}
diff --git
a/library-udf/src/main/java/org/apache/iotdb/library/dlearn/UDTFAR.java
b/library-udf/src/main/java/org/apache/iotdb/library/dlearn/UDTFAR.java
new file mode 100644
index 0000000000..cceebb8531
--- /dev/null
+++ b/library-udf/src/main/java/org/apache/iotdb/library/dlearn/UDTFAR.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.library.dlearn;
+
+import org.apache.iotdb.library.util.Util;
+import org.apache.iotdb.udf.api.UDTF;
+import org.apache.iotdb.udf.api.access.Row;
+import org.apache.iotdb.udf.api.collector.PointCollector;
+import org.apache.iotdb.udf.api.customizer.config.UDTFConfigurations;
+import org.apache.iotdb.udf.api.customizer.parameter.UDFParameters;
+import org.apache.iotdb.udf.api.customizer.strategy.RowByRowAccessStrategy;
+import org.apache.iotdb.udf.api.exception.UDFException;
+import org.apache.iotdb.udf.api.type.Type;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class UDTFAR implements UDTF {
+ private int p;
+ private long interval;
+ private List<Long> timeWindow = new ArrayList<>();
+ private List<Double> valueWindow = new ArrayList<>();
+
+ @Override
+ public void beforeStart(UDFParameters udfParameters, UDTFConfigurations
udtfConfigurations)
+ throws Exception {
+ udtfConfigurations
+ .setAccessStrategy(new RowByRowAccessStrategy())
+ .setOutputDataType(udfParameters.getDataType(0));
+ this.p = udfParameters.getIntOrDefault("p", 1);
+ udtfConfigurations.setAccessStrategy(new RowByRowAccessStrategy());
+ udtfConfigurations.setOutputDataType(Type.DOUBLE);
+ }
+
+ @Override
+ public void transform(Row row, PointCollector collector) throws Exception {
+ if (!row.isNull(0)) {
+ timeWindow.add(row.getTime());
+ valueWindow.add(Util.getValueAsDouble(row));
+ }
+ }
+
+ @Override
+ public void terminate(PointCollector collector) throws Exception {
+ int length = timeWindow.size();
+ if (length <= this.p) {
+ throw new UDFException("Illegal input.");
+ }
+
+ int count = 0;
+ long maxFreqInterval = timeWindow.get(1) - timeWindow.get(0);
+ for (int i = 2; i < timeWindow.size(); i++) {
+ if (maxFreqInterval == timeWindow.get(i) - timeWindow.get(i - 1))
count++;
+ else {
+ count--;
+ if (count == 0) {
+ maxFreqInterval = timeWindow.get(i) - timeWindow.get(i - 1);
+ count++;
+ }
+ }
+ }
+ this.interval = maxFreqInterval;
+
+ List<Long> imputedTimeWindow = new ArrayList<>();
+ List<Double> imputedValueWindow = new ArrayList<>();
+
+ imputedTimeWindow.add(timeWindow.get(0));
+ imputedValueWindow.add(valueWindow.get(0));
+ for (int i = 1; i < timeWindow.size(); i++) {
+ if (timeWindow.get(i) - timeWindow.get(i - 1) > interval) {
+ int gap = (int) ((timeWindow.get(i) - timeWindow.get(i - 1)) /
interval);
+ double step = (valueWindow.get(i) - valueWindow.get(i - 1)) / gap;
+ for (int j = 1; j < gap; j++) {
+ imputedTimeWindow.add(timeWindow.get(i - 1) + j * interval);
+ imputedValueWindow.add(valueWindow.get(i - 1) + j * step);
+ }
+ }
+ imputedTimeWindow.add(timeWindow.get(i));
+ imputedValueWindow.add(valueWindow.get(i));
+ }
+
+ int newLength = imputedTimeWindow.size();
+
+ double[] resultCovariances = new double[this.p + 1];
+ for (int i = 0; i <= p; i++) {
+ resultCovariances[i] = 0;
+ for (int j = 0; j < newLength - i; j++) {
+ if (j + i < newLength)
+ resultCovariances[i] += imputedValueWindow.get(j) *
imputedValueWindow.get(j + i);
+ }
+ resultCovariances[i] /= newLength - i;
+ }
+
+ double[] epsilons = new double[p + 1];
+ double[] kappas = new double[p + 1];
+ double[][] alphas = new double[p + 1][p + 1];
+ // alphas[i][j] denotes alpha_i^{(j)}
+ epsilons[0] = resultCovariances[0];
+ for (int i = 1; i <= p; i++) {
+ double tmpSum = 0.0;
+ for (int j = 1; j <= i - 1; j++) tmpSum += alphas[j][i - 1] *
resultCovariances[i - j];
+ kappas[i] = (resultCovariances[i] - tmpSum) / epsilons[i - 1];
+ alphas[i][i] = kappas[i];
+ if (i > 1) {
+ for (int j = 1; j <= i - 1; j++)
+ alphas[j][i] = alphas[j][i - 1] - kappas[i] * alphas[i - j][i - 1];
+ }
+ epsilons[i] = (1 - kappas[i] * kappas[i]) * epsilons[i - 1];
+ }
+ for (int i = 1; i <= p; i++) {
+ collector.putDouble(i, alphas[i][p]);
+ }
+ }
+}
diff --git a/site/src/main/.vuepress/config.js
b/site/src/main/.vuepress/config.js
index d64a30687b..97c20bc6ff 100644
--- a/site/src/main/.vuepress/config.js
+++ b/site/src/main/.vuepress/config.js
@@ -1194,7 +1194,8 @@ var config = {
['Operators-Functions/Frequency-Domain','Frequency Domain'],
['Operators-Functions/Data-Quality','Data Quality'],
['Operators-Functions/Data-Repairing','Data Repairing'],
-
['Operators-Functions/Series-Discovery','Series Discovery']
+
['Operators-Functions/Series-Discovery','Series Discovery'],
+
['Operators-Functions/Machine-Learning','Machine Learning']
]
},
{
@@ -2394,7 +2395,8 @@ var config = {
['Operators-Functions/Frequency-Domain','频域分析'],
['Operators-Functions/Data-Quality','数据质量'],
['Operators-Functions/Data-Repairing','数据修复'],
-
['Operators-Functions/Series-Discovery','序列发现']
+
['Operators-Functions/Series-Discovery','序列发现'],
+
['Operators-Functions/Machine-Learning','机器学习']
]
},
{