abcpp 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- abcpp-1.0.0/CMakeLists.txt +33 -0
- abcpp-1.0.0/Cpp/include/abcpp/abc.hpp +71 -0
- abcpp-1.0.0/Cpp/include/abcpp/abcpp.hpp +11 -0
- abcpp-1.0.0/Cpp/include/abcpp/linear_algebra.hpp +36 -0
- abcpp-1.0.0/Cpp/include/abcpp/matrix.hpp +56 -0
- abcpp-1.0.0/Cpp/include/abcpp/options.hpp +98 -0
- abcpp-1.0.0/Cpp/include/abcpp/reduction.hpp +24 -0
- abcpp-1.0.0/Cpp/include/abcpp/result.hpp +72 -0
- abcpp-1.0.0/Cpp/include/abcpp/statistics.hpp +44 -0
- abcpp-1.0.0/Cpp/include/abcpp/summary.hpp +19 -0
- abcpp-1.0.0/Cpp/src/abc.cpp +1798 -0
- abcpp-1.0.0/Cpp/src/linear_algebra.cpp +194 -0
- abcpp-1.0.0/Cpp/src/matrix.cpp +118 -0
- abcpp-1.0.0/Cpp/src/options.cpp +149 -0
- abcpp-1.0.0/Cpp/src/reduction.cpp +392 -0
- abcpp-1.0.0/Cpp/src/result.cpp +5 -0
- abcpp-1.0.0/Cpp/src/statistics.cpp +238 -0
- abcpp-1.0.0/Cpp/src/summary.cpp +58 -0
- abcpp-1.0.0/LICENSE +674 -0
- abcpp-1.0.0/PKG-INFO +800 -0
- abcpp-1.0.0/README.md +101 -0
- abcpp-1.0.0/abcpp/__init__.py +4 -0
- abcpp-1.0.0/abcpp/abc.py +120 -0
- abcpp-1.0.0/abcpp/summary.py +6 -0
- abcpp-1.0.0/pyproject.toml +47 -0
- abcpp-1.0.0/src/py_abcpp.cpp +328 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.15...3.27)
|
|
2
|
+
project(abcpp_python CXX)
|
|
3
|
+
|
|
4
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
5
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
6
|
+
|
|
7
|
+
if(MSVC)
|
|
8
|
+
add_compile_options(/utf-8 /W3 /wd4267)
|
|
9
|
+
endif()
|
|
10
|
+
|
|
11
|
+
find_package(pybind11 CONFIG REQUIRED)
|
|
12
|
+
|
|
13
|
+
if(NOT TARGET abcpp)
|
|
14
|
+
add_library(abcpp STATIC
|
|
15
|
+
${CMAKE_CURRENT_LIST_DIR}/Cpp/src/abc.cpp
|
|
16
|
+
${CMAKE_CURRENT_LIST_DIR}/Cpp/src/linear_algebra.cpp
|
|
17
|
+
${CMAKE_CURRENT_LIST_DIR}/Cpp/src/matrix.cpp
|
|
18
|
+
${CMAKE_CURRENT_LIST_DIR}/Cpp/src/options.cpp
|
|
19
|
+
${CMAKE_CURRENT_LIST_DIR}/Cpp/src/reduction.cpp
|
|
20
|
+
${CMAKE_CURRENT_LIST_DIR}/Cpp/src/result.cpp
|
|
21
|
+
${CMAKE_CURRENT_LIST_DIR}/Cpp/src/statistics.cpp
|
|
22
|
+
${CMAKE_CURRENT_LIST_DIR}/Cpp/src/summary.cpp
|
|
23
|
+
)
|
|
24
|
+
set_property(TARGET abcpp PROPERTY POSITION_INDEPENDENT_CODE ON)
|
|
25
|
+
target_include_directories(abcpp PUBLIC
|
|
26
|
+
${CMAKE_CURRENT_LIST_DIR}/Cpp/include
|
|
27
|
+
)
|
|
28
|
+
endif()
|
|
29
|
+
|
|
30
|
+
pybind11_add_module(_core MODULE src/py_abcpp.cpp)
|
|
31
|
+
target_link_libraries(_core PRIVATE abcpp)
|
|
32
|
+
|
|
33
|
+
install(TARGETS _core DESTINATION abcpp)
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "abcpp/matrix.hpp"
|
|
4
|
+
#include "abcpp/options.hpp"
|
|
5
|
+
#include "abcpp/result.hpp"
|
|
6
|
+
|
|
7
|
+
#include <string>
|
|
8
|
+
#include <vector>
|
|
9
|
+
|
|
10
|
+
namespace abcpp {
|
|
11
|
+
|
|
12
|
+
class opt {
|
|
13
|
+
public:
|
|
14
|
+
opt() = default;
|
|
15
|
+
|
|
16
|
+
opt& set_target(const Matrix& target);
|
|
17
|
+
opt& set_params(const Matrix& params);
|
|
18
|
+
opt& set_sumstats(const Matrix& sumstats);
|
|
19
|
+
|
|
20
|
+
opt& set_method(method value);
|
|
21
|
+
opt& set_tol(double value);
|
|
22
|
+
opt& set_kernel(kernel value);
|
|
23
|
+
opt& set_hcorr(bool value);
|
|
24
|
+
opt& set_transform(transform value);
|
|
25
|
+
opt& set_prior_weights(const std::vector<double>& value);
|
|
26
|
+
opt& set_seed(unsigned int value);
|
|
27
|
+
|
|
28
|
+
opt& set_nnet_numnet(int value);
|
|
29
|
+
opt& set_nnet_sizenet(int value);
|
|
30
|
+
opt& set_nnet_lambda(const std::vector<double>& value);
|
|
31
|
+
opt& set_nnet_maxit(int value);
|
|
32
|
+
opt& set_nnet_rang(double value);
|
|
33
|
+
opt& set_nnet_abstol(double value);
|
|
34
|
+
opt& set_nnet_reltol(double value);
|
|
35
|
+
opt& set_nnet_verbose(bool value);
|
|
36
|
+
opt& set_nnet_skip(bool value);
|
|
37
|
+
|
|
38
|
+
result run() const;
|
|
39
|
+
|
|
40
|
+
private:
|
|
41
|
+
Matrix target_;
|
|
42
|
+
Matrix params_;
|
|
43
|
+
Matrix sumstats_;
|
|
44
|
+
bool has_target_ = false;
|
|
45
|
+
bool has_params_ = false;
|
|
46
|
+
bool has_sumstats_ = false;
|
|
47
|
+
options options_;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
result fit(
|
|
51
|
+
const std::vector<double>& target,
|
|
52
|
+
const Matrix& param,
|
|
53
|
+
const Matrix& sumstat,
|
|
54
|
+
const options& options
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
result fit(
|
|
58
|
+
const Matrix& target,
|
|
59
|
+
const Matrix& param,
|
|
60
|
+
const Matrix& sumstat,
|
|
61
|
+
const options& options
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
result fit(
|
|
65
|
+
const Matrix& target,
|
|
66
|
+
const Matrix& param,
|
|
67
|
+
const std::vector<Matrix>& sumstats,
|
|
68
|
+
const options& options
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
} // namespace abcpp
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "abcpp/matrix.hpp"
|
|
4
|
+
|
|
5
|
+
#include <vector>
|
|
6
|
+
|
|
7
|
+
namespace abcpp {
|
|
8
|
+
|
|
9
|
+
Matrix transpose(const Matrix& matrix);
|
|
10
|
+
|
|
11
|
+
Matrix multiply(const Matrix& left, const Matrix& right);
|
|
12
|
+
|
|
13
|
+
std::vector<double> multiply(
|
|
14
|
+
const Matrix& matrix,
|
|
15
|
+
const std::vector<double>& vector
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
Matrix add_intercept(const Matrix& x);
|
|
19
|
+
|
|
20
|
+
std::vector<double> solve_linear_system(
|
|
21
|
+
Matrix a,
|
|
22
|
+
std::vector<double> b
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
Matrix inverse(Matrix matrix);
|
|
26
|
+
|
|
27
|
+
Matrix weighted_least_squares(
|
|
28
|
+
const Matrix& design,
|
|
29
|
+
const Matrix& response,
|
|
30
|
+
const std::vector<double>& weights,
|
|
31
|
+
double ridge_lambda
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
Matrix predict(const Matrix& design, const Matrix& coefficients);
|
|
35
|
+
|
|
36
|
+
} // namespace abcpp
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <cstddef>
|
|
4
|
+
#include <stdexcept>
|
|
5
|
+
#include <vector>
|
|
6
|
+
|
|
7
|
+
namespace abcpp {
|
|
8
|
+
|
|
9
|
+
class Matrix {
|
|
10
|
+
public:
|
|
11
|
+
Matrix();
|
|
12
|
+
|
|
13
|
+
Matrix(
|
|
14
|
+
std::size_t rows,
|
|
15
|
+
std::size_t cols,
|
|
16
|
+
double value = 0.0
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
std::size_t rows() const;
|
|
20
|
+
|
|
21
|
+
std::size_t cols() const;
|
|
22
|
+
|
|
23
|
+
bool empty() const;
|
|
24
|
+
|
|
25
|
+
double& operator()(std::size_t row, std::size_t col);
|
|
26
|
+
|
|
27
|
+
double operator()(std::size_t row, std::size_t col) const;
|
|
28
|
+
|
|
29
|
+
std::vector<double>& data();
|
|
30
|
+
|
|
31
|
+
const std::vector<double>& data() const;
|
|
32
|
+
|
|
33
|
+
std::vector<double> row(std::size_t index) const;
|
|
34
|
+
|
|
35
|
+
std::vector<double> col(std::size_t index) const;
|
|
36
|
+
|
|
37
|
+
void set_row(std::size_t index, const std::vector<double>& values);
|
|
38
|
+
|
|
39
|
+
private:
|
|
40
|
+
std::size_t rows_ = 0;
|
|
41
|
+
std::size_t cols_ = 0;
|
|
42
|
+
std::vector<double> data_;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
Matrix from_row_major(
|
|
46
|
+
const std::vector<double>& values,
|
|
47
|
+
std::size_t rows,
|
|
48
|
+
std::size_t cols
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
Matrix subset_rows(
|
|
52
|
+
const Matrix& matrix,
|
|
53
|
+
const std::vector<std::size_t>& rows
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
} // namespace abcpp
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "abcpp/matrix.hpp"
|
|
4
|
+
|
|
5
|
+
#include <cstddef>
|
|
6
|
+
#include <string>
|
|
7
|
+
#include <vector>
|
|
8
|
+
|
|
9
|
+
namespace abcpp {
|
|
10
|
+
|
|
11
|
+
enum class method {
|
|
12
|
+
rejection,
|
|
13
|
+
loclinear,
|
|
14
|
+
ridge,
|
|
15
|
+
neuralnet
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
using Method = method;
|
|
19
|
+
using AbcMethod = method;
|
|
20
|
+
|
|
21
|
+
enum class kernel {
|
|
22
|
+
gaussian,
|
|
23
|
+
epanechnikov,
|
|
24
|
+
rectangular,
|
|
25
|
+
triangular,
|
|
26
|
+
biweight,
|
|
27
|
+
cosine
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
using Kernel = kernel;
|
|
31
|
+
|
|
32
|
+
enum class transform {
|
|
33
|
+
none,
|
|
34
|
+
log,
|
|
35
|
+
logit
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
using Transform = transform;
|
|
39
|
+
|
|
40
|
+
enum class reduction_method {
|
|
41
|
+
none,
|
|
42
|
+
pca,
|
|
43
|
+
pls
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
using ReductionMethod = reduction_method;
|
|
47
|
+
|
|
48
|
+
struct ReductionOptions {
|
|
49
|
+
reduction_method method = reduction_method::none;
|
|
50
|
+
std::size_t n_comp = 0;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
struct nnet_options {
|
|
54
|
+
int numnet = 10;
|
|
55
|
+
int sizenet = 5;
|
|
56
|
+
std::vector<double> lambda = {0.0001, 0.001, 0.01};
|
|
57
|
+
int maxit = 500;
|
|
58
|
+
double rang = 0.7;
|
|
59
|
+
double abstol = 1e-4;
|
|
60
|
+
double reltol = 1e-8;
|
|
61
|
+
bool verbose = false;
|
|
62
|
+
bool skip = false;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
struct options {
|
|
66
|
+
abcpp::method method = abcpp::method::rejection;
|
|
67
|
+
double tol = 0.01;
|
|
68
|
+
abcpp::kernel kernel = abcpp::kernel::epanechnikov;
|
|
69
|
+
bool hcorr = true;
|
|
70
|
+
abcpp::transform transf = abcpp::transform::none;
|
|
71
|
+
std::vector<abcpp::transform> transformations;
|
|
72
|
+
Matrix logit_bounds;
|
|
73
|
+
std::vector<bool> subset;
|
|
74
|
+
std::vector<double> prior_weights;
|
|
75
|
+
unsigned int seed = 1004;
|
|
76
|
+
nnet_options nnet;
|
|
77
|
+
ReductionOptions reduction;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
using AbcOptions = options;
|
|
81
|
+
|
|
82
|
+
method parse_method(const std::string& value);
|
|
83
|
+
|
|
84
|
+
kernel parse_kernel(const std::string& value);
|
|
85
|
+
|
|
86
|
+
transform parse_transform(const std::string& value);
|
|
87
|
+
|
|
88
|
+
reduction_method parse_reduction(const std::string& value);
|
|
89
|
+
|
|
90
|
+
std::string method_name(abcpp::method method);
|
|
91
|
+
|
|
92
|
+
std::string kernel_name(abcpp::kernel kernel);
|
|
93
|
+
|
|
94
|
+
std::string transform_name(abcpp::transform transform);
|
|
95
|
+
|
|
96
|
+
std::string reduction_name(reduction_method reduction);
|
|
97
|
+
|
|
98
|
+
} // namespace abcpp
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "abcpp/matrix.hpp"
|
|
4
|
+
#include "abcpp/options.hpp"
|
|
5
|
+
#include "abcpp/result.hpp"
|
|
6
|
+
|
|
7
|
+
#include <vector>
|
|
8
|
+
|
|
9
|
+
namespace abcpp {
|
|
10
|
+
|
|
11
|
+
struct ReducedSummary {
|
|
12
|
+
Matrix sumstat;
|
|
13
|
+
std::vector<double> target;
|
|
14
|
+
ReductionInfo info;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
ReducedSummary reduce_summary_statistics(
|
|
18
|
+
const Matrix& param,
|
|
19
|
+
const Matrix& sumstat,
|
|
20
|
+
const std::vector<double>& target,
|
|
21
|
+
const ReductionOptions& options
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
} // namespace abcpp
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "abcpp/matrix.hpp"
|
|
4
|
+
#include "abcpp/options.hpp"
|
|
5
|
+
|
|
6
|
+
#include <string>
|
|
7
|
+
#include <vector>
|
|
8
|
+
|
|
9
|
+
namespace abcpp {
|
|
10
|
+
|
|
11
|
+
struct ReductionInfo {
|
|
12
|
+
reduction_method method = reduction_method::none;
|
|
13
|
+
std::size_t n_comp = 0;
|
|
14
|
+
Matrix rotation;
|
|
15
|
+
std::vector<double> center;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
struct AbcDiagnostics {
|
|
19
|
+
double aic = 0.0;
|
|
20
|
+
double bic = 0.0;
|
|
21
|
+
std::vector<double> lambda;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
struct AbcResult {
|
|
25
|
+
Matrix adj_values;
|
|
26
|
+
Matrix unadj_values;
|
|
27
|
+
Matrix accepted_sumstats;
|
|
28
|
+
Matrix weights;
|
|
29
|
+
Matrix residuals;
|
|
30
|
+
std::vector<double> distances;
|
|
31
|
+
std::vector<std::size_t> accepted_indices;
|
|
32
|
+
std::vector<bool> region;
|
|
33
|
+
std::vector<bool> na_action;
|
|
34
|
+
std::vector<transform> transformations;
|
|
35
|
+
Matrix logit_bounds;
|
|
36
|
+
abcpp::options options;
|
|
37
|
+
abcpp::method method = abcpp::method::rejection;
|
|
38
|
+
abcpp::kernel kernel = abcpp::kernel::epanechnikov;
|
|
39
|
+
bool hcorr = true;
|
|
40
|
+
std::vector<double> lambda;
|
|
41
|
+
int numparam = 0;
|
|
42
|
+
int numstat = 0;
|
|
43
|
+
double aic = 0.0;
|
|
44
|
+
double bic = 0.0;
|
|
45
|
+
ReductionInfo reduction;
|
|
46
|
+
std::string status = "ok";
|
|
47
|
+
std::string message;
|
|
48
|
+
AbcDiagnostics diagnostics;
|
|
49
|
+
std::vector<std::string> parameter_names;
|
|
50
|
+
std::vector<std::string> statistic_names;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
using result = AbcResult;
|
|
54
|
+
|
|
55
|
+
struct SummaryColumn {
|
|
56
|
+
double min = 0.0;
|
|
57
|
+
double q_lower = 0.0;
|
|
58
|
+
double median = 0.0;
|
|
59
|
+
double mean = 0.0;
|
|
60
|
+
double mode = 0.0;
|
|
61
|
+
double q_upper = 0.0;
|
|
62
|
+
double max = 0.0;
|
|
63
|
+
double sd = 0.0;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
struct SummaryResult {
|
|
67
|
+
std::vector<SummaryColumn> columns;
|
|
68
|
+
double interval = 0.95;
|
|
69
|
+
bool unadjusted = false;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
} // namespace abcpp
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "abcpp/matrix.hpp"
|
|
4
|
+
|
|
5
|
+
#include <cstddef>
|
|
6
|
+
#include <vector>
|
|
7
|
+
|
|
8
|
+
namespace abcpp {
|
|
9
|
+
|
|
10
|
+
bool is_finite(double value);
|
|
11
|
+
|
|
12
|
+
double median(std::vector<double> values);
|
|
13
|
+
|
|
14
|
+
double quantile_type7(std::vector<double> values, double probability);
|
|
15
|
+
|
|
16
|
+
double mad(const std::vector<double>& values);
|
|
17
|
+
|
|
18
|
+
double mean(const std::vector<double>& values);
|
|
19
|
+
|
|
20
|
+
double weighted_mean(
|
|
21
|
+
const std::vector<double>& values,
|
|
22
|
+
const std::vector<double>& weights
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
double sample_sd(const std::vector<double>& values);
|
|
26
|
+
|
|
27
|
+
std::vector<double> column_means(const Matrix& matrix);
|
|
28
|
+
|
|
29
|
+
std::vector<double> column_mads(
|
|
30
|
+
const Matrix& matrix,
|
|
31
|
+
const std::vector<bool>& keep_rows
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
std::vector<double> column_weighted_sse(
|
|
35
|
+
const Matrix& matrix,
|
|
36
|
+
const std::vector<double>& weights
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
double kernel_mode(
|
|
40
|
+
const std::vector<double>& values,
|
|
41
|
+
const std::vector<double>& weights
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
} // namespace abcpp
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "abcpp/result.hpp"
|
|
4
|
+
|
|
5
|
+
namespace abcpp {
|
|
6
|
+
|
|
7
|
+
SummaryResult summary(
|
|
8
|
+
const AbcResult& result,
|
|
9
|
+
bool unadjusted = false,
|
|
10
|
+
double interval = 0.95
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
SummaryResult summarize(
|
|
14
|
+
const AbcResult& result,
|
|
15
|
+
bool unadjusted = false,
|
|
16
|
+
double interval = 0.95
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
} // namespace abcpp
|