Skip to content

Commit

Permalink
version 0.6.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven L. Scott authored and cran-robot committed Aug 3, 2016
1 parent 5d0c4e5 commit e0f790d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 26 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Package: bsts
Date: 2016-03-10
Date: 2016-08-02
Title: Bayesian Structural Time Series
Author: Steven L. Scott <[email protected]>
Maintainer: Steven L. Scott <[email protected]>
Description: Time series regression using dynamic linear models fit using MCMC.
Depends: BoomSpikeSlab (>= 0.5.3), zoo, xts, Boom (>= 0.3), R(>= 3.1.0)
LinkingTo: Boom, BH (>= 1.15.0-2)
Version: 0.6.3
Version: 0.6.4
License: LGPL-2.1 | file LICENSE
Encoding: UTF-8
NeedsCompilation: yes
Packaged: 2016-03-11 16:00:47 UTC; stevescott
Packaged: 2016-08-02 16:47:46 UTC; stevescott
Repository: CRAN
Date/Publication: 2016-03-15 16:10:32
Date/Publication: 2016-08-03 10:09:37
10 changes: 5 additions & 5 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
db489ee2926cd564ad6ea09bf0a41e07 *DESCRIPTION
b36acbcd3679bf49aaf8e8713bcc7339 *DESCRIPTION
7eb09e6fd83eb49ed22911c3b2f06744 *LICENSE
77b0e5e553b77ad75d4e4a27e6a709c9 *NAMESPACE
3c5c0ab86b65f589f216f5b00493af8c *R/add.ar.R
Expand Down Expand Up @@ -72,16 +72,16 @@ d57163e548d8d3d98c73c076206cd4e2 *man/summary.bsts.Rd
ba703f81ad4be6d3ac29a85e9c8e397c *man/timeseries.boxplot.Rd
57af8d3de323423befb55d02ed034ada *man/week.ends.Rd
5442c109b338e0fe1e159ab48a2bf06d *src/Makevars
1eeee71e5c9b8d40de50d83b9660fa59 *src/aggregate_time_series.cc
6e67221598474c74ae2647663d084b53 *src/bsts.cc
78b9d1a324db8777ec461d6c23654880 *src/mixed_frequency.cc
329f5c2a4b884556265575b56e7c0cc7 *src/aggregate_time_series.cc
b9e63a061f7a09bc7a0ef13e660f1600 *src/bsts.cc
f246aff45481d5394c45b65d58d1dfba *src/mixed_frequency.cc
a018b30ec484c5246b0d8f4f5022eab3 *src/model_manager.cc
be96d943440bcad54510a233ebda6ed8 *src/model_manager.h
1fd9ab4d4c7476c1552b3bd2809ce92e *src/state_space_gaussian_model_manager.cc
d94a7f45f987cd281697ad728b8358c8 *src/state_space_gaussian_model_manager.h
78669ac7c6707568653f9178be79f222 *src/state_space_logit_model_manager.cc
f4f89c92a9a1ec5d47525613351c7b68 *src/state_space_logit_model_manager.h
b01c649ff283cee42350461cd0a440e3 *src/state_space_poisson_model_manager.cc
0979c1dd250e7864245f800935e39a4e *src/state_space_poisson_model_manager.cc
36526e9c92a816247aa58ca5ef5a2b47 *src/state_space_poisson_model_manager.h
84529a90869531b8bb986ef9d140d1f5 *src/state_space_regression_model_manager.cc
80e15c96df989cd2fde323ca89a7b515 *src/state_space_regression_model_manager.h
Expand Down
11 changes: 6 additions & 5 deletions src/aggregate_time_series.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "LinAlg/SubMatrix.hpp"
#include "LinAlg/Types.hpp"
#include "Rinternals.h"
#include "r_interface/boom_r_tools.hpp"

extern "C" {
// Sum the results of a fine-scale time series to a coarser scale.
Expand Down Expand Up @@ -83,13 +84,13 @@ extern "C" {
}
}

SEXP r_ans;
PROTECT(r_ans = Rf_isMatrix(r_fine_series)
? Rf_allocMatrix(REALSXP, num_fine_rows, num_coarse_time_points)
: Rf_allocVector(REALSXP, num_coarse_time_points));
BOOM::RMemoryProtector protector;
SEXP r_ans = protector.protect(
Rf_isMatrix(r_fine_series)
? Rf_allocMatrix(REALSXP, num_fine_rows, num_coarse_time_points)
: Rf_allocVector(REALSXP, num_coarse_time_points));
double *ans = REAL(r_ans);
std::copy(coarse_series.begin(), coarse_series.end(), ans);
UNPROTECT(1);
return r_ans;
}
}
8 changes: 4 additions & 4 deletions src/bsts.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <ctime>

#include "utils.h"
#include "model_manager.h"

