Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into bugfix/issue-530-n…
Browse files Browse the repository at this point in the history
…o-model-parameters
  • Loading branch information
ksvanhorn committed Feb 11, 2014
2 parents df6c9ff + b548485 commit 1d6cb5c
Show file tree
Hide file tree
Showing 63 changed files with 2,765 additions and 1,274 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ src/test/test-models/**/*
!src/test/test-models/**/*.stan
!src/test/test-models/**/.gitignore


# tests: generated agrad tests
src/test/unit-distribution/**/**/**/*_generated_test.cpp

Expand Down
6 changes: 4 additions & 2 deletions make/tests
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ test/unit/io/mcmc_writer.o: src/test/test-models/no-main/io_example.cpp
test/unit/gm/command_init.o: src/test/test-models/no-main/gm/test_lp.cpp
test/unit/gm/generator.o: src/test/test-models/no-main/gm/test_lp.cpp

test/unit/model/util.o: src/test/test-models/no-main/model/valid.cpp src/test/test-models/no-main/model/domain_fail.cpp

test/unit/mcmc/hmc/hamiltonians/base_hamiltonian.o: src/test/test-models/no-main/mcmc/hmc/hamiltonians/funnel.cpp
test/unit/mcmc/hmc/hamiltonians/unit_e_metric.o: src/test/test-models/no-main/mcmc/hmc/hamiltonians/funnel.cpp
test/unit/mcmc/hmc/hamiltonians/diag_e_metric.o: src/test/test-models/no-main/mcmc/hmc/hamiltonians/funnel.cpp
Expand All @@ -211,7 +213,7 @@ test/integration/compile_models.o : $(patsubst %.stan,%$(EXE),$(FILES)) $(patsub

test/CmdStan/command.o: \
$(addprefix src/test/test-models/compiled/CmdStan/,\
$(addsuffix $(EXE), printer domain_fail value_fail))
$(addsuffix $(EXE), printer domain_fail value_fail proper))
test/CmdStan/gm/argument_configuration.o: src/test/test-models/compiled/CmdStan/test_model$(EXE)
test/CmdStan/fixed_param_sampler.o: src/test/test-models/compiled/CmdStan/empty$(EXE) src/test/test-models/compiled/CmdStan/proper$(EXE)

Expand Down Expand Up @@ -288,7 +290,7 @@ test-headers: $(HEADER_TESTS)
test-unit test-distributions test-models test-bugs test-all:
@echo ''
@echo ''
@echo ' The '$@' target is deprecated. Please use:'
@echo ' The '$@' target is deprecated. Please use these make targets instead:'
@echo ' '$^

