コード例 #1
0
    def preprocess_pystarma_model_with_source_maker(self, source_maker):
        source = source_maker.all_data
        self._preprocessing(self.ts_matrix.as_matrix(), self.wa_matrices,
                            self.max_t_lag, self.sample_size)

        # make time serie stationar
        diff = (1, 288)
        self.ts_matrix = np.log1p(self.ts_matrix)
        self.ts_matrix = set_stationary(self.ts_matrix, diff)

        # re-run preprocessing
        self._preprocessing(self.ts_matrix.as_matrix(), self.wa_matrices,
                            self.max_t_lag, self.sample_size)

        self._model_identification(self.ts_matrix,
                                   self.wa_matrices,
                                   max_lag=25)
コード例 #2
0
    def queren(self):

        time_field = self.comboBox.currentText()
        lon_field = self.comboBox_2.currentText()
        lat_field = self.comboBox_3.currentText()
        val_field = self.comboBox_4.currentText()
        location_field = self.comboBox_5.currentText()
        l_val = int(self.textEdit_3.toPlainText())
        m_val = int(self.textEdit_4.toPlainText())
        p_val = int(self.textEdit_5.toPlainText())
        q_val = int(self.textEdit_6.toPlainText())
        K_val = int(self.textEdit.toPlainText())
        diff_val = int(self.textEdit_7.toPlainText())
        pre_val = int(self.textEdit_8.toPlainText())

        db = pymysql.connect("localhost",
                             "root",
                             "960609",
                             "biye",
                             charset='utf8')
        # 使用cursor()方法获取操作游标
        cursor = db.cursor()

        #获取地点字段
        location_sql = 'select distinct ' + location_field + ' from AOI order by ' + location_field + ' asc'
        cursor.execute(location_sql)
        rows = cursor.fetchall()
        location_val = []
        for (row, ) in rows:
            loca = row
            location_val.append(loca)

        #获取时间字段
        time_sql = 'select distinct ' + time_field + ' from AOI'
        cursor.execute(time_sql)
        rows = cursor.fetchall()
        datetime_val = []
        for (row, ) in rows:
            dt = str(row)
            datetime_val.append(dt)

        data = []
        diff = [diff_val]  #差分次数i
        #拼接时空数据
        for i in range(len(datetime_val)):
            locaval_sql = 'select ' + val_field + ' from AOI where ' + time_field + ' = \'' + datetime_val[
                i] + '\' order by ' + location_field + ' asc'
            cursor.execute(locaval_sql)
            rows = cursor.fetchall()
            lval = []
            for (row, ) in rows:
                val = row
                lval.append(val)
            data.append(lval)
        ts = np.array(data)
        #计算差分
        ts_diff = utils.set_stationary(ts, diff)
        #获取点的经纬度坐标
        # 点的经度
        lon_sql = 'select distinct ' + lon_field + ' from AOI order by ' + location_field + ' asc'
        cursor.execute(lon_sql)
        rows = cursor.fetchall()
        x_val = []
        for (row, ) in rows:
            xval = row
            x_val.append(xval)

        # 点的纬度
        lat_sql = 'select distinct ' + lat_field + ' from AOI order by ' + location_field + ' asc'
        cursor.execute(lat_sql)
        rows = cursor.fetchall()
        y_val = []
        for (row, ) in rows:
            yval = row
            y_val.append(yval)

        #拼接点
        point = []
        for i in range(len(x_val)):
            coor = []
            coor.append(x_val[i])
            coor.append(y_val[i])
            coortuple = tuple(coor)
            point.append(coortuple)
        #计算权重
        points = np.array(point)
        kd = pysal.cg.kdtree.KDTree(points)
        # weights
        K = int(K_val)
        weights = pysal.weights.Distance.KNN(kd, K)
        #weights.transform='r'
        #计算滞后
        w0 = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
              [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
              [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
              [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
              [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
              [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
              [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
              [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
              [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]
        w = [weights]
        s_lag = max(l_val, p_val)
        for s in range(2, s_lag + 1):
            w_tmp = pysal.higher_order(weights, s)
            w.append(w_tmp)

        slw = [w0]
        for j in range(len(w)):
            w[j].transform = 'r'
            w_f = w[j].full()
            slw.append(w_f[0].tolist())

        w_slag = np.array(slw)
        starma = starma_model.STARMA(m_val, q_val, ts_diff, w_slag)
        starma.fit()
        result = starma.predict(ts_diff, pre_val)
        self.table.show_table(result, location_val)
コード例 #3
0
 def fit(self):
     """
     Estimate parameter for model
     """
     self._ts = set_stationary(self._ts, self._d)
     self._fit_model(self._ts)
コード例 #4
0
               0.1428571, 0.1428571, 0.1428571
           ], [0, 0, 0, 0, 0, 0, 0.25, 0, 0, 0, 0.25, 0.25, 0.25, 0],
           [
               0.1428571, 0.1428571, 0.1428571, 0, 0.1428571, 0, 0.1428571, 0,
               0, 0.1428571, 0, 0, 0, 0.1428571
           ], [0.25, 0, 0, 0, 0.25, 0, 0, 0, 0.25, 0.25, 0, 0, 0, 0],
           [0, 0, 0, 0.25, 0.25, 0, 0, 0, 0.25, 0.25, 0, 0, 0, 0],
           [0, 0, 0, 0.25, 0, 0, 0, 0.25, 0.25, 0, 0.25, 0, 0, 0]]

w_slag = [weight, weight1]
a = w_slag[0]
ts = np.array(data)
w = np.array(w_slag)

#一次差分
ts_diff = utils.set_stationary(ts, [1])

#自相关函数
acf = stacf_stpacf.Stacf(ts_diff, w, 5)
acf_val = acf.estimate()
#偏自相关函数
pacf = stacf_stpacf.Stpacf(ts_diff, w, 5)
pacf_val = pacf.estimate()

#STARMA
#starma=starma_model.STARMA(3,1,ts_diff,w)
starma = starma_model.STARMA(1, 0, ts_diff, w)
starma.fit()
starma.print_results()
print(starma.get_model())
#print(starma.predict(ts,3))