@@ -1418,6 +1418,64 @@ class RandomEffectsContainerCpp {
14181418 int NumGroups () {
14191419 return rfx_container_->NumGroups ();
14201420 }
1421+ py::array_t <double > GetBeta () {
1422+ int num_samples = rfx_container_->NumSamples ();
1423+ int num_components = rfx_container_->NumComponents ();
1424+ int num_groups = rfx_container_->NumGroups ();
1425+ std::vector<double > beta_raw = rfx_container_->GetBeta ();
1426+ auto result = py::array_t <double >(py::detail::any_container<py::ssize_t >({num_components, num_groups, num_samples}));
1427+ auto accessor = result.mutable_unchecked <3 >();
1428+ for (int i = 0 ; i < num_components; i++) {
1429+ for (int j = 0 ; j < num_groups; j++) {
1430+ for (int k = 0 ; k < num_samples; k++) {
1431+ accessor (i,j,k) = beta_raw[k*num_groups*num_components + j*num_components + i];
1432+ }
1433+ }
1434+ }
1435+ return result;
1436+ }
1437+ py::array_t <double > GetXi () {
1438+ int num_samples = rfx_container_->NumSamples ();
1439+ int num_components = rfx_container_->NumComponents ();
1440+ int num_groups = rfx_container_->NumGroups ();
1441+ std::vector<double > xi_raw = rfx_container_->GetXi ();
1442+ auto result = py::array_t <double >(py::detail::any_container<py::ssize_t >({num_components, num_groups, num_samples}));
1443+ auto accessor = result.mutable_unchecked <3 >();
1444+ for (int i = 0 ; i < num_components; i++) {
1445+ for (int j = 0 ; j < num_groups; j++) {
1446+ for (int k = 0 ; k < num_samples; k++) {
1447+ accessor (i,j,k) = xi_raw[k*num_groups*num_components + j*num_components + i];
1448+ }
1449+ }
1450+ }
1451+ return result;
1452+ }
1453+ py::array_t <double > GetAlpha () {
1454+ int num_samples = rfx_container_->NumSamples ();
1455+ int num_components = rfx_container_->NumComponents ();
1456+ std::vector<double > alpha_raw = rfx_container_->GetAlpha ();
1457+ auto result = py::array_t <double >(py::detail::any_container<py::ssize_t >({num_components, num_samples}));
1458+ auto accessor = result.mutable_unchecked <2 >();
1459+ for (int i = 0 ; i < num_components; i++) {
1460+ for (int j = 0 ; j < num_samples; j++) {
1461+ accessor (i,j) = alpha_raw[j*num_components + i];
1462+ }
1463+ }
1464+ return result;
1465+ }
1466+ py::array_t <double > GetSigma () {
1467+ int num_samples = rfx_container_->NumSamples ();
1468+ int num_components = rfx_container_->NumComponents ();
1469+ std::vector<double > sigma_raw = rfx_container_->GetSigma ();
1470+ auto result = py::array_t <double >(py::detail::any_container<py::ssize_t >({num_components, num_samples}));
1471+ auto accessor = result.mutable_unchecked <2 >();
1472+ for (int i = 0 ; i < num_components; i++) {
1473+ for (int j = 0 ; j < num_samples; j++) {
1474+ accessor (i,j) = sigma_raw[j*num_components + i];
1475+ }
1476+ }
1477+ return result;
1478+ }
14211479 void DeleteSample (int sample_num) {
14221480 rfx_container_->DeleteSample (sample_num);
14231481 }
@@ -2294,6 +2352,10 @@ PYBIND11_MODULE(stochtree_cpp, m) {
22942352 .def (" NumSamples" , &RandomEffectsContainerCpp::NumSamples)
22952353 .def (" NumComponents" , &RandomEffectsContainerCpp::NumComponents)
22962354 .def (" NumGroups" , &RandomEffectsContainerCpp::NumGroups)
2355+ .def (" GetBeta" , &RandomEffectsContainerCpp::GetBeta)
2356+ .def (" GetXi" , &RandomEffectsContainerCpp::GetXi)
2357+ .def (" GetAlpha" , &RandomEffectsContainerCpp::GetAlpha)
2358+ .def (" GetSigma" , &RandomEffectsContainerCpp::GetSigma)
22972359 .def (" DeleteSample" , &RandomEffectsContainerCpp::DeleteSample)
22982360 .def (" Predict" , &RandomEffectsContainerCpp::Predict)
22992361 .def (" SaveToJsonFile" , &RandomEffectsContainerCpp::SaveToJsonFile)
0 commit comments