Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stan refactor #2004

Merged
merged 134 commits into from Jan 9, 2017
Merged
Show file tree
Hide file tree
Changes from 131 commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
630a7ec
Moving src/stan/services to src/stan/old_services
syclik Jun 13, 2016
8761a55
Adding an empty_var_context
syclik Jun 14, 2016
a241c7a
Implemented a random_var_context
syclik Jun 16, 2016
c226c91
Adding diagnose service method
syclik Jun 18, 2016
d78a6e0
Adding optimize::bfgs service method
syclik Jun 20, 2016
b993b41
Adding optimize::lbfgs service method
syclik Jun 20, 2016
24b1902
Adding optimize::newton service method
syclik Jun 21, 2016
bd90426
Simplifying mcmc_writer
syclik Jun 24, 2016
74f7fb6
Adding sample::fixed_param
syclik Jun 24, 2016
9091931
Adding a stan::services::util::rng function to create rngs
syclik Jun 28, 2016
5f356be
Updated service methods to use stan::services::util::rng()
syclik Jun 28, 2016
86e7c40
Updating diagnose to use initialize
syclik Jun 28, 2016
cfe30cd
Updating initialize code
syclik Jun 28, 2016
2bf8e14
Using stan::services::util::initialize
syclik Jun 28, 2016
4e5ad0c
Updating mcmc_writer
syclik Jun 29, 2016
5a27f99
Adding services::sample::hmc_nuts_dense_e
syclik Jun 29, 2016
531160b
Adding run_adaptive_sampler
syclik Jun 29, 2016
408d718
Adding services::sample::hmc_nuts_dense_e_adapt
syclik Jun 29, 2016
7f7c695
Adding sample service methods
syclik Jun 30, 2016
bb68a7e
Adding rest of sample serivces
syclik Jun 30, 2016
2058c4d
Adding variational service methods
syclik Jul 3, 2016
700d4df
cpplint
syclik Jul 3, 2016
56549bf
Updating tests
syclik Jul 3, 2016
bfb59f5
doxygen
syclik Jul 5, 2016
908a014
Moving mcmc_writer
syclik Jul 5, 2016
ffb0cf2
Moving mcmc_writer
syclik Jul 5, 2016
29f6c4c
Moving error_codes
syclik Jul 5, 2016
d380706
removing progress call from services
syclik Jul 5, 2016
2d56c41
Updating makefile
syclik Jul 5, 2016
05c63db
Adding an init_writer to all the service calls
syclik Jul 7, 2016
ccf8aa9
Adding init_writer
syclik Jul 8, 2016
e205551
Removing dependence on old_services
syclik Jul 8, 2016
387e8f7
Moving arguments to CmdStan
syclik Jul 17, 2016
419ab42
Updating performance test to use the service method
syclik Jul 20, 2016
57c5c93
Renaming stan::interface_callbacks to stan::callbacks
syclik Jul 20, 2016
16d9a72
Moving stan::callbacks::interrupt
syclik Jul 20, 2016
5bb15ca
Changing initialization on unconstrained scale to not transform round…
syclik Jul 27, 2016
524986d
Moving stan/old_services/variational/print_progress.hpp to stan/varia…
syclik Aug 8, 2016
ec144ac
Updating variational services call
syclik Aug 8, 2016
89aadd6
Removing old code
syclik Aug 8, 2016
00ef3bc
Updating initialization code to match existing implementation
syclik Aug 9, 2016
d0e0b82
cpplint
syclik Aug 9, 2016
f589d77
Adding in argument for random_var_context_test.cpp
syclik Aug 9, 2016
ebee819
Updating test
syclik Aug 9, 2016
462b6cf
Updating travis yml
syclik Aug 9, 2016
d052b49
Removing src/stan/callbacks/var_context_factory/*; it's unused now
syclik Aug 9, 2016
feda4a2
Renaming stan/callbacks/writer
syclik Aug 9, 2016
bece850
Merge branch 'feature/issue-1751-service-methods' of github.com:sakre…
sakrejda Aug 12, 2016
dc2f43e
Added test for fixed_param.hpp
sakrejda Aug 12, 2016
8d28dad
Added basic tests for generate_transitions and interrupt callback the…
sakrejda Aug 12, 2016
3fc35ad
Updating interrupts; adding interrupt to finite_diff call
syclik Aug 13, 2016
f614952
Defaults for diagnose
syclik Aug 16, 2016
4fc003f
Squashing warning from test code
syclik Aug 16, 2016
c3dba30
Starting to add defaults for ADVI
syclik Aug 29, 2016
26d4865
Merge branch 'develop' into feature/issue-1751-service-methods
syclik Aug 29, 2016
ea9bf6c
Merge branch 'develop' into feature/issue-1751-service-methods
syclik Sep 9, 2016
737520b
Add instrumented callbacks used for testing as well as a test demonst…
sakrejda Sep 12, 2016
d8a61fc
One more include was missing from util.hpp.
sakrejda Sep 12, 2016
7f4a13a
Merge branch 'develop' into feature/issue-1751-service-methods
syclik Sep 12, 2016
6349c41
Updating calls to writer
syclik Sep 12, 2016
13c25e4
Updating includes
syclik Sep 12, 2016
c6121a0
Updating defaults code.
syclik Sep 12, 2016
21b7bc4
The math include was accidentally removed in a merge
syclik Sep 12, 2016
fe25f74
fixing typo
syclik Sep 12, 2016
e089a40
Fixing services unit tests
syclik Sep 12, 2016
83acaae
Updating tests
syclik Sep 12, 2016
f9588b3
Adding tests for all defaults
syclik Sep 12, 2016
a307555
Updating more tests
syclik Sep 12, 2016
c41cd0b
Trying to squash compiler warnings
syclik Sep 12, 2016
74303af
Updating includes
syclik Sep 12, 2016
d4e7a06
Updating initialize
syclik Sep 12, 2016
6ddb1bc
cpplint
syclik Sep 12, 2016
777dfb7
Updating documentation
syclik Sep 13, 2016
6a77da2
Updated test to use callback/writer classes---won't pass yet.
koxpvp1337 Sep 28, 2016
e23aa24
generate_transitions basic test split up to call counting and output …
koxpvp1337 Sep 28, 2016
72df03d
Fixed param basic test work. Split out the exact output regression t…
koxpvp1337 Sep 28, 2016
ddb4fb7
Added hmc_nuts_dense_e_adapt test but haven't figured out the correct…
koxpvp1337 Sep 28, 2016
c07c74d
hmc_nuts_dense_e_adapt tests now pass though the exact output regress…
koxpvp1337 Sep 28, 2016
c255ba7
Less failing on exact output. We need a way to snapshot if we're goi…
koxpvp1337 Sep 28, 2016
0456dfe
Removed warnings so unit tests pass.
koxpvp1337 Sep 28, 2016
e7b3ea9
Added hmc_nuts_dense_e test, same basic stuff.
koxpvp1337 Sep 28, 2016
5f60d20
Fixed character-counting.
sakrejda Sep 29, 2016
ec18460
Added diag tests, still just boilerplate for the regression tests w/-…
koxpvp1337 Oct 4, 2016
79daf7b
Call counting and parameter/iteration counting on output for hmc_nuts…
koxpvp1337 Oct 4, 2016
3bfa61d
Basic hmc_static test and dependencies.
koxpvp1337 Oct 4, 2016
3df59d6
Basic hmc_static tests for two calls.
koxpvp1337 Oct 4, 2016
7ba89de
Updating make/tests
syclik Oct 5, 2016
cd13dc4
hmc_static_diag_e_adapt basic tests.
koxpvp1337 Oct 5, 2016
a5b7513
hmc_static_diag_e basic tests.
koxpvp1337 Oct 5, 2016
8a4e997
Merge branch 'feature/issue-1751-service-methods' of github.com:stan-…
koxpvp1337 Oct 5, 2016
e006b74
Adding test for chained_writer
syclik Oct 5, 2016
2100505
Adding test for noop_interrupt
syclik Oct 5, 2016
ce6267f
Adding tests for advi services
syclik Oct 5, 2016
4dfb24c
Adding test for experimental message
syclik Oct 5, 2016
ae22860
Updating doc for initialization; adding tests
syclik Oct 6, 2016
cdbf25c
Updating test
syclik Oct 6, 2016
03207db
Updating indenting
syclik Oct 6, 2016
c7523c5
Adding doc and test for run_sampler
syclik Oct 7, 2016
8c3343d
Adding doc and test for run_adaptive_sampler
syclik Oct 8, 2016
56964cb
Adding tests for mcmc_writer.hpp
syclik Oct 8, 2016
0441cca
Merge branch 'develop' into feature/issue-1751-service-methods
syclik Oct 8, 2016
cce23ca
Changing a few methods to static methods
syclik Oct 10, 2016
4fee83c
Changing one of the static methods back to a member method
syclik Oct 10, 2016
a1d9711
Updating order of writers to be more consistent with everything else
syclik Oct 11, 2016
ab9c34b
Merge branch 'develop' into feature/issue-1751-service-methods
syclik Nov 24, 2016
5c49027
Merge branch 'develop' into feature/issue-1751-service-methods
syclik Dec 9, 2016
a2de420
Merge branch 'develop' into feature/issue-1751-service-methods
syclik Dec 9, 2016
8f3718a
Updating doc
syclik Dec 14, 2016
4ad038f
Adding more doc for optimize and advi
syclik Dec 14, 2016
f15d78f
Fixing doc
syclik Dec 14, 2016
0327d32
Removing Interrupt as a template argument
syclik Dec 14, 2016
1319011
Merge branch 'develop' into feature/issue-1751-service-methods
syclik Dec 27, 2016
1102cd2
Removed unused parts of stan::callbacks::writer
syclik Dec 28, 2016
8bc4520
Removing no operation functionality to base class
syclik Dec 28, 2016
c536c68
Renaming chained_writer to tee_writer
syclik Dec 28, 2016
fa75ca1
Adding virtual destructor
syclik Dec 28, 2016
0f9ce3e
Updating doc for writer and stream_writer
syclik Dec 28, 2016
cf6218d
Making doxygen doc more consistent
syclik Dec 28, 2016
800856e
Fixing doc and implementation of var_context
syclik Dec 28, 2016
2ac6f69
Fixing lots of stuff
syclik Dec 29, 2016
f05f8a6
Updating new tests
syclik Dec 29, 2016
2281219
Adding doc
syclik Dec 29, 2016
e63e674
More fixes
syclik Dec 29, 2016
354bd0f
Fixing test
syclik Dec 29, 2016
af7092b
cpplint
syclik Dec 29, 2016
5fd895f
Updating doc and spacing
syclik Dec 30, 2016
fe43b92
Replacing most uses of .str("")
syclik Dec 30, 2016
5f87f9d
updating doc
syclik Dec 30, 2016
23a9458
Updating spacing
syclik Dec 30, 2016
2a3c0aa
Updating spacing
syclik Dec 30, 2016
ffa5aac
cpplint
syclik Dec 30, 2016
48eefc6
Addressing last review comments
Jan 3, 2017
54833b6
Using Eigen::Map
syclik Jan 9, 2017
c5e43b0
Updating experimental message
syclik Jan 9, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -18,13 +18,14 @@ matrix:
fast_finish: true

env:
- TESTFOLDER=src/test/unit/interface_callbacks
- TESTFOLDER=src/test/unit/callbacks
- TESTFOLDER=src/test/unit/io
- TESTFOLDER=src/test/unit/lang
- TESTFOLDER=src/test/unit/mcmc
- TESTFOLDER=src/test/unit/model
- TESTFOLDER=src/test/unit/optimization
- TESTFOLDER=src/test/unit/services
- TESTFOLDER=src/test/unit/variational
- TESTFOLDER=src/test/unit/version_test.cpp

script: ./runTests.py -j2 $TESTFOLDER
35 changes: 28 additions & 7 deletions make/tests
Expand Up @@ -164,6 +164,7 @@ src/test/unit/lang/stanc_helper_test.cpp: change-file-permissions
src/test/performance/logistic_test.cpp: src/test/test-models/performance/logistic.hpp
src/test/unit/lang/generator_test.cpp: src/test/test-models/good/lang/test_lp.hpp
src/test/unit/lang/parser_generator_test.cpp: $(patsubst %.stan,%.hpp,$(shell find src/test/test-models/good/parser-generator -type f -name '*.stan'))
src/test/unit/io/random_var_context_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/lang/reject/reject_func_call_generated_quantities_test.cpp: src/test/test-models/good/lang/reject_func_call_generated_quantities.hpp
src/test/unit/lang/reject/reject_func_call_model_test.cpp: src/test/test-models/good/lang/reject_func_call_model.hpp
src/test/unit/lang/reject/reject_func_call_transformed_data_test.cpp: src/test/test-models/good/lang/reject_func_call_transformed_data.hpp
Expand Down Expand Up @@ -193,13 +194,33 @@ src/test/unit/optimization/bfgs_minimizer_test.cpp: src/test/test-models/good/op
src/test/unit/optimization/bfgs_test.cpp: src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/optimization/bfgs_update_test.cpp: src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/optimization/lbfgs_update_test.cpp: src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/init/command_init_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/services/io/write_iteration_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/services/mcmc/sample_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/services/mcmc/warmup_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/services/optimize/do_bfgs_optimize_test.cpp: src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/generate_transitions_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/services/sample/mcmc_writer_test.cpp: src/test/test-models/good/io_example.hpp
src/test/unit/old_services/init/command_init_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/old_services/io/write_iteration_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/old_services/mcmc/sample_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/old_services/mcmc/warmup_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/old_services/optimize/do_bfgs_optimize_test.cpp: src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/diagnose/diagnose_test.cpp : src/test/test-models/good/services/test_lp.hpp
src/test/unit/services/optimize/bfgs_test.cpp \
src/test/unit/services/optimize/lbfgs_test.cpp \
src/test/unit/services/optimize/newton_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/experimental/advi/fullrank_test.cpp src/test/unit/services/experimental/advi/meanfield_test.cpp : src/test/test-models/good/services/test_lp.hpp
src/test/unit/services/sample/hmc_nuts_dense_e_adapt_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_nuts_dense_e_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_nuts_diag_e_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_nuts_diag_e_adapt_e_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_nuts_unit_e_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_nuts_unit_e_adapt_e_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_static_dense_e_adapt_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_static_dense_e_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_static_diag_e_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_static_diag_e_adapt_e_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_static_unit_e_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_static_unit_e_adapt_e_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/util/generate_transitions_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/services/util/initialize_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/services/util/run_adaptive_sampler_test.cpp src/test/unit/services/util/run_sampler_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/services/util/mcmc_writer.hpp : src/test/test-models/good/services/test_lp.hpp
src/test/unit/old_services/sample/mcmc_writer_test.cpp: src/test/test-models/good/io_example.hpp
src/test/unit/variational/advi_univar_no_constraint_test.cpp: src/test/test-models/good/variational/univariate_no_constraint.hpp
src/test/unit/variational/advi_univar_with_constraint_test.cpp: src/test/test-models/good/variational/univariate_with_constraint.hpp
src/test/unit/variational/advi_multivar_no_constraint_test.cpp: src/test/test-models/good/variational/multivariate_no_constraint.hpp
Expand Down
33 changes: 33 additions & 0 deletions src/stan/callbacks/interrupt.hpp
@@ -0,0 +1,33 @@
#ifndef STAN_CALLBACKS_INTERRUPT_HPP
#define STAN_CALLBACKS_INTERRUPT_HPP

namespace stan {
namespace callbacks {

/**
* <code>interrupt</code> is a base class defining the interface
* for Stan interrupt callbacks.
*
* The interrupt is called from within Stan algorithms to allow
* for the interfaces to handle interrupt signals (ctrl-c).
*/
class interrupt {
public:
/**
* Callback function.
*
* This function is called by the algorithms allowing the interfaces
* to break when necessary.
*/
virtual void operator()() {
}

/**
* Virtual destructor.
*/
virtual ~interrupt() {}
};

}
}
#endif
104 changes: 104 additions & 0 deletions src/stan/callbacks/stream_writer.hpp
@@ -0,0 +1,104 @@
#ifndef STAN_CALLBACKS_STREAM_WRITER_HPP
#define STAN_CALLBACKS_STREAM_WRITER_HPP