test-unit: src/test/unit src/test/unit-agrad-rev src/test/unit-agrad-fwd
Expand Down
44 changes: 29 additions & 15 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,28 @@ endif
@echo ' - doxygen : Builds the API documentation. The documentation is located'
@echo ' doc/api/'
@echo ' (requires doxygen installation)'
@echo ' Tests (requires make 3.81 or higher):'
@echo ' - test-headers : Compiles a trivial file after including each '
@echo ' header separately'
@echo ' - For any subdirectory directory in *src/test*, all tests within'
@echo ' the specified directory and subdirectories can be compiled '
@echo ' and executed by using the folder as the target (without a trailing slash).'
@echo ' Examples:'
@echo ' * all unit tests: src/test/unit'
@echo ' * unit tests for meta: src/test/unit/meta'
@echo ' * normal distribution tests: src/test/unit-distribution/univariate/continuous/normal'
@echo ' - test-all : Runs all tests.'
@echo ' TESTS (requires make 3.81 or higher):'
@echo ''
@echo ' All Tests'
@echo ' - test-all'
@echo ''
@echo ' Header Tests'
@echo ' - test-headers'
@echo ''
@echo ' Unit Tests'
@echo ' The unit tests are broken into three targets:'
@echo ' - src/test/unit'
@echo ' - src/test/unit-agrad-rev'
@echo ' - src/test/unit-agrad-fwd'
@echo ''
@echo ' Subdirectory of Unit Tests'
@echo ' For example, to run the unit tests under meta'
@echo ' - src/test/unit/meta'
@echo ''
@echo ' Single Unit Test'
@echo ' For example, to run the diag_post_multiply test, make the target'
@echo ' - test/unit-agrad-fwd/matrix/diag_post_multiply$(EXE)'
@echo ''
@echo ' Clean:'
@echo ' - clean : Basic clean. Leaves doc and compiled libraries intact.'
@echo ' - clean-all : Cleans up all of Stan.'
Expand All @@ -180,13 +191,16 @@ endif
@echo ''
@echo ' Warning: Deprecated test targets'
@echo ' - test-unit : Runs unit tests.'
@echo ' Replace with: src/test/unit src/test/unit-agrad-rev src/test/unit-agrad-fwd'
@echo ' This has been split into 3 separate targets:'
@echo ' src/test/unit'
@echo ' src/test/unit-agrad-rev'
@echo ' src/test/unit-agrad-fwd'
@echo ' - test-distributions : Runs unit tests for the distributions'
@echo ' Replace with: src/test/unit-distribution'
@echo ' Use this target instead: src/test/unit-distribution'
@echo ' - test-models : Runs diagnostic models.'
@echo ' Replace with: src/test/CmdStan/models'
@echo ' Use this target instead: src/test/CmdStan/models'
@echo ' - test-bugs : Runs the bugs examples (subset of test-models).'
@echo ' Replace with: src/test/CmdStan/models/bugs_examples'
@echo ' Use this target instead: src/test/CmdStan/models/bugs_examples'
@echo ''
@echo '--------------------------------------------------------------------------------'

Expand Down
9 changes: 5 additions & 4 deletions src/docs/stan-reference/acknowledgements.tex
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ \section*{Individuals}
\subsection*{Code and Doc Patches}

Thanks for bug reports, code patches, pull requests, and diagonistics
to: Ethan Adams, Jeffrey Arnold, David R.~Blair, Ross Boylan, Eric N.~Brown, Devin
Caughey, Ctross (GitHub ID), Robert Goedman, Marco Inacio, B.~Harris,
Andrew Hunter, Dan Lakeland, Devin Leopold, P.~D.~Metcalfe, Jeffrey
Oldham, Fernando H.~Toledo, and Zhenming Su.
to: Ethan Adams, Jeffrey Arnold, David R.~Blair, Ross Boylan, Eric
N.~Brown, Devin Caughey, Ctross (GitHub ID), Robert Goedman, Marco
Inacio, B.~Harris, Andrew Hunter, Filip Krynicki, Dan Lakeland, Devin
Leopold, P.~D.~Metcalfe, Jeffrey Oldham, Fernando H.~Toledo, and
Zhenming Su.

Thanks for documentation bug reports and patches to: Jeffrey Arnold,
Asim, Luca Billi, Eric C.~Brown, Seth Flaxman, Wayne Folta, Mauricio
Expand Down
68 changes: 47 additions & 21 deletions src/docs/stan-reference/functions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,22 @@ \chapter{Void Functions}
\section{Increment Log Probability}

There is a special function \code{increment\_log\_prob} takes a single
real-valued argument and adds the result to the log probability.
argument of any expression type \code{T}.
%
\begin{description}
\fitem{void}{increment\_log\_prob}{real \farg{lp}}{Add \farg{lp} to
the total log probability accumulator returned by the log
probability function defined by a Stan model.}
\fitem{void}{increment\_log\_prob}{T \farg{lp}}{Add \farg{lp} (or
elements of \farg{lp} if \code{T} is a container type) to the
total log probability accumulator returned by the log probability
function defined by a Stan model.}
\end{description}
%
The expression \code{lp} can be of any expression type. Specifically,
it can be an integer or real primitive, a vector, row vector, or
matrix, or an array of any type, including multidimensional arrays and
arrays of matrices, vectors, or row vectors. Vector arguments are
included for convenience and have no speed advantage over adding
values in a loop.

The full behavior of the \code{increment\_log\_prob} statement and its
relation to sampling statements is described in
\refsection{increment-log-prob}.
Expand Down Expand Up @@ -1085,26 +1093,44 @@ \subsection{Moments}
elements in \farg{x}}
\end{description}

