Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: stan-dev/stan
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 47e95419c12cf1f86264fa1de7319998c1e02fca
Choose a base ref
...
head repository: stan-dev/stan
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a8fd956ca05fa2a86809cb40a9f7e19ed7bb9afc
Choose a head ref
  • 8 commits
  • 4 files changed
  • 2 contributors

Commits on Feb 3, 2014

  1. Merge remote-tracking branch 'origin/develop' into bugfix/issue-530-n…

    …o-model-parameters
    
    Getting feature #353.
    ksvanhorn committed Feb 3, 2014
    Copy the full SHA
    2dfaea5 View commit details
  2. ps_point::_fast_vector_copy and ps_point::_fast_matrix_copy now check…

    … for zero-byte sources.
    ksvanhorn committed Feb 3, 2014
    Copy the full SHA
    51be3e0 View commit details

Commits on Feb 11, 2014

  1. Copy the full SHA
    df6c9ff View commit details
  2. Copy the full SHA
    1d6cb5c View commit details

Commits on Feb 17, 2014

  1. Merge branch 'develop' of https://github.com/stan-dev/stan into bugfi…

    …x/issue-530-no-model-parameters
    ksvanhorn committed Feb 17, 2014
    Copy the full SHA
    0040d0c View commit details

Commits on Feb 18, 2014

  1. Manual now mentions that algorithm=fixed_param is mandatory when the …

    …parameters block is empty.
    ksvanhorn committed Feb 18, 2014
    Copy the full SHA
    070f5da View commit details

Commits on Mar 7, 2014

  1. Merge branch 'develop' into bugfix/issue-530-no-model-parameters: mov…

    …ing test to CmdStan branch bugfix/issue-530-no-model-parameters
    
    Conflicts:
    	src/test/CmdStan/fixed_param_sampler_test.cpp
    syclik committed Mar 7, 2014
    Copy the full SHA
    f1373d2 View commit details

Commits on Mar 8, 2014

  1. Merge pull request #570 from stan-dev/bugfix/issue-530-no-model-param…

    …eters
    
    Fixes #530. Bugfix/issue 530 no model parameters
    syclik committed Mar 8, 2014
    Copy the full SHA
    a8fd956 View commit details
2 changes: 1 addition & 1 deletion src/docs/stan-reference/commands.tex
Original file line number Diff line number Diff line change
@@ -1319,7 +1319,7 @@ \subsubsection{Fixed Parameter Sampler}
The fixed parameter sampler generates a new sample without changing
the current state of the Markov chain; only generated quantities may
change. This can be useful when, for example, trying to generate pseudo-data
using the generated quantities block.
using the generated quantities block. If the parameters block is empty (no parameters) then using {\tt algorithm=fixed\_param} is mandatory.
%
\begin{description}
\hierlongcmd{\indentarrow\indentarrow\indentarrow}{\farg{\bfseries fixed\_param}}
9 changes: 8 additions & 1 deletion src/stan/common/command.hpp
Original file line number Diff line number Diff line change
@@ -148,7 +148,7 @@ namespace stan {
//////////////////////////////////////////////////

Model model(data_var_context, &std::cout);

Eigen::VectorXd cont_params = Eigen::VectorXd::Zero(model.num_params_r());

if (output_stream) {
@@ -603,6 +603,13 @@ namespace stan {
parser.arg("method")->arg("sample")->arg("adapt"));
bool adapt_engaged = dynamic_cast<stan::gm::bool_argument*>(adapt->arg("engaged"))->value();

if (model.num_params_r() == 0 && algo->value() != "fixed_param") {
std::cout
<< "Must use algorithm=fixed_param for model that has no parameters."
<< std::endl;
return -1;
}

if (algo->value() == "fixed_param") {

sampler_ptr = new stan::mcmc::fixed_param_sampler();
22 changes: 15 additions & 7 deletions src/stan/mcmc/hmc/hamiltonians/ps_point.hpp
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ namespace stan {

// Point in a generic phase space
class ps_point {
friend class ps_point_test;

public:

@@ -76,16 +77,23 @@ namespace stan {
protected:

template <typename T>
inline void _fast_vector_copy(Eigen::Matrix<T, Eigen::Dynamic, 1>& v_to, const Eigen::Matrix<T, Eigen::Dynamic, 1>& v_from) {
v_to.resize(v_from.size());
std::memcpy(&v_to(0), &v_from(0), v_from.size() * sizeof(double));
static inline void _fast_vector_copy(Eigen::Matrix<T, Eigen::Dynamic, 1>& v_to, const Eigen::Matrix<T, Eigen::Dynamic, 1>& v_from) {
int sz = v_from.size();
v_to.resize(sz);
if (sz > 0) {
std::memcpy(&v_to(0), &v_from(0), v_from.size() * sizeof(double));
}
}

template <typename T>
inline void _fast_matrix_copy(Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& v_to,
static inline void _fast_matrix_copy(Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& v_to,
const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& v_from) {
v_to.resize(v_from.rows(), v_from.cols());
std::memcpy(&v_to(0), &v_from(0), v_from.size() * sizeof(double));
int nr = v_from.rows();
int nc = v_from.cols();
v_to.resize(nr, nc);
if (nr > 0 && nc > 0) {
std::memcpy(&v_to(0), &v_from(0), v_from.size() * sizeof(double));
}
}

};
@@ -95,4 +103,4 @@ namespace stan {
} // stan


#endif
#endif
64 changes: 64 additions & 0 deletions src/test/unit/mcmc/hmc/hamiltonians/ps_point_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <gtest/gtest.h>
#include <stan/mcmc/hmc/hamiltonians/ps_point.hpp>

namespace stan {

namespace mcmc {

class ps_point_test : public ::testing::Test
{
public:
typedef Eigen::Matrix<double, Eigen::Dynamic, 1> vector_t;
typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> matrix_t;

static void fast_vector_copy()
{
vector_t from3(3); from3 << 5.25, 3.125, -6.5;
vector_t to3(12);
ps_point::_fast_vector_copy(to3, from3);

EXPECT_EQ(from3, to3);

int zero = 0;
vector_t from0(zero);
vector_t to0(7);
ps_point::_fast_vector_copy(to0, from0);

EXPECT_EQ(from0, to0);
}

static void fast_matrix_copy()
{
matrix_t from2_3(2, 3);
from2_3 << 5, 2, 7, -3, 4, -9;
matrix_t to2_3(1, 13);
ps_point::_fast_matrix_copy(to2_3, from2_3);

EXPECT_EQ(from2_3, to2_3);

int zero = 0;

matrix_t from2_0(2, zero);
matrix_t to2_0(8, 3);
ps_point::_fast_matrix_copy(to2_0, from2_0);

EXPECT_EQ(from2_0, to2_0);

matrix_t from0_5(zero, 5);
matrix_t to0_5(7, 4);
ps_point::_fast_matrix_copy(to0_5, from0_5);

EXPECT_EQ(from0_5, to0_5);
}

};

TEST(psPoint, fastVectorCopy) {
ps_point_test::fast_vector_copy();
}

TEST(psPoint, fastMatrixCopy) {
ps_point_test::fast_matrix_copy();
}
}
}