amazon-science / chronos-forecasting

Chronos: Pretrained (Language) Models for Probabilistic Time Series Forecasting
https://arxiv.org/abs/2403.07815
Apache License 2.0
2.03k stars 238 forks source link

How to use it for multivariate forecasting? #13

Open harshitv804 opened 3 months ago

abdulfatir commented 3 months ago

@harshitv804 as we discussed in the paper, Chronos currently focuses on univariate forecasting. For multivariate time series, you might want to use Chronos on the individual dimensions independently. If you have specific multivariate use cases/datasets to share with us, please do. It will helpful for us to understand the types of practical multivariate problems.

lostella commented 3 months ago

Keeping this open for visibility, since others may have the same question

ozanbarism commented 1 week ago

Can chronos take multiple inputs (channels) but make predictions on a single one of them?

I have pushed a data of size: (n_features, samples) and it makes predictions on one of them. However, it seems like I cannot choose the feature that it is making predictions on. Is there a way to choose it?

Thanks

lostella commented 1 week ago

@ozanbarism if I understand your question right, you want to provide covariates: this is not possible, see #22.

I have pushed a data of size: (n_features, samples) and it makes predictions on one of them.

I'm not sure what you mean here: don't you get predictions for all of them? That's what should happen

ozanbarism commented 1 week ago

I do not get predictions for all of them. I get predictions for one of them it seems like. Also, there is a number of samples term, is this the length of the context data we provide?

This is what it looks like for a univariate data. image And this is the case where i push multivariate data. as you can see it still returns a single prediction column. image

this is my code

model = ChronosModel(name = "amazon/chronos-t5-small", device = "cpu") duration = 20 # in hours pred_hrz = 2 sampling_rates=[300] for i, sr in enumerate(sampling_rates):

Parameter = ParameterGenerator('OfficeSmall', 'Hot_Dry', 'Tucson', max_power=max_power, time_reso=control_rate)  # Description of ParameterGenerator in bldg_utils.py
data, gt = building_simulate(Parameter, room_id, duration, pred_hrz, control_rate,
                          sr, T_cool, T_heat, mode, hysteresis_margin, single_variate=False, make_plot=False, show_outdoor=False)

pred_len = int(pred_hrz*3600/sr)
low, forecast, high = model(data, prediction_length=pred_len, num_samples=1)
plot_pred(data, forecast, gt, forecast_index=None)
print('MSE {:.4f}'.format(np.mean((forecast-gt[:,0])**2)))

and this is how i defined the chronosmodel class

class ChronosModel:

def __init__(self, name, device="cuda"):
    from chronos import ChronosPipeline
    self.model = ChronosPipeline.from_pretrained(
        name,
        device_map=device,  # use "cpu" for CPU inference and "mps" for Apple Silicon
        torch_dtype=torch.bfloat16,
    )

def __call__(self, data, prediction_length, num_samples=1):
    if not torch.is_tensor(data):
        _data = torch.tensor(data)
    else:
        _data = data
    forecast = self.model.predict(
        context=_data,
        prediction_length=prediction_length,
        num_samples=num_samples,
    )

    low, median, high = np.quantile(forecast[0].numpy(), [0.1, 0.5, 0.9], axis=0)
    return low, median, high # 80% interval