% \subsection{Distance and Squared Distance}
\subsection{Distance and Squared Distance}

\begin{description}
\fitem{real}{distance}{vector \farg{x}, vector \farg{y}}{The Euclidean
distance between \farg{x} and \farg{y}, defined by
\[
\mbox{distance}(\mbox{\farg{x}},\mbox{\farg{y}})
= \sqrt{\textstyle \sum_{n=1}^N (\mbox{\farg{x}}[n] - \mbox{\farg{y}}[n])^2},
\]
where \code{N} is the size of \farg{x} and \farg{y}.}
%
% \fitem{real}{dist}{real \farg{x}[], real \farg{y}[]}{The Euclidean
% distance between \farg{x} and \farg{y}, defined by
% \[
% \mbox{dist}(\mbox{\farg{x}},\mbox{\farg{y}})
% = \sqrt{\textstyle \sum_{n=1}^N (\mbox{\farg{x}}[n] - \mbox{\farg{y}}[n])^2},
% \]
% where \code{N} is the size of \farg{x} and \farg{y}.
% }
\fitem{real}{distance}{vector \farg{x}, row\_vector \farg{y}}{The Euclidean
distance between \farg{x} and \farg{y}}
%
% \fitem{real}{squared\_dist}{real \farg{x}[], real \farg{y}[]}{The Euclidean
% distance between \farg{x} and \farg{y}, defined by
% \[
% \mbox{squared\_dist}(\mbox{\farg{x}},\mbox{\farg{y}})
% = \textstyle \sum_{n=1}^N (\mbox{\farg{x}}[n] - \mbox{\farg{y}}[n])^2,
% \]
% where \code{N} is the size of \farg{x} and \farg{y}.
% }
\fitem{real}{distance}{row\_vector \farg{x}, vector \farg{y}}{The Euclidean
distance between \farg{x} and \farg{y}}
%
\fitem{real}{distance}{row\_vector \farg{x}, row\_vector \farg{y}}{The Euclidean
distance between \farg{x} and \farg{y}}
%
\fitem{real}{squared\_distance}{vector \farg{x}, vector \farg{y}[]}{The Euclidean
distance between \farg{x} and \farg{y}, defined by
\[
\mbox{squared\_distance}(\mbox{\farg{x}},\mbox{\farg{y}})
= \textstyle \sum_{n=1}^N (\mbox{\farg{x}}[n] - \mbox{\farg{y}}[n])^2,
\]
where \code{N} is the size of \farg{x} and \farg{y}.}
%
\fitem{real}{squared\_distance}{vector \farg{x}, row\_vector \farg{y}[]}{The Euclidean
distance between \farg{x} and \farg{y}}
%
\fitem{real}{squared\_distance}{row\_vector \farg{x}, vector \farg{y}[]}{The Euclidean
distance between \farg{x} and \farg{y}}
%
\fitem{real}{squared\_distance}{row\_vector \farg{x}, row\_vector \farg{y}[]}{The Euclidean
distance between \farg{x} and \farg{y}}
%
\end{description}

\section{Array Size and Dimension Function}

Expand Down
8 changes: 8 additions & 0 deletions src/docs/stan-reference/language.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2365,6 +2365,13 @@ \section{Log Probability Increment Statement}\label{increment-log-prob.section}
normalizing constant $Z$ is either time-consuming to compute or
intractable to evaluate.

\subsubsection{Vectorization}

The \code{increment\_log\_prob} function accepts parameters of any
expression type, including integers, reals, vectors, row vectors,
matrices, and arrays of any dimensionality, including arrays of
vectors and matrices.

\subsection{Log Probability Variable \code{lp\_\_}}

