1.1)定义:哈尔小波变换分为哈尔小波分解和重构。本文利用哈尔小波分解和哈尔小波重构分别对社交网络中的时间序列进行降维和升维操作,而分解降维和重构升维互为逆过程,这里以哈尔小波分解降维步骤为例进行说明。
1.2)哈尔小波分解(重构是其逆过程):可以被看作是一系列对离散时间函数的均值和差操作。本文计算离散函数f(t),即时间序列元素值的每两个相邻值间的均值和差。找出离散函数f(t)={9, 7, 3, 5}的哈尔小波分解过程如下表所示:
分辨率 级别 |
分辨率 (维度) |
均值 |
差值 |
哈尔小波 分解系数 |
降维后的 时序 |
全分辨率下的时序 |
2 |
4 |
{9,7,3,5} |
|
{9,7,3,5} |
|
{9,7,3,5} |
1 |
2 |
{8,4} |
{1,-1} |
{8,4,1,-1} |
{8,4} |
{8,8,4,4} |
0 |
1 |
{6} |
{2} |
{6,2,1,-1} |
{6} |
{6,6,6,6} |
【2】将上述哈尔小波分解过程用倒置二叉树表示如下:
【3】看个荔枝
public class HaarTransform{ /** * executing haar reconstruction transform towards given array * @param rawitem raw array * @param curResolution current resolution */ public static int maxResolution; public static void Reconstruct(double[] rawitem, int curResolution) { double[] temp = new double[(int) pow(2, curResolution+1)]; int span; span = (int) pow(2, curResolution); for (int i = 0; i < span; i++) { temp[2*i] = rawitem[i] + rawitem[i+span]; temp[2*i+1] = rawitem[i] - rawitem[i+span]; } System.arraycopy(temp, 0, rawitem, 0, temp.length); } /** * @param rawitem is a array * @param leastResolution is the least resolution allowed be zero. * @param maxResolution is equals to log(full dimension) * @return */ public static double[] Decompose(double[] rawitem, int leastResolution, int maxResolution) { double[] temp = new double[rawitem.length]; int resolutionLength = ClusterData.dimension; HaarTransform.maxResolution = maxResolution; System.out.print("===初始分辨率为:" + maxResolution); AlgTools.printOneDimArray(rawitem); System.out.println("\n===哈儿小波分解数据维度(降维)==="); // you know least resolution equals to 0. for (int i = (int)maxResolution; i > leastResolution; i--) { for (int j = 0; j < resolutionLength / 2; j++) { temp[j] = (rawitem[2*j] + rawitem[2*j+1]) / 2; temp[resolutionLength/2+j] = (rawitem[2*j] - rawitem[2*j+1]) / 2; } rawitem = temp.clone(); System.out.print("===降维后的分辨率为:" + (i-1)); AlgTools.printOneDimArray(rawitem); resolutionLength /= 2; } return temp; } }
循环次数 round |
分辨率i |
分辨率级别的对应维度 resolutionLength |
j(max) |
下一分辨率级别 的维度sum |
1 |
7 |
128 |
63(0~63) |
64 |
2 |
6 |
64 |
31(0~31) |
32 |
3 |
5 |
32 |
15(0~15) |
16 |
4 |
4 |
16 |
7(0~7) |
8 |
5 |
3 |
8 |
3(0~3) |
4 |
6 |
2 |
4 |
1(0~1) |
2 |
7 |
1 |
2 |
0(0~1) |
1 |
===初始分辨率为:7 3.618 3.335 3.002 3.073 2.602 2.448 2.532 2.756 2.790 2.956 3.373 3.163 3.315 3.511 3.288 3.109 3.011 3.077 2.971 3.214 3.369 3.105 3.063 2.722 2.288 3.272 11.291 20.017 31.324 51.307 94.234163.889253.627372.525497.424642.902811.8281000.9981172.9371298.4281399.1901444.7701452.2061422.1691394.1541369.3461350.4861332.4741253.0821117.242946.172790.994645.383527.494437.614366.880329.590325.505353.907392.927440.781495.314556.211615.969662.322697.820712.415715.096719.292721.732721.731716.570711.313691.281662.400620.116572.862544.525524.006506.244490.833489.327490.983509.590557.346606.486656.436719.957793.370856.480916.926970.167992.306989.343969.713931.645876.140813.348743.502664.335607.390569.595548.589551.772559.155585.741615.046665.824716.634757.659804.571828.447868.492878.705886.999881.957831.100781.153724.207686.238632.322595.360546.200466.399410.905372.359357.818349.447 ===哈儿小波分解数据维度(降维)=== ===降维后的分辨率为:6 3.476 3.038 2.525 2.644 2.873 3.268 3.413 3.199 3.044 3.092 3.237 2.892 2.780 15.654 41.315129.061313.076570.163906.4131235.6831421.9801437.1881381.7501341.4801185.162868.583586.439402.247327.548373.417468.048586.090680.071713.756720.512719.150701.297641.258558.694515.125490.080500.286581.916688.196824.925943.546990.824950.679844.744703.919588.492550.181572.448640.435737.147816.509873.598884.478806.127705.222613.841506.300391.632353.632 0.142 -0.036 0.077 -0.112 -0.083 0.105 -0.098 0.089 -0.033 -0.121 0.132 0.171 -0.492 -4.363 -9.991-34.827-59.449-72.739-94.585-62.745-22.790 15.018 12.404 9.006 67.920 77.589 58.945 35.367 2.042-19.510-27.267-29.879-17.749 -1.340 -1.220 2.580 10.016 21.142 14.169 8.881 0.753 -9.303-24.570-31.761-31.555-26.620 1.482 19.034 31.396 39.583 18.897 -1.591-13.293-25.389-20.512-11.938 -5.106 2.521 24.974 18.984 18.481 39.901 19.273 4.186 ===降维后的分辨率为:5 3.257 2.584 3.071 3.306 3.068 3.065 9.217 85.188441.6201071.0481429.5841361.6151026.872494.343350.482527.069696.913719.831671.278536.909495.183635.056884.236970.752774.331569.337606.441776.828879.038755.674560.070372.632 0.219 -0.060 -0.198 0.107 -0.024 0.172 -6.437-43.873-128.543-164.635 -7.604 20.135158.289 92.096-22.934-59.021-16.842 0.681 30.019 21.784 -5.103-53.140-59.311 20.073 70.412 19.156-33.994-39.681 -5.440 50.452 53.771 19.000 0.142 -0.036 0.077 -0.112 -0.083 0.105 -0.098 0.089 -0.033 -0.121 0.132 0.171 -0.492 -4.363 -9.991-34.827-59.449-72.739-94.585-62.745-22.790 15.018 12.404 9.006 67.920 77.589 58.945 35.367 2.042-19.510-27.267-29.879-17.749 -1.340 -1.220 2.580 10.016 21.142 14.169 8.881 0.753 -9.303-24.570-31.761-31.555-26.620 1.482 19.034 31.396 39.583 18.897 -1.591-13.293-25.389-20.512-11.938 -5.106 2.521 24.974 18.984 18.481 39.901 19.273 4.186 ===降维后的分辨率为:4 2.921 3.188 3.066 47.203756.3341395.599760.608438.776708.372604.094565.120927.494671.834691.635817.356466.351 0.336 -0.118 0.002-37.986-314.714 33.984266.265-88.293-11.459 67.184-69.937-43.258102.497-85.193 61.682 93.719 0.219 -0.060 -0.198 0.107 -0.024 0.172 -6.437-43.873-128.543-164.635 -7.604 20.135158.289 92.096-22.934-59.021-16.842 0.681 30.019 21.784 -5.103-53.140-59.311 20.073 70.412 19.156-33.994-39.681 -5.440 50.452 53.771 19.000 0.142 -0.036 0.077 -0.112 -0.083 0.105 -0.098 0.089 -0.033 -0.121 0.132 0.171 -0.492 -4.363 -9.991-34.827-59.449-72.739-94.585-62.745-22.790 15.018 12.404 9.006 67.920 77.589 58.945 35.367 2.042-19.510-27.267-29.879-17.749 -1.340 -1.220 2.580 10.016 21.142 14.169 8.881 0.753 -9.303-24.570-31.761-31.555-26.620 1.482 19.034 31.396 39.583 18.897 -1.591-13.293-25.389-20.512-11.938 -5.106 2.521 24.974 18.984 18.481 39.901 19.273 4.186 ===降维后的分辨率为:3 3.054 25.1351075.967599.692656.233746.307681.734641.854 -0.134-22.068-319.633160.916 52.139-181.187 -9.900175.502 0.336 -0.118 0.002-37.986-314.714 33.984266.265-88.293-11.459 67.184-69.937-43.258102.497-85.193 61.682 93.719 0.219 -0.060 -0.198 0.107 -0.024 0.172 -6.437-43.873-128.543-164.635 -7.604 20.135158.289 92.096-22.934-59.021-16.842 0.681 30.019 21.784 -5.103-53.140-59.311 20.073 70.412 19.156-33.994-39.681 -5.440 50.452 53.771 19.000 0.142 -0.036 0.077 -0.112 -0.083 0.105 -0.098 0.089 -0.033 -0.121 0.132 0.171 -0.492 -4.363 -9.991-34.827-59.449-72.739-94.585-62.745-22.790 15.018 12.404 9.006 67.920 77.589 58.945 35.367 2.042-19.510-27.267-29.879-17.749 -1.340 -1.220 2.580 10.016 21.142 14.169 8.881 0.753 -9.303-24.570-31.761-31.555-26.620 1.482 19.034 31.396 39.583 18.897 -1.591-13.293-25.389-20.512-11.938 -5.106 2.521 24.974 18.984 18.481 39.901 19.273 4.186 ===降维后的分辨率为:2 14.094837.829701.270661.794-11.040238.137-45.037 19.940 -0.134-22.068-319.633160.916 52.139-181.187 -9.900175.502 0.336 -0.118 0.002-37.986-314.714 33.984266.265-88.293-11.459 67.184-69.937-43.258102.497-85.193 61.682 93.719 0.219 -0.060 -0.198 0.107 -0.024 0.172 -6.437-43.873-128.543-164.635 -7.604 20.135158.289 92.096-22.934-59.021-16.842 0.681 30.019 21.784 -5.103-53.140-59.311 20.073 70.412 19.156-33.994-39.681 -5.440 50.452 53.771 19.000 0.142 -0.036 0.077 -0.112 -0.083 0.105 -0.098 0.089 -0.033 -0.121 0.132 0.171 -0.492 -4.363 -9.991-34.827-59.449-72.739-94.585-62.745-22.790 15.018 12.404 9.006 67.920 77.589 58.945 35.367 2.042-19.510-27.267-29.879-17.749 -1.340 -1.220 2.580 10.016 21.142 14.169 8.881 0.753 -9.303-24.570-31.761-31.555-26.620 1.482 19.034 31.396 39.583 18.897 -1.591-13.293-25.389-20.512-11.938 -5.106 2.521 24.974 18.984 18.481 39.901 19.273 4.186 ===降维后的分辨率为:1 425.962681.532-411.867 19.738-11.040238.137-45.037 19.940 -0.134-22.068-319.633160.916 52.139-181.187 -9.900175.502 0.336 -0.118 0.002-37.986-314.714 33.984266.265-88.293-11.459 67.184-69.937-43.258102.497-85.193 61.682 93.719 0.219 -0.060 -0.198 0.107 -0.024 0.172 -6.437-43.873-128.543-164.635 -7.604 20.135158.289 92.096-22.934-59.021-16.842 0.681 30.019 21.784 -5.103-53.140-59.311 20.073 70.412 19.156-33.994-39.681 -5.440 50.452 53.771 19.000 0.142 -0.036 0.077 -0.112 -0.083 0.105 -0.098 0.089 -0.033 -0.121 0.132 0.171 -0.492 -4.363 -9.991-34.827-59.449-72.739-94.585-62.745-22.790 15.018 12.404 9.006 67.920 77.589 58.945 35.367 2.042-19.510-27.267-29.879-17.749 -1.340 -1.220 2.580 10.016 21.142 14.169 8.881 0.753 -9.303-24.570-31.761-31.555-26.620 1.482 19.034 31.396 39.583 18.897 -1.591-13.293-25.389-20.512-11.938 -5.106 2.521 24.974 18.984 18.481 39.901 19.273 4.186 ===降维后的分辨率为:0 553.747-127.785-411.867 19.738-11.040238.137-45.037 19.940 -0.134-22.068-319.633160.916 52.139-181.187 -9.900175.502 0.336 -0.118 0.002-37.986-314.714 33.984266.265-88.293-11.459 67.184-69.937-43.258102.497-85.193 61.682 93.719 0.219 -0.060 -0.198 0.107 -0.024 0.172 -6.437-43.873-128.543-164.635 -7.604 20.135158.289 92.096-22.934-59.021-16.842 0.681 30.019 21.784 -5.103-53.140-59.311 20.073 70.412 19.156-33.994-39.681 -5.440 50.452 53.771 19.000 0.142 -0.036 0.077 -0.112 -0.083 0.105 -0.098 0.089 -0.033 -0.121 0.132 0.171 -0.492 -4.363 -9.991-34.827-59.449-72.739-94.585-62.745-22.790 15.018 12.404 9.006 67.920 77.589 58.945 35.367 2.042-19.510-27.267-29.879-17.749 -1.340 -1.220 2.580 10.016 21.142 14.169 8.881 0.753 -9.303-24.570-31.761-31.555-26.620 1.482 19.034 31.396 39.583 18.897 -1.591-13.293-25.389-20.512-11.938 -5.106 2.521 24.974 18.984 18.481 39.901 19.273 4.186 ===哈儿小波重构数据维度(升维)=== ===升维后的分辨率为:1 425.962681.532-411.867 19.738-11.040238.137-45.037 19.940 -0.134-22.068-319.633160.916 52.139-181.187 -9.900175.502 0.336 -0.118 0.002-37.986-314.714 33.984266.265-88.293-11.459 67.184-69.937-43.258102.497-85.193 61.682 93.719 0.219 -0.060 -0.198 0.107 -0.024 0.172 -6.437-43.873-128.543-164.635 -7.604 20.135158.289 92.096-22.934-59.021-16.842 0.681 30.019 21.784 -5.103-53.140-59.311 20.073 70.412 19.156-33.994-39.681 -5.440 50.452 53.771 19.000 0.142 -0.036 0.077 -0.112 -0.083 0.105 -0.098 0.089 -0.033 -0.121 0.132 0.171 -0.492 -4.363 -9.991-34.827-59.449-72.739-94.585-62.745-22.790 15.018 12.404 9.006 67.920 77.589 58.945 35.367 2.042-19.510-27.267-29.879-17.749 -1.340 -1.220 2.580 10.016 21.142 14.169 8.881 0.753 -9.303-24.570-31.761-31.555-26.620 1.482 19.034 31.396 39.583 18.897 -1.591-13.293-25.389-20.512-11.938 -5.106 2.521 24.974 18.984 18.481 39.901 19.273 4.186 ===升维后的分辨率为:2 14.094837.829701.270661.794-11.040238.137-45.037 19.940 -0.134-22.068-319.633160.916 52.139-181.187 -9.900175.502 0.336 -0.118 0.002-37.986-314.714 33.984266.265-88.293-11.459 67.184-69.937-43.258102.497-85.193 61.682 93.719 0.219 -0.060 -0.198 0.107 -0.024 0.172 -6.437-43.873-128.543-164.635 -7.604 20.135158.289 92.096-22.934-59.021-16.842 0.681 30.019 21.784 -5.103-53.140-59.311 20.073 70.412 19.156-33.994-39.681 -5.440 50.452 53.771 19.000 0.142 -0.036 0.077 -0.112 -0.083 0.105 -0.098 0.089 -0.033 -0.121 0.132 0.171 -0.492 -4.363 -9.991-34.827-59.449-72.739-94.585-62.745-22.790 15.018 12.404 9.006 67.920 77.589 58.945 35.367 2.042-19.510-27.267-29.879-17.749 -1.340 -1.220 2.580 10.016 21.142 14.169 8.881 0.753 -9.303-24.570-31.761-31.555-26.620 1.482 19.034 31.396 39.583 18.897 -1.591-13.293-25.389-20.512-11.938 -5.106 2.521 24.974 18.984 18.481 39.901 19.273 4.186 ===升维后的分辨率为:3 3.054 25.1351075.967599.692656.233746.307681.734641.854 -0.134-22.068-319.633160.916 52.139-181.187 -9.900175.502 0.336 -0.118 0.002-37.986-314.714 33.984266.265-88.293-11.459 67.184-69.937-43.258102.497-85.193 61.682 93.719 0.219 -0.060 -0.198 0.107 -0.024 0.172 -6.437-43.873-128.543-164.635 -7.604 20.135158.289 92.096-22.934-59.021-16.842 0.681 30.019 21.784 -5.103-53.140-59.311 20.073 70.412 19.156-33.994-39.681 -5.440 50.452 53.771 19.000 0.142 -0.036 0.077 -0.112 -0.083 0.105 -0.098 0.089 -0.033 -0.121 0.132 0.171 -0.492 -4.363 -9.991-34.827-59.449-72.739-94.585-62.745-22.790 15.018 12.404 9.006 67.920 77.589 58.945 35.367 2.042-19.510-27.267-29.879-17.749 -1.340 -1.220 2.580 10.016 21.142 14.169 8.881 0.753 -9.303-24.570-31.761-31.555-26.620 1.482 19.034 31.396 39.583 18.897 -1.591-13.293-25.389-20.512-11.938 -5.106 2.521 24.974 18.984 18.481 39.901 19.273 4.186 ===升维后的分辨率为:4 2.921 3.188 3.066 47.203756.3341395.599760.608438.776708.372604.094565.120927.494671.834691.635817.356466.351 0.336 -0.118 0.002-37.986-314.714 33.984266.265-88.293-11.459 67.184-69.937-43.258102.497-85.193 61.682 93.719 0.219 -0.060 -0.198 0.107 -0.024 0.172 -6.437-43.873-128.543-164.635 -7.604 20.135158.289 92.096-22.934-59.021-16.842 0.681 30.019 21.784 -5.103-53.140-59.311 20.073 70.412 19.156-33.994-39.681 -5.440 50.452 53.771 19.000 0.142 -0.036 0.077 -0.112 -0.083 0.105 -0.098 0.089 -0.033 -0.121 0.132 0.171 -0.492 -4.363 -9.991-34.827-59.449-72.739-94.585-62.745-22.790 15.018 12.404 9.006 67.920 77.589 58.945 35.367 2.042-19.510-27.267-29.879-17.749 -1.340 -1.220 2.580 10.016 21.142 14.169 8.881 0.753 -9.303-24.570-31.761-31.555-26.620 1.482 19.034 31.396 39.583 18.897 -1.591-13.293-25.389-20.512-11.938 -5.106 2.521 24.974 18.984 18.481 39.901 19.273 4.186 ===升维后的分辨率为:5 3.257 2.584 3.071 3.306 3.068 3.065 9.217 85.188441.6201071.0481429.5841361.6151026.872494.343350.482527.069696.913719.831671.278536.909495.183635.056884.236970.752774.331569.337606.441776.828879.038755.674560.070372.632 0.219 -0.060 -0.198 0.107 -0.024 0.172 -6.437-43.873-128.543-164.635 -7.604 20.135158.289 92.096-22.934-59.021-16.842 0.681 30.019 21.784 -5.103-53.140-59.311 20.073 70.412 19.156-33.994-39.681 -5.440 50.452 53.771 19.000 0.142 -0.036 0.077 -0.112 -0.083 0.105 -0.098 0.089 -0.033 -0.121 0.132 0.171 -0.492 -4.363 -9.991-34.827-59.449-72.739-94.585-62.745-22.790 15.018 12.404 9.006 67.920 77.589 58.945 35.367 2.042-19.510-27.267-29.879-17.749 -1.340 -1.220 2.580 10.016 21.142 14.169 8.881 0.753 -9.303-24.570-31.761-31.555-26.620 1.482 19.034 31.396 39.583 18.897 -1.591-13.293-25.389-20.512-11.938 -5.106 2.521 24.974 18.984 18.481 39.901 19.273 4.186 ===升维后的分辨率为:6 3.476 3.038 2.525 2.644 2.873 3.268 3.413 3.199 3.044 3.092 3.237 2.892 2.780 15.654 41.315129.061313.076570.163906.4131235.6831421.9801437.1881381.7501341.4801185.162868.583586.439402.247327.548373.417468.048586.090680.071713.756720.512719.150701.297641.258558.694515.125490.080500.286581.916688.196824.925943.546990.824950.679844.744703.919588.492550.181572.448640.435737.147816.509873.598884.478806.127705.222613.841506.300391.632353.632 0.142 -0.036 0.077 -0.112 -0.083 0.105 -0.098 0.089 -0.033 -0.121 0.132 0.171 -0.492 -4.363 -9.991-34.827-59.449-72.739-94.585-62.745-22.790 15.018 12.404 9.006 67.920 77.589 58.945 35.367 2.042-19.510-27.267-29.879-17.749 -1.340 -1.220 2.580 10.016 21.142 14.169 8.881 0.753 -9.303-24.570-31.761-31.555-26.620 1.482 19.034 31.396 39.583 18.897 -1.591-13.293-25.389-20.512-11.938 -5.106 2.521 24.974 18.984 18.481 39.901 19.273 4.186 ===升维后的分辨率为:7 3.618 3.335 3.002 3.073 2.602 2.448 2.532 2.756 2.790 2.956 3.373 3.163 3.315 3.511 3.288 3.109 3.011 3.077 2.971 3.214 3.369 3.105 3.063 2.722 2.288 3.272 11.291 20.017 31.324 51.307 94.234163.889253.627372.525497.424642.902811.8281000.9981172.9371298.4281399.1901444.7701452.2061422.1691394.1541369.3461350.4861332.4741253.0821117.242946.172790.994645.383527.494437.614366.880329.590325.505353.907392.927440.781495.314556.211615.969662.322697.820712.415715.096719.292721.732721.731716.570711.313691.281662.400620.116572.862544.525524.006506.244490.833489.327490.983509.590557.346606.486656.436719.957793.370856.480916.926970.167992.306989.343969.713931.645876.140813.348743.502664.335607.390569.595548.589551.772559.155585.741615.046665.824716.634757.659804.571828.447868.492878.705886.999881.957831.100781.153724.207686.238632.322595.360546.200466.399410.905372.359357.818349.447