Skip to content

Commit

Permalink
Merge pull request #286 from robfairh/timeseries
Browse files Browse the repository at this point in the history
backsteps
  • Loading branch information
gwenchee authored Aug 6, 2019
2 parents 8546257 + f2fb746 commit 63cb844
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ and stochastic-optimizing.
There are three methods implemented for the NO models. Autoregressive
moving average (ARMA), and autoregressive conditional heteroskedasticity (ARCH).
There are four parameters users can define:
- **steps**: Number of timesteps forward to prdict supply and demand (default = 2)
- **back_steps**: Number of steps backwards from the current timestep to use for the prediction (default = 10)
- **steps**: Number of timesteps forward to prdict supply and demand (default = 1)
- **back_steps**: Number of steps backwards from the current timestep to use for the prediction (default = 5)
- **supply_std_dev** = Standard deviation adjustment for supply (default = 0)
- **demand_std_dev** = Standard deviation adjustment for demand (default = 0)

Expand Down
14 changes: 5 additions & 9 deletions d3ploy/NO_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ def predict_ma(ts, steps=5, std_dev=0, back_steps=5):
x : The moving average calculated by the function.
"""
supply = np.array(list(ts.values()))
if steps >= len(supply):
steps = len(supply) * -1
else:
steps *= -1
x = np.average(supply[steps:])
x = np.average(supply[-1*back_steps:])
return x


Expand All @@ -56,7 +52,7 @@ def predict_arma(ts, steps=5, std_dev=0, back_steps=5):
forecast = fit.forecast(steps)
x = forecast[0][steps-1] + forecast[1][steps-1]*std_dev
except (ValueError, np.linalg.linalg.LinAlgError):
x = predict_ma(ts)
x = predict_ma(ts, steps, std_dev, back_steps)
return x


Expand All @@ -67,15 +63,15 @@ def predict_arch(ts, steps=1, std_dev=0, back_steps=2):
calculation to perform the prediciton.
"""
v = list(ts.values())
v = v[-1*2:]
v = v[-1*back_steps:]
try:
model = arch_model(v)
fit = model.fit(disp="off", show_warning=False)
forecast = fit.forecast(horizon=steps)
step = 'h.' + str(steps)
x = forecast.mean.get(step)[len(v)-steps]
except:
x = predict_ma(ts, steps=1)
x = predict_ma(ts, steps, std_dev, back_steps)
if math.isnan(x):
x = predict_ma(ts, steps=1)
x = predict_ma(ts, steps, std_dev, back_steps)
return x
2 changes: 1 addition & 1 deletion d3ploy/demand_driven_deployment_inst.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class DemandDrivenDeploymentInst(Institution):
"then the calculation will use all values in the time series.",
tooltip="",
uilabel="Back Steps",
default=10)
default=5)

supply_std_dev = ts.Double(
doc="The standard deviation adjustment for the supple side.",
Expand Down
2 changes: 1 addition & 1 deletion d3ploy/supply_driven_deployment_inst.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class SupplyDrivenDeploymentInst(Institution):
"will use all values in the time series.",
tooltip="",
uilabel="Back Steps",
default=10
default=5
)

capacity_std_dev = ts.Double(
Expand Down
8 changes: 4 additions & 4 deletions tests/integration_tests/installedcap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"facility_commod": {"item": {"commod": "fuel", "facility": "source"}},
"installed_cap": "1",
"record": "0",
"steps": "1"
"back_steps": "1"
}
},
"name": "non_driving_inst"
Expand All @@ -111,7 +111,7 @@
"facility_commod": {"item": {"commod": "POWER", "facility": "reactor"}},
"installed_cap": "1",
"record": "0",
"steps": "1"
"back_steps": "1"
}
},
"name": "driving_inst"
Expand Down Expand Up @@ -183,7 +183,7 @@ def test_installed_cap():
"facility_commod": {"item": {"commod": "fuel", "facility": "source"}},
"installed_cap": "1",
"record": "0",
"steps": "1"
"back_steps": "1"
}
},
"name": "non_driving_inst"
Expand All @@ -198,7 +198,7 @@ def test_installed_cap():
"facility_commod": {"item": {"commod": "POWER", "facility": "reactor"}},
"installed_cap": "1",
"record": "0",
"steps": "1"
"back_steps": "1"
}
},
"initialfacilitylist": {"entry": {"number": "1", "prototype": "reactor"}},
Expand Down

0 comments on commit 63cb844

Please sign in to comment.