ConicBundle
CMlowrankdd.hxx
Go to the documentation of this file.
1 
2 
3 #ifndef CONICBUNDLE_CMLOWRANKDD_HXX
4 #define CONICBUNDLE_CMLOWRANKDD_HXX
5 
13 #include "Coeffmat.hxx"
14 
15 namespace ConicBundle {
16 
20 
24  class CMlowrankdd: public Coeffmat
25  {
26  private:
29  public:
32  {A=Ain;B=Bin;CM_type=CM_lowrankdd;infop=cip;}
34  virtual ~CMlowrankdd(){}
35 
36 
38  virtual Coeffmat* clone() const
39  {return new CMlowrankdd(A,B,ConicBundle::clone(infop));}
40 
42  virtual CH_Matrix_Classes::Integer dim() const { return A.rowdim(); }
43 
46  {
47  return
50  }
51 
54  { CH_Matrix_Classes::rank2add(A,B,S,2.);}
55 
57  virtual CH_Matrix_Classes::Real norm(void) const
59  CH_Matrix_Classes::genmult(A,A,C,1.,0.,1); CH_Matrix_Classes::genmult(B,B,D,1.,0.,1);
60  return sqrt(2.*CH_Matrix_Classes::ip(C,D)+d);}
61 
63  virtual Coeffmat* subspace(const CH_Matrix_Classes::Matrix& P) const
65  return new CMlowrankdd(C,D,ConicBundle::clone(infop)); }
66 
69  { A*=d; if (infop) infop->multiply(d);}
70 
74 
78  return 2.*CH_Matrix_Classes::ip(C,D); }
79 
82  {
85  for(CH_Matrix_Classes::Integer j=0;j<C.coldim();j++){
86  const CH_Matrix_Classes::Real *pp=P.get_store()+start_row+j*P.rowdim();
87  const CH_Matrix_Classes::Real *ap=A.get_store();
89  for(CH_Matrix_Classes::Integer i=C.rowdim();--i>=0;){
90  (*cp++)=CH_Matrix_Classes::mat_ip(ard,ap,pp);
91  ap+=ard;
92  }
93  }
94  chk_set_init(C,1);
96  cp=D.get_store();
97  {for(CH_Matrix_Classes::Integer j=0;j<D.coldim();j++){
98  const CH_Matrix_Classes::Real *pp=P.get_store()+start_row+j*P.rowdim();
99  const CH_Matrix_Classes::Real *ap=B.get_store();
101  for(CH_Matrix_Classes::Integer i=D.rowdim();--i>=0;){
102  (*cp++)=CH_Matrix_Classes::mat_ip(ard,ap,pp);
103  ap+=ard;
104  }
105  }}
106  chk_set_init(D,1);
107  CH_Matrix_Classes::Real trval=0;
108  if (Lam==0) {
109  trval=CH_Matrix_Classes::ip(C,D);
110  }
111  else {
112  assert(Lam->dim()==P.coldim());
113  const CH_Matrix_Classes::Real *cp=C.get_store();
114  const CH_Matrix_Classes::Real *dp=D.get_store();
115  const CH_Matrix_Classes::Real *lp=Lam->get_store();
116  for (CH_Matrix_Classes::Integer i=0;i<C.coldim();i++,cp+=C.rowdim(),dp+=D.rowdim())
117  trval+=(*lp++)*CH_Matrix_Classes::mat_ip(C.rowdim(),cp,dp);
118  }
119  return 2.*trval;
120  }
121 
124  { CH_Matrix_Classes::rank2add(A,B,S,2.*d,1.); }
125 
129  CH_Matrix_Classes::genmult(B,CH_Matrix_Classes::genmult(A,C,E,1.,0.,1),D,d,1.);}
130 
134  CH_Matrix_Classes::genmult(B,CH_Matrix_Classes::genmult(A,C,E,1.,0.,1),D,d,1.);}
135 
138  {
139  CH_Matrix_Classes::Matrix tmp1; CH_Matrix_Classes::genmult(P,A,tmp1,1.,0.,1,0);
140  CH_Matrix_Classes::Matrix tmp2; CH_Matrix_Classes::genmult(B,Q,tmp2,1.,0.,1,0);
141  CH_Matrix_Classes::genmult(tmp1,tmp2,R,1.,0.,0,0);
142  CH_Matrix_Classes::genmult(P,B,tmp1,1.,0.,1,0);
143  CH_Matrix_Classes::genmult(A,Q,tmp2,1.,0.,1,0);
144  CH_Matrix_Classes::genmult(tmp1,tmp2,R,1.,1.,0,0);
145  }
146 
149  { return 4*A.rowdim()*A.coldim()+4*B.rowdim()*B.coldim(); }
150 
152  virtual int dense() const
153  {return 0;}
154 
156  virtual int sparse() const
157  { return 0;}
158 
162  CH_Matrix_Classes::Matrix& /* val */,
163  CH_Matrix_Classes::Real /* d=1. */)const
164  {return 0;}
165 
167  virtual int support_in(const CH_Matrix_Classes::Sparsesym& /* S */ ) const
168  {return 0;}
169 
172  {return 2.*CH_Matrix_Classes::ip(A,S*B);}
173 
177  CH_Matrix_Classes::rank2add(C,D,S,2.);}
178 
181  {
184  for(CH_Matrix_Classes::Integer j=0;j<C.coldim();j++){
185  const CH_Matrix_Classes::Real *pp=P.get_store()+start_row+j*P.rowdim();
186  const CH_Matrix_Classes::Real *ap=A.get_store();
188  for(CH_Matrix_Classes::Integer i=C.rowdim();--i>=0;){
189  (*cp++)=CH_Matrix_Classes::mat_ip(ard,ap,pp);
190  ap+=ard;
191  }
192  }
193  chk_set_init(C,1);
195  cp=D.get_store();
196  {for(CH_Matrix_Classes::Integer j=0;j<D.coldim();j++){
197  const CH_Matrix_Classes::Real *pp=P.get_store()+start_row+j*P.rowdim();
198  const CH_Matrix_Classes::Real *ap=B.get_store();
200  for(CH_Matrix_Classes::Integer i=D.rowdim();--i>=0;){
201  (*cp++)=CH_Matrix_Classes::mat_ip(ard,ap,pp);
202  ap+=ard;
203  }
204  }}
205  chk_set_init(D,1);
206  CH_Matrix_Classes::rank2add(C,D,S,2.*alpha,1.,1);
207  }
208 
211  CH_Matrix_Classes::Real alpha=1.,CH_Matrix_Classes::Real beta=0.,int dtrans=0) const
212  {
214  CH_Matrix_Classes::genmult(A,CH_Matrix_Classes::genmult(B,D,E,1.,0.,1,dtrans),C,alpha,beta);
215  return CH_Matrix_Classes::genmult(B,CH_Matrix_Classes::genmult(A,D,E,1.,0.,1,dtrans),C,alpha,1.);
216  }
217 
220  CH_Matrix_Classes::Real alpha=1.,CH_Matrix_Classes::Real beta=0.,int dtrans=0) const
221  {
223  CH_Matrix_Classes::genmult(CH_Matrix_Classes::genmult(D,A,E,1.,0.,dtrans),B,C,alpha,beta,0,1);
224  return CH_Matrix_Classes::genmult(CH_Matrix_Classes::genmult(D,B,E,1.,0.,dtrans),A,C,alpha,1.,0,1);
225  }
226 
228  virtual int equal(const Coeffmat* p,double tol=1e-6) const
229  {
230  const CMlowrankdd *pp=dynamic_cast<const CMlowrankdd *>(p);
231  if (pp==0)
232  return 0;
233  if ((A.rowdim()==(pp->A).rowdim())&&(A.coldim()==(pp->A).coldim()) &&
234  (B.rowdim()==(pp->B).rowdim())&&(B.coldim()==(pp->B).coldim()) &&
235  (CH_Matrix_Classes::norm2(A-pp->A)<tol) && (CH_Matrix_Classes::norm2(B-pp->B)<tol))
236  return 1;
237  if ((A.rowdim()==(pp->B).rowdim())&&(A.coldim()==(pp->B).coldim()) &&
238  (B.rowdim()==(pp->A).rowdim())&&(B.coldim()==(pp->A).coldim()) &&
239  (CH_Matrix_Classes::norm2(A-pp->B)<tol) && (CH_Matrix_Classes::norm2(B-pp->A)<tol))
240  return 1;
241  return 0;
242  }
243 
245  virtual std::ostream& display(std::ostream& o) const
246  {o<<"CMlowrankdd\n";A.display(o);B.display(o);return o;}
247 
249  virtual std::ostream& out(std::ostream& o) const
250  {return o<<"LOWRANK_DENSE_DENSE\n"<<A<<B;}
251 
253  virtual std::istream& in(std::istream& i)
254  {
255  i>>A>>B;
256  if((A.rowdim()!=B.rowdim())||(A.coldim()!=B.coldim())){
257  i.clear(std::ios::failbit);
258  if (CH_Matrix_Classes::materrout) (*CH_Matrix_Classes::materrout)<<"*** ERROR: CMlowrankdd::in(): dimensions of A and B do not match"<<std::endl;
259  }
260  return i;
261  }
262 
264  CMlowrankdd(std::istream& is,CoeffmatInfo* cip=0)
265  {CM_type=CM_lowrankdd;infop=cip;in(is);}
266 
267 
268 };
269 
271 
272 }
273 #endif
274 
#define chk_set_init(x, y)
CONICBUNDLE_DEBUG being undefined, the template function is removed. Otherwise it would allow to set ...
Definition: matop.hxx:1774
int Integer
all integer numbers in calculations and indexing are of this type
Definition: matop.hxx:40
virtual CH_Matrix_Classes::Integer dim() const
returns the order of the represented symmetric matrix
Definition: CMlowrankdd.hxx:42
Header declaring the classes ConicBundle::Coeffmat, ConicBundle::CoeffmatPointer, ConicBundle::Coeffm...
CH_Matrix_Classes::Matrix B
this is B in A*B^T+B*A^T
Definition: CMlowrankdd.hxx:28
Integer rowdim() const
returns the row dimension
Definition: matrix.hxx:215
std::ostream * materrout
if not zero, this is the output stream for runtime error messages, by default it is set to &std::cout...
double Real
all real numbers in calculations are of this type
Definition: matop.hxx:50
for CMlowrankdd
Definition: Coeffmat.hxx:33
allows to memorize the scalings applied to a Coeffmat and offers the basis for storing further user d...
Definition: Coeffmat.hxx:52
virtual int sparse(CH_Matrix_Classes::Indexmatrix &, CH_Matrix_Classes::Indexmatrix &, CH_Matrix_Classes::Matrix &, CH_Matrix_Classes::Real) const
returns 0 if not sparse. If it is sparse it returns 1 and the nonzero structure in I...
Definition: CMlowrankdd.hxx:160
virtual CH_Matrix_Classes::Real norm(void) const
returns the Frobenius norm of the matrix
Definition: CMlowrankdd.hxx:57
defines a base class for coefficient matrices in semidefinite programming, in particular for use with...
Definition: Coeffmat.hxx:125
Matrix class for integral values of type Integer
Definition: indexmat.hxx:195
virtual void add_projection(CH_Matrix_Classes::Symmatrix &S, const CH_Matrix_Classes::Matrix &P, CH_Matrix_Classes::Real alpha=1., CH_Matrix_Classes::Integer start_row=0) const
computes S+=Q^T(*this)Q for Q=P.rows(start_row,start_row+dim-1)
Definition: CMlowrankdd.hxx:180
virtual void left_right_prod(const CH_Matrix_Classes::Matrix &P, const CH_Matrix_Classes::Matrix &Q, CH_Matrix_Classes::Matrix &R) const
computes R=P^T*(*this)*Q
Definition: CMlowrankdd.hxx:137
Real norm2(const Matrix &A)
returns the Frobenius norm of A, i.e., the square root of the sum of A(i,j)*A(i,j) over all i...
Definition: matrix.hxx:1235
virtual void multiply(CH_Matrix_Classes::Real d)
multiply constraint permanentely by d; this is to allow scaling or sign changes in the constraints ...
Definition: CMlowrankdd.hxx:68
virtual const CH_Matrix_Classes::Matrix & postgenmult(const CH_Matrix_Classes::Matrix &D, CH_Matrix_Classes::Matrix &C, CH_Matrix_Classes::Real alpha=1., CH_Matrix_Classes::Real beta=0., int dtrans=0) const
computes C= alpha*(*this)*D^(T if dtrans) + beta*C, C is also returned
Definition: CMlowrankdd.hxx:210
virtual int support_in(const CH_Matrix_Classes::Sparsesym &) const
returns 0 if the support of the costraint matrix is not contained in the support of the sparse symmet...
Definition: CMlowrankdd.hxx:167
virtual void addprodto(CH_Matrix_Classes::Matrix &D, const CH_Matrix_Classes::Matrix &C, CH_Matrix_Classes::Real d=1.) const
computes D+=d*(*this)*C
Definition: CMlowrankdd.hxx:127
virtual std::ostream & display(std::ostream &o) const
display constraint information
Definition: CMlowrankdd.hxx:245
Real * get_store()
returns the current address of the internal value array; use cautiously, do not use delete! ...
Definition: matrix.hxx:326
Matrix class of symmetric matrices with real values of type Real
Definition: symmat.hxx:43
virtual CH_Matrix_Classes::Real operator()(CH_Matrix_Classes::Integer i, CH_Matrix_Classes::Integer j) const
returns the value of the matrix element (i,j)
Definition: CMlowrankdd.hxx:45
virtual std::istream & in(std::istream &i)
counterpart to out(), does not read the class type, though. This is assumed to have been read in orde...
Definition: CMlowrankdd.hxx:253
virtual int sparse() const
returns 0 if not sparse, otherwise 1
Definition: CMlowrankdd.hxx:156
void display(std::ostream &out, int precision=0, int width=0, int screenwidth=0) const
displays a matrix in a pretty way for bounded screen widths; for variables of value zero default valu...
CH_Matrix_Classes::Matrix A
this is A in A*B^T+B*A^T
Definition: CMlowrankdd.hxx:27
conic bundle method solver for sum of convex functions. See the ConicBundle_Manual for a quick introd...
Definition: CBSolver.hxx:22
virtual int equal(const Coeffmat *p, double tol=1e-6) const
returns 1, if p is the same derived class and entries differ by less than tol, otherwise zero ...
Definition: CMlowrankdd.hxx:228
virtual std::ostream & out(std::ostream &o) const
put entire contents onto ostream with the class type in the beginning so that the derived class can b...
Definition: CMlowrankdd.hxx:249
Coeffmattype CM_type
in order to enable type identification
Definition: Coeffmat.hxx:134
CoeffmatInfo * infop
allows the user to specify and output additional information
Definition: Coeffmat.hxx:135
CMlowrankdd(std::istream &is, CoeffmatInfo *cip=0)
constructor with istream and possibly additional user information
Definition: CMlowrankdd.hxx:264
virtual void addprodto(CH_Matrix_Classes::Matrix &D, const CH_Matrix_Classes::Sparsemat &C, CH_Matrix_Classes::Real d=1.) const
computes D+=d*(*this)*C
Definition: CMlowrankdd.hxx:132
Integer trace(const Indexmatrix &A)
returns the sum of the diagonal elements A(i,i) over all i
virtual CH_Matrix_Classes::Real gramip(const CH_Matrix_Classes::Matrix &P, CH_Matrix_Classes::Integer start_row, const CH_Matrix_Classes::Matrix *Lam=0) const
returns ip(*this,QQ^T)=trace Q^T(*this)Q for Q=P.rows(start_row,start_row+dim-1)
Definition: CMlowrankdd.hxx:81
virtual Coeffmat * subspace(const CH_Matrix_Classes::Matrix &P) const
delivers a new object on the heap corresponding to the matrix P^T(*this)P, the caller is responsible ...
Definition: CMlowrankdd.hxx:63
Matrix class of symmetric matrices with real values of type Real
Definition: sparssym.hxx:89
void multiply(CH_Matrix_Classes::Real sf)
scales the scale factor
Definition: Coeffmat.hxx:70
implements a low rank matrix as Coeffmat with each a dense rectangular CH_Matrix_Classes::Matrix (f...
Definition: CMlowrankdd.hxx:24
virtual CH_Matrix_Classes::Integer prodvec_flops() const
returns an estimate of number of flops to compute addprodto for a vector
Definition: CMlowrankdd.hxx:148
Integer coldim() const
returns the column dimension
Definition: matrix.hxx:218
virtual void project(CH_Matrix_Classes::Symmatrix &S, const CH_Matrix_Classes::Matrix &P) const
computes S=P^T*(*this)*P
Definition: CMlowrankdd.hxx:175
virtual const CH_Matrix_Classes::Matrix & pregenmult(const CH_Matrix_Classes::Matrix &D, CH_Matrix_Classes::Matrix &C, CH_Matrix_Classes::Real alpha=1., CH_Matrix_Classes::Real beta=0., int dtrans=0) const
computes C= alpha*D^(T if dtrans)*(*this) + beta*C, C is also returned
Definition: CMlowrankdd.hxx:219
Matrix class for real values of type Real
Definition: matrix.hxx:74
virtual void addmeto(CH_Matrix_Classes::Symmatrix &S, CH_Matrix_Classes::Real d=1.) const
computes S+=d*(*this);
Definition: CMlowrankdd.hxx:123
Val mat_ip(Integer len, const Val *x, const Val *y, const Val *d=0)
return sum(x[i]*y[i]) summing over len elements of the arrays x and y.
Definition: matop.hxx:1096
Matrix class of sparse matrices with real values of type Real
Definition: sparsmat.hxx:74
virtual void make_symmatrix(CH_Matrix_Classes::Symmatrix &S) const
returns a dense symmetric constraint matrix
Definition: CMlowrankdd.hxx:53
virtual CH_Matrix_Classes::Real ip(const CH_Matrix_Classes::Symmatrix &S) const
returns ip(*this,S)=trace(*this*S), the trace inner product
Definition: CMlowrankdd.hxx:72
virtual int dense() const
returns 1 if its structure is as bad as its dense symmetric representation, otherwise 0 ...
Definition: CMlowrankdd.hxx:152
virtual Coeffmat * clone() const
makes an explicit copy of itself and returns a pointer to it
Definition: CMlowrankdd.hxx:38
CMlowrankdd(const CH_Matrix_Classes::Matrix &Ain, const CH_Matrix_Classes::Matrix &Bin, CoeffmatInfo *cip=0)
copy Ain, Bin and store the user information
Definition: CMlowrankdd.hxx:31
virtual CH_Matrix_Classes::Real gramip(const CH_Matrix_Classes::Matrix &P) const
returns ip(*this,PP^T)=trace P^T(*this)P
Definition: CMlowrankdd.hxx:76
Indexmatrix & genmult(const Indexmatrix &A, const Indexmatrix &B, Indexmatrix &C, Integer alpha=1, Integer beta=0, int atrans=0, int btrans=0)
returns C=beta*C+alpha*A*B, where A and B may be transposed; C must not be equal to A and B; if beta=...
Symmatrix & rank2add(const Matrix &A, const Matrix &B, Symmatrix &C, Real alpha=1., Real beta=0., int trans=0)
returns C=beta*C+alpha*(A*B^T+B*A^T)/2 [or for transposed (A^T*B+B^T*A)/2]. If beta==0. then C is initiliazed to the correct size.
double sqrt(int a)
return sqrt for int a
Definition: mymath.hxx:121
CoeffmatInfo * clone(const CoeffmatInfo *cip)
if cip is not zero, it calls and returns cip->clone() and 0 otherwise
Definition: Coeffmat.hxx:106
virtual CH_Matrix_Classes::Real ip(const CH_Matrix_Classes::Sparsesym &S) const
returns the inner product of the constraint matrix with S
Definition: CMlowrankdd.hxx:171
Real ip(const Matrix &A, const Matrix &B)
returns the usual inner product of A and B, i.e., the sum of A(i,j)*B(i,j) over all i...
Definition: matrix.hxx:1165