#include <stan/callbacks/writer.hpp>
#include <ostream>
#include <vector>
#include <string>

namespace stan {
namespace callbacks {

/**
* <code>stream_writer</code> is an implementation
* of <code>writer</code> that writes to a stream.
*/
class stream_writer : public writer {
public:
/**
* Constructs a stream writer with an output stream
* and an optional prefix for comments.
*
* @param[in, out] output stream to write
* @param[in] comment_prefix string to stream before
* each comment line. Default is "".
*/
stream_writer(std::ostream& output,
const std::string& comment_prefix = ""):
output_(output), comment_prefix_(comment_prefix) {}

/**
* Writes a set of names on a single line in csv format followed
* by a newline.
*
* Note: the names are not escaped.
*
* @param[in] names Names in a std::vector
*/
void operator()(const std::vector<std::string>& names) {
if (names.empty()) return;

std::vector<std::string>::const_iterator last = names.end();
--last;

for (std::vector<std::string>::const_iterator it = names.begin();
it != last; ++it)
output_ << *it << ",";
output_ << names.back() << std::endl;
}

/**
* Writes a set of values in csv format followed by a newline.
*
* Note: the precision of the output is determined by the settings
* of the stream on construction.
*
* @param[in] state Values in a std::vector
*/
void operator()(const std::vector<double>& state) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is 100% code dup with previous---I would ratha single templated impl called twice

if (state.empty()) return;

std::vector<double>::const_iterator last = state.end();
--last;

for (std::vector<double>::const_iterator it = state.begin();
it != last; ++it)
output_ << *it << ",";
output_ << state.back() << std::endl;
}

/**
* Writes the comment_prefix to the stream followed by a newline.
*/
void operator()() {
output_ << comment_prefix_ << std::endl;
}

/**
* Writes the comment_prefix then the message followed by a newline.
*
* @param[in] message A string
*/
void operator()(const std::string& message) {
output_ << comment_prefix_ << message << std::endl;
}

/**
* Virtual destructor
*/
virtual ~stream_writer() {}

private:
/**
* Output stream
*/
std::ostream& output_;
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space between declarations

* Comment prefix to use when printing comments: strings and blank lines
*/
std::string comment_prefix_;
};

}
}
#endif
67 changes: 67 additions & 0 deletions src/stan/callbacks/tee_writer.hpp
@@ -0,0 +1,67 @@
#ifndef STAN_CALLBACKS_TEE_WRITER_HPP
#define STAN_CALLBACKS_TEE_WRITER_HPP

