C++
Interface
The C++ interface is located in the
file. To use the solver your code must include this file. The solver consists of a single function 1
<pogs>/src/pogs.h
, with signature1
Pogs
1 2 | template <typename T, typename M> void Pogs(PogsData<T, M> *pogs_data); |
The type
represents the data type (either 1
T
or 1
float
), and 1
double
is the matrix type (currently 1
M
and 1
float*
are supported, but further types will be added for sparse matrices). 1
double*
is a struct with fields1
PogsData
Inputs
correspond to the functions \( f \) and \( g \) in the objective. The dimension of1
std::vector<FunctionObj<T> > f, g
must be \( m \) and the dimension of1
f
must be \( n \). See section below for an explanation of the1
g
struct.1
FunctionObj<T>
corresponds to the data matrix \( A \). If \( A \) is a dense matrix, then1
const M A
is a pointer to a row major matrix of dimension \( m n \).1
M A
are the dimensions of \( y \), resp. \( x \).1
size_t m, n
Outputs
point to where the primal optimal variables \( x^\star_\text{pogs} \) and \( y^\star_\text{pogs} \) should be saved. The memory must be pre-allocated and have dimension \( m \) (resp. \( n \)). If either1
T *x, *y
or1
x=NULL
, then the respective variable will be discarded upon exit. Note, \( y^\star_\text{pogs} = A x^\star_\text{pogs} \) is only satisfied to a given tolerance (see Usage).1
y=NULL
points to where the dual optimal variable \( \lambda^\star_\text{pogs} \) should be stored. The memory must be pre-allocated and have dimension \( m \). If1
T *l
, then the dual variable will be discarded upon exit.1
l=NULL
is the primal optimum \( p^\star_\text{pogs} = f(y^\star_\text{pogs}) + g(x^\star_\text{pogs}) \). Note, since \( y^\star_\text{pogs} = A x^\star_\text{pogs} \) is only satisfied to a specified tolerance,1
T optval
may be a slightly lower than \( p^\star \) (the actual optimum).1
optval
Parameters (for a detailed description see Usage and ADMM)
is the penalty term.1
T rho
are the absolute and relative stopping tolerances.1
T rel_tol, abs_tol
is the maximum number of iterations before the solver terminates.1
unsigned int max_iter
determines whether the solver should display progress information.1
bool quiet
determines whether \( \rho \) should be chosen adaptively.1
bool adaptive_rho
Factors (allocate space for these variables to use factorization caching – see Usage)
used for factorization caching. Allocate space using1
M factors
and free space using1
AllocDenseFactors
.1
FreeDenseFactors
FunctionObj
The
struct is a parameterization of the generic function
\[
c \, h(a \, x - b) + d \, x + e \, x ^ 2,
\]1
FunctionObj
and is defined as
1 2 3 4 5 6 7 8 9 | template <typename T> struct FunctionObj { // Parameters Function h; T a, b, c, d, e; // Constructor with defaults FunctionObj(Function h) : h(h), a(1), b(0), c(1), d(0), e(0) { } }; |
where
is an enum, taking on the values1
Function
1 2 | kAbs, kExp, kHuber, kIdentity, kIndBox01, kIndEq0, kIndGe0, kIndLe0, kLogistic, kMaxNeg0, kMaxPos0, kNegEntr, kNegLog, kRecipr, kSquare, kZero. |
Definitions of both
and 1
FunctionObj
are located in 1
Function
.1
<pogs>/src/prox_lib.h
The
is necessary when specifying the objective terms \( f_i(y_i) \) and \( g_j(x_j) \). For example, to specify that \(g_j(x_j) = |x_j|\) for \(j = 1\ldots 4\) and \(g_5(x_5) = I(x_5 = 0)\), use the syntax1
FunctionObj
1 2 3 4 | pogs_data.g.reserve(5); for (unsigned int i = 0; i < 4; ++i) pogs_data.g.push_back(FunctionObj(kAbs)); pogs_data.g.push_back(FunctionObj(kIndGe0)); |
Linking to CPU implementation
Open Terminal and navigate to the directory
, then execute the command1
<pogs>/src
1 | make pogs.o |
This creates an object file
, to which your code must be linked. An example can be found in 1
pogs.o
. Look for the section marked 1
<pogs>/examples/cpp/Makefile
. When compiling your code it is important to also link to a BLAS library. On an Apple computer this can be done using the flag 1
#CPU
.1
-framework Accelerate
Linking to GPU implementation
Open terminal and navigate to the directory
, then execute the command1
<pogs>/src
1 | make pogs_cu_link.o |
This creates two object files –
and 1
pogs_cu.o
– to which your code must be linked. An example can be found in 1
pogs_cu_link.o
. Look for the section marked 1
<pogs>/examples/cpp/Makefile
. You will need to link the the CUDA runtime and CuBLAS libraries. To do so, use the 1
#GPU
flags.1
-lcudart -lcublas