Skip to content

Commit

Permalink
Merge pull request #39 from felipenv/master
Browse files Browse the repository at this point in the history
- fix nmrse and forecast_step loop.
  • Loading branch information
petroniocandido committed Mar 3, 2021
2 parents e536b0d + 49300f7 commit 98d6b63
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions pyFTS/benchmarks/Measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,30 @@ def acf(data, k):
return 1 / ((n - k) * sigma) * s


def rmse(targets, forecasts, order, steps_ahead):
def rmse(targets, forecasts, order=0, offset=0):
"""
Root Mean Squared Error
:param targets:
:param forecasts:
:param targets: array of targets
:param forecasts: array of forecasts
:param order: model order
:param offset: forecast offset related to target.
:return:
"""
if isinstance(targets, list):
targets = np.array(targets)
if isinstance(forecasts, list):
forecasts = np.array(forecasts)
return np.sqrt(np.nanmean((targets[order+steps_ahead:] - forecasts[:-steps_ahead]) ** 2))

if offset == 0:
return np.sqrt(np.nanmean((targets[order:] - forecasts[:]) ** 2))
else:
return np.sqrt(np.nanmean((targets[order+offset:] - forecasts[:-offset]) ** 2))


def nmrse(targets, forecasts, order, steps_ahead):
def nmrse(targets, forecasts, order=0, offset=0):
""" Normalized Root Mean Squared Error """
return rmse(targets, forecasts, order, steps_ahead) / (np.max(targets) - np.min(targets)) ## normalizing in targets because on forecasts might explode to inf (when model predict a line)
return rmse(targets, forecasts, order, offset) / (np.max(targets) - np.min(targets)) ## normalizing in targets because on forecasts might explode to inf (when model predict a line)



Expand Down
2 changes: 1 addition & 1 deletion pyFTS/common/fts.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def forecast_step(self, data, step, **kwargs):

start = kwargs.get('start_at',0)

for k in np.arange(start+self.max_lag, l):
for k in np.arange(start+self.max_lag, l+1):
sample = data[k-self.max_lag:k]
tmp = self.forecast_ahead(sample, step, **kwargs)

Expand Down

0 comments on commit 98d6b63

Please sign in to comment.