Exemplo n.º 1
0
                ap_pred[i][j] = cal.rfc[cur_ap_i].predict(ap_arranged_filtered)
                ap_pred[i][j] = ap_pred[i][j].reshape((ap_pred[i][j].shape[0], 1))

            # # plot predictions
            # plt.plot(ap_pred_times[i][j], ap_pred[i][j], 'go')
            # plt.show()

    """
    amalgamating predictions for each time frame
    """
    # Building time frames
    time_frames.append(range(int(track.track_time[i][0]), int(track.track_time[i][-1] + cfg_exp.time_step),
                             cfg_exp.time_step))

    # not valid prediction are saved as 100
    ap_timed_pred[i], ap_timed_sd[i] = fn_exp.timed_predictions(ap_pred[i], ap_pred_times[i], time_frames[i])

    # remove NaNs
    ap_timed_pred[i] = fn.remove_nan(ap_timed_pred[i])

    # Holt's filtering algorithm
    holt = np.zeros(ap_timed_pred[i].shape)
    holt[0, :] = ap_timed_pred[i][0, :]
    holt_trend = np.zeros(ap_timed_pred[i].shape)

    for j in range(1, ap_timed_pred[i].shape[0]):
        holt[j, :] = (1 - cfg_exp.alpha) * (holt[j-1, :] + holt_trend[j-1, :]) + cfg_exp.alpha * ap_timed_pred[i][j, :]
        holt_trend[j, :] = cfg_exp.trend * (holt[j, :] - holt[j-1, :]) + (1 - cfg_exp.trend) * holt_trend[j-1, :]

    ap_timed_holt[i] = holt
Exemplo n.º 2
0
                ap_pred[i][j] = ap_pred[i][j].reshape((ap_pred[i][j].shape[0], 1))

            # # plot predictions
            # plt.plot(ap_pred_times[i][j], ap_pred[i][j], 'go')
            # plt.show()

    """
    amalgamating predictions for each time frame
    """
    # Building time frames
    time_frames.append(np.array(range(int(track.track_time[i][0]),
                                      int(track.track_time[i][-1] + cfg_exp.time_step),
                                      cfg_exp.time_step)))

    # not valid prediction are saved as 100
    ap_timed_pred_raw[i], ap_timed_sd[i] = fn_exp.timed_predictions(ap_pred[i], ap_pred_times[i], track.track_time_int[i])

    timeout_matrix = np.zeros(ap_timed_pred_raw[i].shape).astype('int')
    timeout_matrix[0, :] = np.isnan(ap_timed_pred_raw[i][0, :]) * (cfg_exp.timeout + 1)
    for j in range(1, ap_timed_pred_raw[i].shape[0]):
        for k in range(ap_timed_pred_raw[i].shape[1]):
            if np.isnan(ap_timed_pred_raw[i][j, k]):
                timeout_matrix[j, k] = timeout_matrix[j-1, k] + 1
            else:
                timeout_matrix[j, k] = 0

    ap_timeout[i] = timeout_matrix

    # Kalman's filtering algorithm
    kalman_x_p = np.zeros(ap_timed_pred_raw[i].shape)
    kalman_x_m = np.zeros(ap_timed_pred_raw[i].shape)
Exemplo n.º 3
0
                ap_pred[i][j] = cal.rfc[cur_ap_i].predict(ap_arranged_filtered)
                ap_pred[i][j] = ap_pred[i][j].reshape((ap_pred[i][j].shape[0], 1))

            # # plot predictions
            # plt.plot(ap_pred_times[i][j], ap_pred[i][j], 'go')
            # plt.show()

    """
    amalgamating predictions for each time frame
    """
    # Building time frames
    time_frames.append(range(int(track.track_time[i][0]), int(track.track_time[i][-1] + cfg_exp.time_step),
                             cfg_exp.time_step))

    # not valid prediction are saved as 100
    ap_timed_pred[i], ap_timed_sd[i] = fn_exp.timed_predictions(ap_pred[i], ap_pred_times[i], time_frames[i])

    # remove NaNs
    ap_timed_pred[i] = fn.remove_nan(ap_timed_pred[i])

    # Kalman's filtering algorithm
    kalman_x_p = np.zeros(ap_timed_pred[i].shape)
    kalman_x_p[0, :] = ap_timed_pred[i][0, :]
    kalman_p_m = np.zeros(ap_timed_pred[i].shape)
    kalman_p_p = np.zeros(ap_timed_pred[i].shape)
    kalman_p_p[0, :] = np.ones((1, 4)) * cfg_exp.kalman_q

    for j in range(1, ap_timed_pred[i].shape[0]):
        kalman_p_m[j, :] = kalman_p_p[j-1, :] + cfg_exp.kalman_q
        kalman_k_j = kalman_p_m[j, :] / (kalman_p_m[j, :] + cfg_exp.kalman_r)
        kalman_p_p[j, :] = (1 - kalman_k_j) * kalman_p_m[j, :]