Skip to content

Commit

Permalink
v0.2.5 Minor refactor + fix OpenMP issue
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel-watson committed Jul 3, 2023
1 parent 5641d6e commit 5982cbc
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: glmmrOptim
Type: Package
Title: Approximate Optimal Experimental Designs Using Generalised Linear Mixed Models
Version: 0.2.5
Date: 2023-06-27
Date: 2023-07-03
Authors@R: c(person("Sam", "Watson", email = "[email protected]",
role = c("aut", "cre")),
person("Yi", "Pan", email = "[email protected]",
Expand Down
6 changes: 6 additions & 0 deletions R/R6designspace.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ DesignSpace <- R6::R6Class("DesignSpace",
#' are separate experimental conditions.
#' @return A `DesignSpace` object
#' @examples
#' \dontshow{
#' glmmrBase::setParallel(FALSE) # for the CRAN check
#' }
#' df <- nelder(~ ((int(2)*t(3)) > cl(3)) > ind(5))
#' df$int <- df$int - 1
#' des <- Model$new(covariance = list(formula = ~ (1|gr(cl)) + (1|gr(cl,t)),
Expand Down Expand Up @@ -214,6 +217,9 @@ DesignSpace <- R6::R6Class("DesignSpace",
#' the list contains the rows in the optimal design, the indexes of the experimental conditions in the optimal design,
#' the variance from this design, and the total number of function evaluations. Optionally the linked designs are also modified (see option `keep`).
#' @examples
#' \dontshow{
#' glmmrBase::setParallel(FALSE) # for the CRAN check
#' }
#' df <- nelder(~(cl(6)*t(5)) > ind(5))
#' df$int <- 0
#' df[df$t >= df$cl, 'int'] <- 1
Expand Down
2 changes: 2 additions & 0 deletions inst/include/glmmrOptim.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

#include <cmath>
#include <RcppEigen.h>
#include "optim/optimmaths.h"
#include "optim/matrixfield.h"
#include "optim/optimclass.h"
#include "optim/optimdata.h"
#include <glmmr/openmpheader.h>

#endif
2 changes: 2 additions & 0 deletions inst/include/optim/optimclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ using namespace Eigen;

namespace glmmr {

// I plan to refactor this class as it is too big!

class OptimDesign {
private:
glmmr::OptimData& data_;
Expand Down
1 change: 0 additions & 1 deletion inst/include/optim/optimlinalg.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <cmath>
#include <RcppEigen.h>
//#include <glmmr.h>
#include "optimmaths.h"

namespace glmmr {
Expand Down
31 changes: 16 additions & 15 deletions inst/include/optim/optimmaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,41 @@

#include <cmath>
#include <RcppEigen.h>
//#include <glmmr.h>

namespace glmmr {
namespace maths {

inline double obj_fun(const Eigen::MatrixXd &A,
const Eigen::VectorXd &U2) {
using namespace Eigen;

inline double obj_fun(const MatrixXd &A,
const VectorXd &U2) {
return U2.transpose() * A * U2;
}

inline double c_obj_fun(const Eigen::MatrixXd &M,
const Eigen::VectorXd &C) {
inline double c_obj_fun(const MatrixXd &M,
const VectorXd &C) {
// this is the objective function c-optimal
Eigen::MatrixXd M_inv = M.inverse();
MatrixXd M_inv = M.inverse();
return C.transpose() * M_inv * C;
}

inline double c_d_deriv(const Eigen::MatrixXd &M1,
const Eigen::MatrixXd &M2,
const Eigen::VectorXd &C) {
inline double c_d_deriv(const MatrixXd &M1,
const MatrixXd &M2,
const VectorXd &C) {
// this is the directional derivative from M1 to M2 c-optimal
Eigen::MatrixXd M_inv = M1.inverse();
MatrixXd M_inv = M1.inverse();
return C.transpose() * M_inv * (M1 - M2) * M_inv * C;
}

inline double c_deriv(const Eigen::MatrixXd &M,
const Eigen::VectorXd &C) {
inline double c_deriv(const MatrixXd &M,
const VectorXd &C) {
// this is the directional derivative from M1 to M2 c-optimal
Eigen::MatrixXd M_inv = M.inverse();
MatrixXd M_inv = M.inverse();
return (-1 * M_inv * C * C.transpose() * M_inv).norm();
}

inline Eigen::MatrixXd gen_m(const Eigen::MatrixXd &X,
const Eigen::MatrixXd &A) {
inline MatrixXd gen_m(const MatrixXd &X,
const MatrixXd &A) {
//generate information matrix
return X.transpose() * A * X;
}
Expand Down

0 comments on commit 5982cbc

Please sign in to comment.