Before version 2.0 of Stan, rather than writing
Expand Down Expand Up @@ -3840,6 +3847,7 @@ \subsection{Statements}
| 'for' '(' identifier 'in' expression ':' expression ')' statement
| '{' var_decl* statement+ '}'
| 'print' '(' (expression | string_literal)* ')'
| 'increment_log_prob '(' expression ')'
| ';'
string_literal ::= '"' char* '"'
Expand Down
2 changes: 1 addition & 1 deletion src/stan/agrad/rev/matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <stan/agrad/rev/matrix/sd.hpp>
#include <stan/agrad/rev/matrix/softmax.hpp>
#include <stan/agrad/rev/matrix/sort.hpp>
#include <stan/agrad/rev/matrix/squared_dist.hpp>
#include <stan/agrad/rev/matrix/squared_distance.hpp>
#include <stan/agrad/rev/matrix/stan_print.hpp>
#include <stan/agrad/rev/matrix/stored_gradient_vari.hpp>
#include <stan/agrad/rev/matrix/sum.hpp>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __STAN__AGRAD__REV__MATRIX__SQUARED_DIST_HPP__
#define __STAN__AGRAD__REV__MATRIX__SQUARED_DIST_HPP__
#ifndef __STAN__AGRAD__REV__MATRIX__SQUARED_DISTANCE_HPP__
#define __STAN__AGRAD__REV__MATRIX__SQUARED_DISTANCE_HPP__

