コード例 #1
0
    # Start Testing
    # Create an instance of the filter
    kf = Kalman(history, order)

    # Use the first 7 of them for training
    obs_train = obs[:history]
    model_train = model[:history]

    # The rest to be used dynamically
    obs_dyn = obs[history:]
    model_dyn = model[history:]
    fcst = np.zeros_like(obs_dyn)

    # Perform an initial training of the model
    kf.train_me(obs_train, model_train)

    for ij in range(len(obs_dyn)):
        # Provide a correction to the forecast
        fcst[ij] = kf.adjust_forecast(model_dyn[ij])

        # Update filter
        kf.train_me([obs_dyn[ij]], [model_dyn[ij]])

    fig = plt.figure(figsize=figSize)
    plt.plot(obs_dyn[pltRange], label='obs')
    plt.plot(model_dyn[pltRange], label='model')
    plt.plot(fcst[pltRange], label='kalman')
    plt.legend()
    plt.show()