00001 // Hessian coloring algorithms -*- C++ -*- 00002 00003 // Copyright (C) 2008 Mihaly Csaba Markot 00004 // 00005 // This file is a COCONUT inference engine. This library 00006 // is free software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 2, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // Library GNU General Public License for more details. 00015 00016 // As a special exception, you may use this file as part of a free software 00017 // library without restriction. Specifically, if other files instantiate 00018 // templates or use macros or inline functions from this file, or you compile 00019 // this file and link it with other files to produce an executable, this 00020 // file does not by itself cause the resulting executable to be covered by 00021 // the Library GNU General Public License. This exception does not however 00022 // invalidate any other reasons why the executable file might be covered by 00023 // the Library GNU General Public License. 00024 00027 #ifndef __HESS_COLOR_H_ 00028 #define __HESS_COLOR_H_ 00029 00030 #include <sparsity.h> 00031 #include <linalg.h> 00032 #include <print_seq.h> 00033 00034 namespace coco { 00035 00036 // This value can be used to determine whether the Hessian is sparse enough 00037 // to invoke Hessian-coloring and thus the evaluations of binary vectors for 00038 // the Hessian-vector products. For dense problems the unit vectors are adviced 00039 // to be used. 00040 #define HESS_VEC_THRESHOLD 0.9 00041 00042 // This is algorithm StarColoringAlg1 of A.H. Gebremedhin, F. Manne, A. Pothen: 00043 // "What Color Is Your Jacobian? Graph Coloring For Computing Derivatives.", 00044 // SIAM Review 47(4), pp. 629-705. 00045 // 00046 // Input: n, the size of the Hessian (number of variables) 00047 // H, the sparsity structure of the Hessian (e.g. as a 0-1 matrix, of 00048 // size nxn 00049 // Output: parts: the partitioning of the columns of H. 00050 // provides: provides has parts.size() rows and n columns, and each 00051 // nonzero element of it, (say provides[i][j] = k), indicates 00052 // that the jth element of the product of the Hessian and the 00053 // ith binary vector provides the Hessian element 00054 // H(j,k-1) = H(k-1,j). 00055 // 00056 // Meaning: By setting the binary n-vector d_i to d_i[j]=1 if j \in parts[i], 00057 // d_i[j]=0 otherwise, and computing Hess*d_i (i=1,...,parts.size()), it is 00058 // guaranteed that all different element of the Hessian appears as some element 00059 // of the resulting product, as given by "provides". 00060 // 00061 void hess_star_color1(const unsigned int n, 00062 const linalg::matrix<int>& H, 00063 std::vector<std::vector<unsigned int> >& parts, 00064 std::vector<linalg::sparse_vector<unsigned int> >& provides); 00065 00066 } // namespace coco 00067 00068 #endif /* __HESS_COLOR_H_ */