#include <vector>
#include <stan/math/matrix/Eigen.hpp>
Expand All @@ -14,14 +14,14 @@
namespace stan {
namespace agrad {
namespace {
class squared_dist_vv_vari : public vari {
class squared_distance_vv_vari : public vari {
protected:
vari** v1_;
vari** v2_;
size_t length_;

template<int R1,int C1,int R2,int C2>
inline static double var_squared_dist(const Eigen::Matrix<var,R1,C1> &v1,
inline static double var_squared_distance(const Eigen::Matrix<var,R1,C1> &v1,
const Eigen::Matrix<var,R2,C2> &v2) {
double result = 0;
for (typename Eigen::Matrix<var,R1,C1>::size_type i = 0;
Expand All @@ -33,9 +33,9 @@ namespace stan {
}
public:
template<int R1,int C1,int R2,int C2>
squared_dist_vv_vari(const Eigen::Matrix<var,R1,C1> &v1,
squared_distance_vv_vari(const Eigen::Matrix<var,R1,C1> &v1,
const Eigen::Matrix<var,R2,C2> &v2)
: vari(var_squared_dist(v1, v2)), length_(v1.size())
: vari(var_squared_distance(v1, v2)), length_(v1.size())
{
v1_ = (vari**)memalloc_.alloc(length_*sizeof(vari*));
for (size_t i = 0; i < length_; i++)
Expand All @@ -53,14 +53,14 @@ namespace stan {
}
}
};
class squared_dist_vd_vari : public vari {
class squared_distance_vd_vari : public vari {
protected:
vari** v1_;
double* v2_;
size_t length_;

template<int R1,int C1,int R2,int C2>
inline static double var_squared_dist(const Eigen::Matrix<var,R1,C1> &v1,
inline static double var_squared_distance(const Eigen::Matrix<var,R1,C1> &v1,
const Eigen::Matrix<double,R2,C2> &v2) {
double result = 0;
for (typename Eigen::Matrix<var,R1,C1>::size_type i = 0;
Expand All @@ -72,9 +72,9 @@ namespace stan {
}
public:
template<int R1,int C1,int R2,int C2>
squared_dist_vd_vari(const Eigen::Matrix<var,R1,C1> &v1,
squared_distance_vd_vari(const Eigen::Matrix<var,R1,C1> &v1,
const Eigen::Matrix<double,R2,C2> &v2)
: vari(var_squared_dist(v1, v2)), length_(v1.size())
: vari(var_squared_distance(v1, v2)), length_(v1.size())
{
v1_ = (vari**)memalloc_.alloc(length_*sizeof(vari*));
for (size_t i = 0; i < length_; i++)
Expand All @@ -93,28 +93,28 @@ namespace stan {
}

template<int R1,int C1,int R2, int C2>
inline var squared_dist(const Eigen::Matrix<var, R1, C1>& v1,
inline var squared_distance(const Eigen::Matrix<var, R1, C1>& v1,
const Eigen::Matrix<var, R2, C2>& v2) {
stan::math::validate_vector(v1,"squared_dist");
stan::math::validate_vector(v2,"squared_dist");
stan::math::validate_matching_sizes(v1,v2,"squared_dist");
return var(new squared_dist_vv_vari(v1,v2));
stan::math::validate_vector(v1,"squared_distance");
stan::math::validate_vector(v2,"squared_distance");
stan::math::validate_matching_sizes(v1,v2,"squared_distance");
return var(new squared_distance_vv_vari(v1,v2));
}
template<int R1,int C1,int R2, int C2>
inline var squared_dist(const Eigen::Matrix<var, R1, C1>& v1,
inline var squared_distance(const Eigen::Matrix<var, R1, C1>& v1,
const Eigen::Matrix<double, R2, C2>& v2) {
stan::math::validate_vector(v1,"squared_dist");
stan::math::validate_vector(v2,"squared_dist");
stan::math::validate_matching_sizes(v1,v2,"squared_dist");
return var(new squared_dist_vd_vari(v1,v2));
stan::math::validate_vector(v1,"squared_distance");
stan::math::validate_vector(v2,"squared_distance");
stan::math::validate_matching_sizes(v1,v2,"squared_distance");
return var(new squared_distance_vd_vari(v1,v2));
}
template<int R1,int C1,int R2, int C2>
inline var squared_dist(const Eigen::Matrix<double, R1, C1>& v1,
inline var squared_distance(const Eigen::Matrix<double, R1, C1>& v1,
const Eigen::Matrix<var, R2, C2>& v2) {
stan::math::validate_vector(v1,"squared_dist");
stan::math::validate_vector(v2,"squared_dist");
stan::math::validate_matching_sizes(v1,v2,"squared_dist");
return var(new squared_dist_vd_vari(v2,v1));
stan::math::validate_vector(v1,"squared_distance");
stan::math::validate_vector(v2,"squared_distance");
stan::math::validate_matching_sizes(v1,v2,"squared_distance");
return var(new squared_distance_vd_vari(v2,v1));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/stan/gm/arguments/arg_refresh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace stan {
arg_refresh(): int_argument() {
_name = "refresh";
_description = "Number of interations between screen updates";
_validity = "0 < refresh";
_validity = "0 <= refresh";
_default = "100";
_default_value = 100;
_constrained = true;
Expand All @@ -23,7 +23,7 @@ namespace stan {
_value = _default_value;
};

bool is_valid(int value) { return value > 0; }
bool is_valid(int value) { return value >= 0; }

};

Expand Down
2 changes: 1 addition & 1 deletion src/stan/gm/arguments/argument.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace stan {
return _description;
}

virtual void print(std::ostream* s, const int depth, const char prefix) = 0;
virtual void print(std::ostream* s, const int depth, const std::string prefix) = 0;
virtual void print_help(std::ostream* s, const int depth, const bool recurse) = 0;

virtual bool parse_args(std::vector<std::string>& args,
Expand Down
9 changes: 4 additions & 5 deletions src/stan/gm/arguments/argument_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ namespace stan {
argument_parser(std::vector<argument*>& valid_args)
: _arguments(valid_args),
_help_flag(false),
_method_flag(false)
{
_method_flag(false) {
_arguments.insert(_arguments.begin(), new arg_method());
}

Expand Down Expand Up @@ -136,7 +135,7 @@ namespace stan {
error_codes::OK : error_codes::USAGE;
}

void print(std::ostream* s, const char prefix = '\0') {
void print(std::ostream* s, const std::string prefix = "") {
if (!s)
return;

Expand Down Expand Up @@ -164,8 +163,8 @@ namespace stan {
*s << std::left;

*s << "Usage: " << executable << " <arg1> <subarg1_1> ... <subarg1_m>"
<< " ... <arg_n> <subarg_n_1> ... <subarg_n_m>"
<< std::endl << std::endl;
<< " ... <arg_n> <subarg_n_1> ... <subarg_n_m>"
<< std::endl << std::endl;

*s << "Begin by selecting amongst the following inference methods"
<< " and diagnostics," << std::endl;
Expand Down
Loading

0 comments on commit 1d6cb5c

Please sign in to comment.