Expand Down Expand Up @@ -34,6 +36,7 @@ SEXP fit_bsts_model_(
SEXP r_timeout_in_seconds,
SEXP r_seed) {
BOOM::RErrorReporter error_reporter;
BOOM::RMemoryProtector protector;
try {
BOOM::RInterface::seed_rng_from_R(r_seed);
BOOM::RListIoManager io_manager;
Expand Down Expand Up @@ -67,7 +70,7 @@ SEXP fit_bsts_model_(
int niter = lround(Rf_asReal(r_niter));
int ping = lround(Rf_asReal(r_ping));
double timeout_threshold_seconds = Rf_asReal(r_timeout_in_seconds);
SEXP ans = PROTECT(io_manager.prepare_to_write(niter));
SEXP ans = protector.protect(io_manager.prepare_to_write(niter));
clock_t start_time = clock();
double time_threshold = CLOCKS_PER_SEC * timeout_threshold_seconds;
for (int i = 0; i < niter; ++i) {
Expand All @@ -90,7 +93,6 @@ SEXP fit_bsts_model_(
<< double(current_time - start_time) / CLOCKS_PER_SEC
<< " seconds.";
Rf_warning(warning.str().c_str());
UNPROTECT(1);
return BOOM::appendListElement(
ans,
ToRVector(BOOM::Vector(1, i + 1)),
Expand All @@ -103,13 +105,11 @@ SEXP fit_bsts_model_(
<< "iteration " << i << ". Aborting." << std::endl
<< e.what() << std::endl;
error_reporter.SetError(err.str());
UNPROTECT(1);
return BOOM::appendListElement(ans,
ToRVector(Vector(1, i)),
"ngood");
}
}
UNPROTECT(1);
return ans;
} catch (std::exception &e) {
BOOM::RInterface::handle_exception(e);
Expand Down
4 changes: 2 additions & 2 deletions src/mixed_frequency.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ extern "C" {
SEXP r_seed,
SEXP r_truth) {
RErrorReporter error_reporter;
BOOM::RMemoryProtector protector;
try {
BOOM::RInterface::seed_rng_from_R(r_seed);

Expand Down Expand Up @@ -378,7 +379,7 @@ extern "C" {

int niter = Rf_asInteger(r_niter);
int ping = Rf_asInteger(r_ping);
SEXP ans = PROTECT(io_manager.prepare_to_write(niter));
SEXP ans = protector.protect(io_manager.prepare_to_write(niter));

for (int i = 0; i < niter; ++i) {
if (RCheckInterrupt()) {
Expand Down Expand Up @@ -411,7 +412,6 @@ extern "C" {
return R_NilValue;
}
}
UNPROTECT(1);
return ans;
} catch(std::exception &e) {
handle_exception(e);
Expand Down
25 changes: 19 additions & 6 deletions src/state_space_poisson_model_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "r_interface/prior_specification.hpp"

#include "cpputil/math_utils.hpp"

#include "Models/StateSpace/PosteriorSamplers/StateSpacePoissonPosteriorSampler.hpp"
#include "Models/Glm/PosteriorSamplers/PoissonRegressionSpikeSlabSampler.hpp"
#include "Models/Glm/PosteriorSamplers/PoissonDataImputer.hpp"
Expand All @@ -13,8 +15,18 @@ namespace BOOM {
namespace bsts {

namespace {
typedef StateSpacePoissonModelManager SSPMM;
}
typedef StateSpacePoissonModelManager SSPMM;
void zero_missing_values(
Vector *counts,
Vector *exposure,
const std::vector<bool> &observed) {
for (size_t i = 0; i < counts->size(); ++i) {
if (!observed[i]) {
(*counts)[i] = (*exposure)[i] = 0;
}
}
}
} // namespace

SSPMM::StateSpacePoissonModelManager()
: predictor_dimension_(-1) {}
Expand All @@ -37,6 +49,7 @@ StateSpacePoissonModel * SSPMM::CreateObservationModel(
Matrix(counts.size(), 1.0);
std::vector<bool> response_is_observed(ToVectorBool(getListElement(
r_data_list, "response.is.observed")));
zero_missing_values(&counts, &exposure, response_is_observed);
model_.reset(
new StateSpacePoissonModel(
counts,
Expand Down Expand Up @@ -165,18 +178,18 @@ void SSPMM::AddData(const Vector &counts,
const Matrix &predictors,
const std::vector<bool> &is_observed) {
for (int i = 0; i < counts.size(); ++i) {
bool missing = (!is_observed.empty() && !is_observed[i]);
Ptr<StateSpace::AugmentedPoissonRegressionData> data_point(
new StateSpace::AugmentedPoissonRegressionData(
counts[i],
exposure[i],
missing ? 0 : counts[i],
missing ? 0 : exposure[i],
predictors.row(i)));
if (!is_observed.empty() && !is_observed[i]) {
if (missing) {
data_point->set_missing_status(Data::missing_status::completely_missing);
}
model_->add_data(data_point);
}
}


} // namespace bsts
} // namespace BOOM

0 comments on commit e0f790d

Please sign in to comment.