#include <stan/callbacks/writer.hpp>
#include <ostream>
#include <vector>
#include <string>

namespace stan {
namespace callbacks {

/**
* <code>tee_writer</code> is an implementation that writes to
* two writers.
*
* For any call to this writer, it will tee the call to both writers
* provided in the constructor.
*/
class tee_writer : public writer {
public:
/**
* Constructor accepting two writers.
*
* @param[in, out] writer1 first writer
* @param[in, out] writer2 second writer
*/
tee_writer(writer& writer1,
writer& writer2)
: writer1_(writer1), writer2_(writer2) {
}

void operator()(const std::vector<std::string>& names) {
writer1_(names);
writer2_(names);
}

void operator()(const std::vector<double>& state) {
writer1_(state);
writer2_(state);
}

void operator()() {
writer1_();
writer2_();
}

void operator()(const std::string& message) {
writer1_(message);
writer2_(message);
}

virtual ~tee_writer() {}

private:
/**
* The first writer
*/
writer& writer1_;
/**
* The second writer
*/
writer& writer2_;
};

}
}
#endif
56 changes: 56 additions & 0 deletions src/stan/callbacks/writer.hpp
@@ -0,0 +1,56 @@
#ifndef STAN_CALLBACKS_WRITER_HPP
#define STAN_CALLBACKS_WRITER_HPP

#include <boost/lexical_cast.hpp>
#include <string>
#include <vector>

namespace stan {
namespace callbacks {

/**
* <code>writer</code> is a base class defining the interface
* for Stan writer callbacks. The base class can be used as a
* no-op implementation.
*/
class writer {
public:
/**
* Writes a set of names.
*
* @param[in] names Names in a std::vector
*/
virtual void operator()(const std::vector<std::string>& names) {
}

/**
* Writes a set of values.
*
* @param[in] state Values in a std::vector
*/
virtual void operator()(const std::vector<double>& state) {
}

/**
* Writes blank input.
*/
virtual void operator()() {
}

/**
* Writes a string.
*
* @param[in] message A string
*/
virtual void operator()(const std::string& message) {
}

/**
* Virtual destructor.
*/
virtual ~writer() {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move dtor up before other methods

};

}
}
#endif
18 changes: 0 additions & 18 deletions src/stan/interface_callbacks/interrupt/base_interrupt.hpp

This file was deleted.

20 changes: 0 additions & 20 deletions src/stan/interface_callbacks/interrupt/noop.hpp

This file was deleted.