mirror of
https://github.com/saymrwulf/prophet.git
synced 2026-09-15 22:10:22 +00:00
Upgrade CmdStanPy interface (#1849)
* cmdstan variable extraction update * add backwards compatibility * Fix bug * Upgrade stan version in requirements and in CI testing Co-authored-by: Ben Letham <bletham@gmail.com>
This commit is contained in:
parent
8ffa0e02a6
commit
16472a5700
4 changed files with 10 additions and 6 deletions
6
.github/workflows/build-and-test.yml
vendored
6
.github/workflows/build-and-test.yml
vendored
|
|
@ -27,7 +27,7 @@ jobs:
|
||||||
cd python && python setup.py develop test
|
cd python && python setup.py develop test
|
||||||
python setup.py clean
|
python setup.py clean
|
||||||
rm -rf fbprophet/stan_model
|
rm -rf fbprophet/stan_model
|
||||||
wget https://github.com/stan-dev/cmdstan/releases/download/v2.22.1/cmdstan-2.22.1.tar.gz -O /tmp/cmdstan.tar.gz > /dev/null
|
wget https://github.com/stan-dev/cmdstan/releases/download/v2.26.1/cmdstan-2.26.1.tar.gz -O /tmp/cmdstan.tar.gz > /dev/null
|
||||||
tar -xvf /tmp/cmdstan.tar.gz -C /tmp > /dev/null
|
tar -xvf /tmp/cmdstan.tar.gz -C /tmp > /dev/null
|
||||||
make -C /tmp/cmdstan-2.22.1/ build > /dev/null
|
make -C /tmp/cmdstan-2.26.1/ build > /dev/null
|
||||||
CMDSTAN=/tmp/cmdstan-2.22.1 STAN_BACKEND=CMDSTANPY python setup.py develop test
|
CMDSTAN=/tmp/cmdstan-2.26.1 STAN_BACKEND=CMDSTANPY python setup.py develop test
|
||||||
|
|
|
||||||
|
|
@ -1170,6 +1170,7 @@ class Prophet(object):
|
||||||
else:
|
else:
|
||||||
self.params = self.stan_backend.fit(stan_init, dat, **kwargs)
|
self.params = self.stan_backend.fit(stan_init, dat, **kwargs)
|
||||||
|
|
||||||
|
self.stan_fit = self.stan_backend.stan_fit
|
||||||
# If no changepoints were requested, replace delta with 0s
|
# If no changepoints were requested, replace delta with 0s
|
||||||
if len(self.changepoints) == 0:
|
if len(self.changepoints) == 0:
|
||||||
# Fold delta into the base rate k
|
# Fold delta into the base rate k
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ class CmdStanPyBackend(IStanBackend):
|
||||||
inits=stan_init,
|
inits=stan_init,
|
||||||
iter_sampling=iter_half,
|
iter_sampling=iter_half,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
res = self.stan_fit.sample
|
res = self.stan_fit.draws()
|
||||||
(samples, c, columns) = res.shape
|
(samples, c, columns) = res.shape
|
||||||
res = res.reshape((samples * c, columns))
|
res = res.reshape((samples * c, columns))
|
||||||
params = self.stan_to_dict_numpy(self.stan_fit.column_names, res)
|
params = self.stan_to_dict_numpy(self.stan_fit.column_names, res)
|
||||||
|
|
@ -182,7 +182,10 @@ class CmdStanPyBackend(IStanBackend):
|
||||||
end = 0
|
end = 0
|
||||||
two_dims = len(data.shape) > 1
|
two_dims = len(data.shape) > 1
|
||||||
for cname in column_names:
|
for cname in column_names:
|
||||||
|
if "." in cname:
|
||||||
parsed = cname.split(".")
|
parsed = cname.split(".")
|
||||||
|
else:
|
||||||
|
parsed = cname.split("[")
|
||||||
|
|
||||||
curr = parsed[0]
|
curr = parsed[0]
|
||||||
if prev is None:
|
if prev is None:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
Cython>=0.22
|
Cython>=0.22
|
||||||
cmdstanpy==0.9.5
|
cmdstanpy==0.9.68
|
||||||
pystan>=2.14
|
pystan>=2.14
|
||||||
numpy>=1.15.4
|
numpy>=1.15.4
|
||||||
pandas>=1.0.4
|
pandas>=1.0.4
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue