ConicBundle
AffineFunctionTransformation.hxx
Go to the documentation of this file.
1 
2 
3 #ifndef CONICBUNDLE_AFFINEFUNCTIONTRANSFORMATION_HXX
4 #define CONICBUNDLE_AFFINEFUNCTIONTRANSFORMATION_HXX
5 
13 #include "CBout.hxx"
14 #include "CBSolver.hxx"
15 #include "MinorantPointer.hxx"
16 #include "AFTModification.hxx"
18 
19 
20 namespace ConicBundle {
21 
25 
26 
27 //-----------------------------------------------------------------------------
28 // AffineFunctionTransformation
29 //-----------------------------------------------------------------------------
30 
69  {
70  private:
76 
78 
80 
82 
83  public:
85  virtual int init(CH_Matrix_Classes::Real fun_coeff=1.,
86  CH_Matrix_Classes::Real fun_offset=0.,
87  CH_Matrix_Classes::Matrix* linear_cost=0,
88  CH_Matrix_Classes::Matrix* arg_offset=0,
89  CH_Matrix_Classes::Sparsemat* arg_trafo=0,
90  bool model_calls_delete=true);
91 
94  CH_Matrix_Classes::Real in_fun_offset=0.,
95  CH_Matrix_Classes::Matrix* in_linear_cost=0,
96  CH_Matrix_Classes::Matrix* in_arg_offset=0,
97  CH_Matrix_Classes::Sparsemat* in_arg_trafo=0,
98  bool in_model_calls_delete=true,
99  CBout* cbo=0,int incr=-1):
100  CBout(cbo,incr),linear_cost(0),arg_offset(0),arg_trafo(0)
101  {init(in_fun_coeff,in_fun_offset,in_linear_cost,in_arg_offset,in_arg_trafo,in_model_calls_delete);}
102 
105 
108 
110  void set_model_calls_delete(bool mcd){model_calls_delete=mcd;}
111 
113  bool argument_changes() const
114  {if ((arg_offset!=0)||(arg_trafo!=0)) return true; return false;}
115 
120  { return ((arg_trafo!=0)&&(3*arg_trafo->get_rowinfo().rowdim()<=arg_trafo->rowdim()));}
121 
126  const CH_Matrix_Classes::Indexmatrix* row_ind) const;
127 
132  bool scaled_index(CH_Matrix_Classes::Integer& mapped_index,
134  CH_Matrix_Classes::Integer index) const;
135 
138  {return fun_coeff;}
139 
142  {return fun_coeff;}
143 
146  {return fun_offset;}
147 
150  {return fun_offset;}
151 
154  {return linear_cost;}
155 
158  {return arg_offset;}
159 
162  {return arg_trafo;}
163 
166  {
167  if (i<0) return fun_offset;
168  if (linear_cost) return (*linear_cost)(i);
169  return 0.;
170  }
171 
174  return constant_minorant;
175  }
176 
179  {
180  if (arg_trafo)
181  return arg_trafo->coldim();
182  if (linear_cost)
183  return linear_cost->rowdim();
184  if (arg_offset) //arg_trafo==NULL is the identity, so this is ok
185  return arg_offset->rowdim();
186  return -1; //no information on the dimension
187  }
188 
191  {
192  if (arg_trafo)
193  return arg_trafo->rowdim();
194  if (arg_offset)
195  return arg_offset->rowdim();
196  if (linear_cost) //arg_trafo==NULL is the identity, so this is ok
197  return linear_cost->rowdim();
198  return -1; //no information on the dimension
199  }
200 
203  const CH_Matrix_Classes::Matrix& copy_from) const;
204 
222  CH_Matrix_Classes::Real& transformed_offset,
223  const CH_Matrix_Classes::Matrix& input_y) const;
224 
225 
237  const CH_Matrix_Classes::Matrix& input_y,
238  const AFTModification* aftmdf,
239  const GroundsetModification& gsmdf) const;
240 
241 
247  CH_Matrix_Classes::Real function_value) const
248  {return offset+fun_coeff*function_value;}
249 
264  int transform_minorant(MinorantPointer& out_minorant,
265  const MinorantPointer& in_minorant,
266  CH_Matrix_Classes::Real alpha=1.,
267  bool add_trafo_minorant=false,
268  const CH_Matrix_Classes::Indexmatrix* provided_row_indices=0,
269  const CH_Matrix_Classes::Indexmatrix* needed_column_indices=0) const;
270 
277  int transform_minorants(MinorantBundle& out_minorants,
278  const MinorantBundle& in_minorants,
279  CH_Matrix_Classes::Real alpha=1.) const;
280 
281 
282 
290  int qp_cost_indices(CH_Matrix_Classes::Indexmatrix& provide_row_indices,
291  const CH_Matrix_Classes::Indexmatrix* needed_col_indices) const;
292 
300  const CH_Matrix_Classes::Indexmatrix& col_indices) const;
301 
309  const CH_Matrix_Classes::Indexmatrix* indices,
311  const CH_Matrix_Classes::Matrix& in_diagscale) const;
312 
337  const GroundsetModification*
338  analyze_modification(bool& minorant_trafo_differs,
339  const AFTModification* aftmdf,
340  const GroundsetModification& gsmdf) const;
341 
349  int
350  apply_modification(const AFTModification* aftmdf,
351  const GroundsetModification& gsmdf);
352 
353 
355  virtual std::ostream& output_aft_data(std::ostream& out) const;
356 
357 
358  };
359 
360 
361 
363 
364 }
365 
366 #endif
367 
CH_Matrix_Classes::Real get_fun_offset() const
returns the constant offset for the funciton
Definition: AffineFunctionTransformation.hxx:145
const GroundsetModification * analyze_modification(bool &minorant_trafo_differs, const AFTModification *aftmdf, const GroundsetModification &gsmdf) const
returns information on the changes in the ground set of the transformed arguments and checks whether ...
int Integer
all integer numbers in calculations and indexing are of this type
Definition: matop.hxx:40
bool scaled_index(CH_Matrix_Classes::Integer &mapped_index, CH_Matrix_Classes::Real &coeff, CH_Matrix_Classes::Integer index) const
returns false if index is mapped to more than one index, otherwise true with mapped_index==-1 if mapp...
const CH_Matrix_Classes::Sparsemat * get_arg_trafo() const
returns the pointer to the linear transformation of the argument (not neeeded in the code) ...
Definition: AffineFunctionTransformation.hxx:161
const CH_Matrix_Classes::Matrix & modified_transform_argument(CH_Matrix_Classes::Matrix &transformed_y, const CH_Matrix_Classes::Matrix &input_y, const AFTModification *aftmdf, const GroundsetModification &gsmdf) const
given the modification aftmdf or if 0, gsmdf, compute the transformed argument that would arise after...
int transform_minorant(MinorantPointer &out_minorant, const MinorantPointer &in_minorant, CH_Matrix_Classes::Real alpha=1., bool add_trafo_minorant=false, const CH_Matrix_Classes::Indexmatrix *provided_row_indices=0, const CH_Matrix_Classes::Indexmatrix *needed_column_indices=0) const
transforms the in linear minorant (scaled by alpha) and initializes or adds it to the out linear mino...
CH_Matrix_Classes::Real get_fun_coeff() const
returns the factor for the function
Definition: AffineFunctionTransformation.hxx:137
Integer rowdim() const
returns the row dimension
Definition: matrix.hxx:215
double Real
all real numbers in calculations are of this type
Definition: matop.hxx:50
CH_Matrix_Classes::Real objective_value(CH_Matrix_Classes::Real offset, CH_Matrix_Classes::Real function_value) const
if offset is the value computed in transform_argument and function_value results form an evaluation i...
Definition: AffineFunctionTransformation.hxx:246
Matrix class for integral values of type Integer
Definition: indexmat.hxx:195
CH_Matrix_Classes::Real fun_offset
constant added in the end
Definition: AffineFunctionTransformation.hxx:72
int add_diagonal_scaling(CH_Matrix_Classes::Matrix &diagscale, const CH_Matrix_Classes::Indexmatrix *indices, CH_Matrix_Classes::Real alpha, const CH_Matrix_Classes::Matrix &in_diagscale) const
transform the scaling matrix in_diagscale of the untransformed function model and add it as described...
virtual ~AffineFunctionTransformation()
deletes linear_cost, arg_offset and arg_trafo
bool sparse_argument_changes() const
returns true if arg_trafo influences at most two thirds of the entries of local_argument ...
Definition: AffineFunctionTransformation.hxx:119
int copy_traforows(CH_Matrix_Classes::Matrix &copy_to, const CH_Matrix_Classes::Matrix &copy_from) const
only copies the elements that are effected by the image of arg_trafo
virtual std::ostream & output_aft_data(std::ostream &out) const
for testing purposes this outputs the data in mfile readable form
bool get_model_calls_delete()
retruns true if the model has to delete this
Definition: AffineFunctionTransformation.hxx:107
conic bundle method solver for sum of convex functions. See the ConicBundle_Manual for a quick introd...
Definition: CBSolver.hxx:22
AffineFunctionTransformation(CH_Matrix_Classes::Real in_fun_coeff=1., CH_Matrix_Classes::Real in_fun_offset=0., CH_Matrix_Classes::Matrix *in_linear_cost=0, CH_Matrix_Classes::Matrix *in_arg_offset=0, CH_Matrix_Classes::Sparsemat *in_arg_trafo=0, bool in_model_calls_delete=true, CBout *cbo=0, int incr=-1)
calls init()
Definition: AffineFunctionTransformation.hxx:93
CH_Matrix_Classes::Sparsemat * arg_trafo
NULL means identity (!!!)
Definition: AffineFunctionTransformation.hxx:75
base class for uniform use of WARNINGS and ERRORS (at some point in time)
Definition: CBout.hxx:30
Header declaring the classes ConicBundle::CBSolver, ConicBundle::FunctionOracle and ConicBundle::Prim...
bool argument_changes() const
returns true if not the identity
Definition: AffineFunctionTransformation.hxx:113
CH_Matrix_Classes::Real get_linear_cost(CH_Matrix_Classes::Integer i) const
returns the value of the linear cost coefficient for i>=0 and for i==-1 the constant offset ...
Definition: AffineFunctionTransformation.hxx:165
Header declaring the output class CBout.
CH_Matrix_Classes::Real fun_coeff
function value is multiplied by this
Definition: AffineFunctionTransformation.hxx:71
bool scaled_index_subset(const CH_Matrix_Classes::Indexmatrix *col_ind, const CH_Matrix_Classes::Indexmatrix *row_ind) const
returns true if the transformation maps each index (in col_ind if !=0) onto at most one index and vic...
Header declaring the class ConicBundle::AFTModification.
CH_Matrix_Classes::Matrix * arg_offset
NULL means no offset.
Definition: AffineFunctionTransformation.hxx:74
collects modifications for an AffineFunctionTransformation for the scaling and offset constants as we...
Definition: AFTModification.hxx:31
Matrix class for real values of type Real
Definition: matrix.hxx:74
Header declaring the class ConicBundle::GroundsetModification.
const CH_Matrix_Classes::Matrix * get_linear_cost() const
returns the pointer to the linear term added to the funciton
Definition: AffineFunctionTransformation.hxx:153
int scaling_indices(CH_Matrix_Classes::Indexmatrix &row_indices, const CH_Matrix_Classes::Indexmatrix &col_indices) const
if AFTModel::add_diagonal_scaling() is called with indices specified by col_indices, then AFTmodel has to provide a diagonal scaling matrix of dimension to_dim() as in_diagscale in add_diagonal_scaling() with the entries in the output vector row_indices computed correctly.
virtual int init(CH_Matrix_Classes::Real fun_coeff=1., CH_Matrix_Classes::Real fun_offset=0., CH_Matrix_Classes::Matrix *linear_cost=0, CH_Matrix_Classes::Matrix *arg_offset=0, CH_Matrix_Classes::Sparsemat *arg_trafo=0, bool model_calls_delete=true)
sets the parameters of the transformation. The ownership of objects pointed to is passed to *this (th...
std::ostream * out
not output at all if out==0, otherwise use this output stream
Definition: CBout.hxx:33
int transform_minorants(MinorantBundle &out_minorants, const MinorantBundle &in_minorants, CH_Matrix_Classes::Real alpha=1.) const
transforms several linear minorants (scaled by alpha) and initializes or adds them to the out linear ...
Matrix class of sparse matrices with real values of type Real
Definition: sparsmat.hxx:74
std::vector< MinorantPointer > MinorantBundle
a bundle is a vector with MinorantPointer entries
Definition: MinorantPointer.hxx:24
const CH_Matrix_Classes::Matrix & transform_argument(CH_Matrix_Classes::Matrix &transformed_y, CH_Matrix_Classes::Real &transformed_offset, const CH_Matrix_Classes::Matrix &input_y) const
computes transformed_offset and, if this is not the identity,transformed_y and returns either input_y...
const Indexmatrix & get_rowinfo() const
returns information on nonzero rows, k by 3, listing: index, %nonzeros, first index in rowindex/rowva...
Definition: sparsmat.hxx:272
CH_Matrix_Classes::Real & set_fun_offset()
allows to set the constant offset for the funciton
Definition: AffineFunctionTransformation.hxx:149
CH_Matrix_Classes::Real & set_fun_coeff()
allows to set the factor for the function
Definition: AffineFunctionTransformation.hxx:141
Integer rowdim() const
returns the row dimension
Definition: indexmat.hxx:321
MinorantPointer constant_minorant
corresponds to fun_offset + <*linear_cost,.>
Definition: AffineFunctionTransformation.hxx:77
const MinorantPointer & get_constant_minorant() const
return the constant linear minorant corresponding to fun_offset+<*linear_cost,.>
Definition: AffineFunctionTransformation.hxx:173
basic function object (abstract class). It serves for using the same interface on distinct oracle typ...
Definition: CBSolver.hxx:236
int apply_modification(const AFTModification *aftmdf, const GroundsetModification &gsmdf)
if arg_trafo==NULL (act as identity) and if aftmdf!=NULL adds any explicit matrix parts or has modifi...
Collects modifications for the unconstrained Groundset for appending, deleting or reassigning variabl...
Definition: GroundsetModification.hxx:32
const CH_Matrix_Classes::Matrix * get_arg_offset() const
returns the pointer to the constant offset added to the argument (not neeeded in the code) ...
Definition: AffineFunctionTransformation.hxx:157
CH_Matrix_Classes::Matrix * linear_cost
NULL means no linear cost.
Definition: AffineFunctionTransformation.hxx:73
Header declaring the class ConicBundle::MinorantPointer.
void set_model_calls_delete(bool mcd)
set to true if the model has to delete this, to false if it is destructed elsewhere ...
Definition: AffineFunctionTransformation.hxx:110
GroundsetModification local_gsmdf
this describes the effect of the last modification on the image space (if there was one at all) ...
Definition: AffineFunctionTransformation.hxx:79
transform a function f(z) to fun_coeff*f(arg_offset+arg_trafo*y)+linear_cost*y+fun_offset (scales the...
Definition: AffineFunctionTransformation.hxx:68
Integer coldim() const
returns the column dimension
Definition: sparsmat.hxx:202
Integer rowdim() const
returns the row dimension
Definition: sparsmat.hxx:199
points to MinorantUseData that may be shared by many and allows computations with Minorants ...
Definition: MinorantPointer.hxx:34
bool model_calls_delete
tells the model whether it should delete this at the end of its use or just leave it alone (i...
Definition: AffineFunctionTransformation.hxx:81
CH_Matrix_Classes::Integer from_dim() const
returns the dimension of the input argument or -1 if it is unknown
Definition: AffineFunctionTransformation.hxx:178
int qp_cost_indices(CH_Matrix_Classes::Indexmatrix &provide_row_indices, const CH_Matrix_Classes::Indexmatrix *needed_col_indices) const
if the algorithm only requires the indices given in needed_col_indices (NULL means all indices) then ...
CH_Matrix_Classes::Integer to_dim() const
returns the dimension of the output argument or -1 if it is unknown
Definition: AffineFunctionTransformation.hxx:190