Skip to content

Commit

Permalink
Merge d8c8325 into 8bb020d
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesYang007 committed Apr 22, 2020
2 parents 8bb020d + d8c8325 commit 05dd622
Show file tree
Hide file tree
Showing 40 changed files with 2,608 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
coveralls
--root ../../
--build-root ./
--include autoppl/include
--include include
--exclude lib
--gcov 'gcov-7'
--gcov-options '\-lp'
Expand Down
18 changes: 16 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ option(AUTOPPL_ENABLE_BENCHMARK "Enable benchmarks to be built." OFF)
option(AUTOPPL_ENABLE_TEST_COVERAGE "Build with test coverage (AUTOPPL_ENABLE_TEST must be ON)" OFF)

# Automate the choosing of config
# if CMAKE_BUILD_TYPE not defined
if (NOT CMAKE_BUILD_TYPE)
# if binary directory ends with "release", use release mode
if (${PROJECT_BINARY_DIR} MATCHES "release$")
Expand All @@ -22,6 +21,16 @@ if (NOT CMAKE_BUILD_TYPE)
endif()
message(STATUS "Compiling in ${CMAKE_BUILD_TYPE} mode")

# Add this library as interface (header-only)
add_library(${PROJECT_NAME} INTERFACE)

target_include_directories(${PROJECT_NAME}
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

# Set C++17 standard for project target
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)

# Configure tests
if (AUTOPPL_ENABLE_TEST)
include(CTest) # enable memcheck
Expand All @@ -35,6 +44,11 @@ if (AUTOPPL_ENABLE_TEST)
add_subdirectory(${PROJECT_SOURCE_DIR}/test ${PROJECT_BINARY_DIR}/test)
endif()

# TODO: add src dir if needed
#set(AUTOPPL_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/src)
#file(GLOB_RECURSE AUTOPPL_SOURCE_FILES RELATIVE src LIST_DIRECTORIES false *.cpp)
#set(AUTOPPL_SOURCE_FILES ${AUTOPPL_SOURCE_DIR}/autoppl.cpp)
#set(AUTOPPL_HEADER_FILES ${AUTOPPL_INCLUDE_DIR}/autoppl.h)

# Add subdirectories
add_subdirectory(${PROJECT_SOURCE_DIR}/autoppl ${PROJECT_BINARY_DIR}/autoppl)
add_subdirectory(${PROJECT_SOURCE_DIR}/lib ${PROJECT_BINARY_DIR}/lib)
15 changes: 0 additions & 15 deletions autoppl/CMakeLists.txt

This file was deleted.

11 changes: 0 additions & 11 deletions autoppl/include/autoppl.hpp

This file was deleted.

32 changes: 32 additions & 0 deletions doc/design/model_design2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Y ~ W.x + epsilon
Y ~ N(W.x, sigma^2)

Parameter<double> X {4.0}; // observed
Parameter<double> Y {5.0}; // observed
Parameter<double> W; // hidden
Model m1 = Model( // Model class defines a distribution over existing Parameters.
W |= Uniform(-10, 10), // linear regression
Y |= Normal(W * X, 3), // overload multiplication to build a graph from W * X
​);

Model m2 = Model(
W |= Normal(0, 1), // ridge regression instead
Y |= Normal(W * X, 3),
);
m1.sample(1000);

(3*x).pdf(10) => x.pdf(10 / 3)

X.observe(3); // observe more data

// P(Y, W | X) = P(Y | W, X) P(W | X) which is doable for multiple samples, just need to
// assert len(Y) == len(X) and then multiply out over all pairs of (X, Y) values.

// P(Y | X) => this is a fine distribution, but I can't talk about P(Y, X) or P(X | Y) until I put a prior on Y.
// I don't have a joint distribution yet.

// Some issues:
// how do we do (x ** 2).pdf(5)? This is pretty damn hard for non-bijective functions, need to integrate?
//
106 changes: 106 additions & 0 deletions doc/design/model_inttest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include "gtest/gtest.h"
#include <autoppl/expression/model.hpp>
#include <autoppl/expression/rv_tag.hpp>
#include <autoppl/expression/uniform.hpp>

namespace ppl {

template <class VectorType, class IndexType>
struct BracketNode
{
VectorType v;
IndexType i;
};

struct myvector
{

rv_tag<double> operator[](rv_tag)
{
return rv
}
std::vector<rv_tags> v; // 3 things
};

template <class MuType, class SigType>
auto normal(const MuType& mu, const SigType& sig)
{
Normal<MuType, SigType>(mu, sig);
}

TEST(dummy, dummy_test)
{
double x_data = 2.3; // 1-sample data

std::vector<double> sampled_theta_1(100);
std::vector<double> sampled_theta_2(100);

double* ptr;
rv_tag<double, ...> x;
rv_tag<double> theta_1(sampled_theta_1.data());
rv_tag<double> theta_2(sampled_theta_2.data());

std::vector<rv_tag<double>> v;
std::for_each(..., ... , [](){v[i].set_sample_storage(&mat.row(i));});

x.observe(x_data);

x_1.observe(...);
x_2.observe(...);

auto model = (
mu |= uniform(-10000, 10000),
y |= uniform({1,2,3}) //
x_1 |= normal(mu[y], 1),
x_2 |= normal(mu[y], 1),
);

x.observe(...);

rv_tag<double> var, mu, x;
auto normal_model = (
var |= normal(0,1),
mu |= normal(1,5),
x |= normal(mu, var)
);

std::vector<double> var_storage(1000);
std::vector<double> mu_storage(1000);

var.set_storage(var_storage.data());
mu.set_storage(mu_storage.data());

metropolis_hastings(model, 1000, 400);

auto gmm_model = (
mu |=
);

std::vector<rv_tag<double>> vec(model.param_num);
model.bind_storage(vec.begin(), vec.end(), ...);
model.pdf();

metropolis_hastings(model, 100);

std::vector<double> sampled_theta_1_again(1000);
std::vector<double> sampled_theta_2_again(1000);

theta_1.set_storage(sampled_theta_1_again.data());
theta_2.set_storage(sampled_theta_2_again.data());

metropolis_hastings(model, 1000);







auto model = (
w |= normal(0,1),
y |= normal(w*x, 1)
)
metropolis_hastings(modeli)
}

}
Loading

0 comments on commit 05dd622

Please sign in to comment.