-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActiveSetNNLS_8h_source.html
116 lines (114 loc) · 35.1 KB
/
ActiveSetNNLS_8h_source.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>planc: /Users/rnu/Documents/research/nmflibrary/nnls/ActiveSetNNLS.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
$(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="logo.png"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">planc
</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('ActiveSetNNLS_8h_source.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="headertitle">
<div class="title">ActiveSetNNLS.h</div> </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="comment">// $Id: nnls.cc,v 1.1.2.1 2003/03/06 16:28:07 suvrit Exp $</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="comment">// File: nnls.cc</span></div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="comment">// Implements the Lawson-Hanson NNLS algorithm</span></div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span> </div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="comment">// https://software.sandia.gov/appspack/version3/nnls_8c-source.html</span></div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span> </div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="comment">// Copyright (C) 2004 Lawson-Hanson</span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="comment">// Modifications to adapt to c++ by Suvrit Sra.</span></div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span> </div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="comment">// This program is free software; you can redistribute it and/or</span></div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="comment">// modify it under the terms of the GNU General Public License</span></div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="comment">// as published by the Free Software Foundation; either version 2</span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span> <span class="comment">// of the License, or (at your option) any later version.</span></div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span> </div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="comment">// This program is distributed in the hope that it will be useful,</span></div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span> <span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span> <span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span></div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span> <span class="comment">// GNU General Public License for more details.</span></div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span> </div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span> <span class="comment">// You should have received a copy of the GNU General Public License</span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span> <span class="comment">// along with this program; if not, write to the Free Software</span></div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span> <span class="comment">// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</span></div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span> </div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <span class="preprocessor">#ifndef NNLS_ACTIVESETNNLS_H_</span></div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span> <span class="preprocessor">#define NNLS_ACTIVESETNNLS_H_</span></div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span> </div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span> <span class="preprocessor">#include <stdio.h></span></div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span> <span class="preprocessor">#include <math.h></span></div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span> <span class="preprocessor">#define nnls_max(a, b) ((a) >= (b) ? (a) : (b))</span></div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span> <span class="preprocessor">#define nnls_abs(x) ((x) >= 0 ? (x) : -(x))</span></div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span> </div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span> <span class="comment">// has definitions of nnls, g1, h12 function</span></div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span> <span class="comment">// defined them static to avoid multiple definitions</span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span> <span class="comment">// error</span></div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span> <span class="preprocessor">#include "ActiveSetNNLS.hpp"</span></div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span> </div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span> <span class="keyword">typedef</span> <span class="keywordtype">int</span> integer;</div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span> <span class="keyword">typedef</span> <span class="keywordtype">double</span> doublereal;</div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span> </div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span> <span class="comment">/* SUBROUTINE NNLS (A,MDA,M,N,B,X,RNORM,W,ZZ,INDEX,MODE) */</span></div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span> </div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span> <span class="comment">/* Algorithm NNLS: NONNEGATIVE LEAST SQUARES */</span></div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span> </div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span> <span class="comment">/* The original version of this code was developed by */</span></div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span> <span class="comment">/* Charles L. Lawson and Richard J. Hanson at Jet Propulsion Laboratory */</span></div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span> <span class="comment">/* 1973 JUN 15, and published in the book */</span></div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span> <span class="comment">/* "SOLVING LEAST SQUARES PROBLEMS", Prentice-HalL, 1974. */</span></div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span> <span class="comment">/* Revised FEB 1995 to accompany reprinting of the book by SIAM. */</span></div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span> </div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span> <span class="comment">/* GIVEN AN M BY N MATRIX, A, AND AN M-VECTOR, B, COMPUTE AN */</span></div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span> <span class="comment">/* N-VECTOR, X, THAT SOLVES THE LEAST SQUARES PROBLEM */</span></div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span> </div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span> <span class="comment">/* A * X = B SUBJECT TO X .GE. 0 */</span></div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span> <span class="comment">/* ------------------------------------------------------------------ */</span></div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span> <span class="comment">/* Subroutine Arguments */</span></div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span> </div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span> <span class="comment">/* A(),MDA,M,N MDA IS THE FIRST DIMENSIONING PARAMETER FOR THE */</span></div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span> <span class="comment">/* ARRAY, A(). ON ENTRY A() CONTAINS THE M BY N */</span></div><div class="line"><a name="l00059"></a><span class="lineno"> 59</span> <span class="comment">/* MATRIX, A. ON EXIT A() CONTAINS */</span></div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span> <span class="comment">/* THE PRODUCT MATRIX, Q*A , WHERE Q IS AN */</span></div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span> <span class="comment">/* M BY M ORTHOGONAL MATRIX GENERATED IMPLICITLY BY */</span></div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span> <span class="comment">/* THIS SUBROUTINE. */</span></div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span> <span class="comment">/* B() ON ENTRY B() CONTAINS THE M-VECTOR, B. ON EXIT B() CON- */</span></div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span> <span class="comment">/* TAINS Q*B. */</span></div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span> <span class="comment">/* X() ON ENTRY X() NEED NOT BE INITIALIZED. ON EXIT X() WILL */</span></div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span> <span class="comment">/* CONTAIN THE SOLUTION VECTOR. */</span></div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span> <span class="comment">/* RNORM ON EXIT RNORM CONTAINS THE EUCLIDEAN NORM OF THE */</span></div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span> <span class="comment">/* RESIDUAL VECTOR. */</span></div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span> <span class="comment">/* W() AN N-ARRAY OF WORKING SPACE. ON EXIT W() WILL CONTAIN */</span></div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span> <span class="comment">/* THE DUAL SOLUTION VECTOR. W WILL SATISFY W(I) = 0. */</span></div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span> <span class="comment">/* FOR ALL I IN SET P AND W(I) .LE. 0. FOR ALL I IN SET Z */</span></div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span> <span class="comment">/* ZZ() AN M-ARRAY OF WORKING SPACE. */</span></div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span> <span class="comment">/* INDEX() AN INT WORKING ARRAY OF LENGTH AT LEAST N. */</span></div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span> <span class="comment">/* ON EXIT THE CONTENTS OF THIS ARRAY DEFINE THE SETS */</span></div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span> <span class="comment">/* P AND Z AS FOLLOWS.. */</span></div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span> </div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span> <span class="comment">/* INDEX(1) THRU INDEX(NSETP) = SET P. */</span></div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span> <span class="comment">/* INDEX(IZ1) THRU INDEX(IZ2) = SET Z. */</span></div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span> <span class="comment">/* IZ1 = NSETP + 1 = NPP1 */</span></div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span> <span class="comment">/* IZ2 = N */</span></div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span> <span class="comment">/* MODE THIS IS A SUCCESS-FAILURE FLAG WITH THE FOLLOWING */</span></div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span> <span class="comment">/* MEANINGS. */</span></div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span> <span class="comment">/* 1 THE SOLUTION HAS BEEN COMPUTED SUCCESSFULLY. */</span></div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span> <span class="comment">/* 2 THE DIMENSIONS OF THE PROBLEM ARE BAD. */</span></div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span> <span class="comment">/* EITHER M .LE. 0 OR N .LE. 0. */</span></div><div class="line"><a name="l00086"></a><span class="lineno"> 86</span> <span class="comment">/* 3 ITERATION COUNT EXCEEDED. MORE THAN 3*N ITERATIONS. */</span></div><div class="line"><a name="l00087"></a><span class="lineno"> 87</span> </div><div class="line"><a name="l00088"></a><span class="lineno"> 88</span> <span class="comment">/* ------------------------------------------------------------------ */</span></div><div class="line"><a name="l00089"></a><span class="lineno"> 89</span> <span class="comment">/* Subroutine */</span></div><div class="line"><a name="l00090"></a><span class="lineno"> 90</span> <span class="comment">//int nnls(double* a, int mda, int m, int n,</span></div><div class="line"><a name="l00091"></a><span class="lineno"> 91</span> <span class="comment">// double* b, double* x, double* rnorm,</span></div><div class="line"><a name="l00092"></a><span class="lineno"> 92</span> <span class="comment">// double* w, double* zz, int* index, int* mode, int maxIter);</span></div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span> </div><div class="line"><a name="l00094"></a><span class="lineno"> 94</span> </div><div class="line"><a name="l00095"></a><span class="lineno"> 95</span> </div><div class="line"><a name="l00096"></a><span class="lineno"> 96</span> <span class="comment">/* SUBROUTINE H12 (MODE,LPIVOT,L1,M,U,IUE,UP,C,ICE,ICV,NCV) */</span></div><div class="line"><a name="l00097"></a><span class="lineno"> 97</span> </div><div class="line"><a name="l00098"></a><span class="lineno"> 98</span> <span class="comment">/* CONSTRUCTION AND/OR APPLICATION OF A SINGLE */</span></div><div class="line"><a name="l00099"></a><span class="lineno"> 99</span> <span class="comment">/* HOUSEHOLDER TRANSFORMATION.. Q = I + U*(U**T)/B */</span></div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span> </div><div class="line"><a name="l00101"></a><span class="lineno"> 101</span> <span class="comment">/* The original version of this code was developed by */</span></div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span> <span class="comment">/* Charles L. Lawson and Richard J. Hanson at Jet Propulsion Laboratory */</span></div><div class="line"><a name="l00103"></a><span class="lineno"> 103</span> <span class="comment">/* 1973 JUN 12, and published in the book */</span></div><div class="line"><a name="l00104"></a><span class="lineno"> 104</span> <span class="comment">/* "SOLVING LEAST SQUARES PROBLEMS", Prentice-HalL, 1974. */</span></div><div class="line"><a name="l00105"></a><span class="lineno"> 105</span> <span class="comment">/* Revised FEB 1995 to accompany reprinting of the book by SIAM. */</span></div><div class="line"><a name="l00106"></a><span class="lineno"> 106</span> <span class="comment">/* ------------------------------------------------------------------ */</span></div><div class="line"><a name="l00107"></a><span class="lineno"> 107</span> <span class="comment">/* Subroutine Arguments */</span></div><div class="line"><a name="l00108"></a><span class="lineno"> 108</span> </div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span> <span class="comment">/* MODE = 1 OR 2 Selects Algorithm H1 to construct and apply a */</span></div><div class="line"><a name="l00110"></a><span class="lineno"> 110</span> <span class="comment">/* Householder transformation, or Algorithm H2 to apply a */</span></div><div class="line"><a name="l00111"></a><span class="lineno"> 111</span> <span class="comment">/* previously constructed transformation. */</span></div><div class="line"><a name="l00112"></a><span class="lineno"> 112</span> <span class="comment">/* LPIVOT IS THE INDEX OF THE PIVOT ELEMENT. */</span></div><div class="line"><a name="l00113"></a><span class="lineno"> 113</span> <span class="comment">/* L1,M IF L1 .LE. M THE TRANSFORMATION WILL BE CONSTRUCTED TO */</span></div><div class="line"><a name="l00114"></a><span class="lineno"> 114</span> <span class="comment">/* ZERO ELEMENTS INDEXED FROM L1 THROUGH M. IF L1 GT. M */</span></div><div class="line"><a name="l00115"></a><span class="lineno"> 115</span> <span class="comment">/* THE SUBROUTINE DOES AN IDENTITY TRANSFORMATION. */</span></div><div class="line"><a name="l00116"></a><span class="lineno"> 116</span> <span class="comment">/* U(),IUE,UP On entry with MODE = 1, U() contains the pivot */</span></div><div class="line"><a name="l00117"></a><span class="lineno"> 117</span> <span class="comment">/* vector. IUE is the storage increment between elements. */</span></div><div class="line"><a name="l00118"></a><span class="lineno"> 118</span> <span class="comment">/* On exit when MODE = 1, U() and UP contain quantities */</span></div><div class="line"><a name="l00119"></a><span class="lineno"> 119</span> <span class="comment">/* defining the vector U of the Householder transformation. */</span></div><div class="line"><a name="l00120"></a><span class="lineno"> 120</span> <span class="comment">/* on entry with MODE = 2, U() and UP should contain */</span></div><div class="line"><a name="l00121"></a><span class="lineno"> 121</span> <span class="comment">/* quantities previously computed with MODE = 1. These will */</span></div><div class="line"><a name="l00122"></a><span class="lineno"> 122</span> <span class="comment">/* not be modified during the entry with MODE = 2. */</span></div><div class="line"><a name="l00123"></a><span class="lineno"> 123</span> <span class="comment">/* C() ON ENTRY with MODE = 1 or 2, C() CONTAINS A MATRIX WHICH */</span></div><div class="line"><a name="l00124"></a><span class="lineno"> 124</span> <span class="comment">/* WILL BE REGARDED AS A SET OF VECTORS TO WHICH THE */</span></div><div class="line"><a name="l00125"></a><span class="lineno"> 125</span> <span class="comment">/* HOUSEHOLDER TRANSFORMATION IS TO BE APPLIED. */</span></div><div class="line"><a name="l00126"></a><span class="lineno"> 126</span> <span class="comment">/* ON EXIT C() CONTAINS THE SET OF TRANSFORMED VECTORS. */</span></div><div class="line"><a name="l00127"></a><span class="lineno"> 127</span> <span class="comment">/* ICE STORAGE INCREMENT BETWEEN ELEMENTS OF VECTORS IN C(). */</span></div><div class="line"><a name="l00128"></a><span class="lineno"> 128</span> <span class="comment">/* ICV STORAGE INCREMENT BETWEEN VECTORS IN C(). */</span></div><div class="line"><a name="l00129"></a><span class="lineno"> 129</span> <span class="comment">/* NCV NUMBER OF VECTORS IN C() TO BE TRANSFORMED. IF NCV .LE. 0 */</span></div><div class="line"><a name="l00130"></a><span class="lineno"> 130</span> <span class="comment">/* NO OPERATIONS WILL BE DONE ON C(). */</span></div><div class="line"><a name="l00131"></a><span class="lineno"> 131</span> <span class="comment">/* ------------------------------------------------------------------ */</span></div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span> <span class="comment">/* Subroutine */</span></div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span> <span class="comment">//int h12(int mode, int* lpivot, int* l1,</span></div><div class="line"><a name="l00134"></a><span class="lineno"> 134</span> <span class="comment">// int m, double* u, int* iue, double* up, double* c__,</span></div><div class="line"><a name="l00135"></a><span class="lineno"> 135</span> <span class="comment">// int* ice, int* icv, int* ncv);</span></div><div class="line"><a name="l00136"></a><span class="lineno"> 136</span> </div><div class="line"><a name="l00137"></a><span class="lineno"> 137</span> </div><div class="line"><a name="l00138"></a><span class="lineno"> 138</span> <span class="comment">/* COMPUTE ORTHOGONAL ROTATION MATRIX.. */</span></div><div class="line"><a name="l00139"></a><span class="lineno"> 139</span> </div><div class="line"><a name="l00140"></a><span class="lineno"> 140</span> <span class="comment">/* The original version of this code was developed by */</span></div><div class="line"><a name="l00141"></a><span class="lineno"> 141</span> <span class="comment">/* Charles L. Lawson and Richard J. Hanson at Jet Propulsion Laboratory</span></div><div class="line"><a name="l00142"></a><span class="lineno"> 142</span> <span class="comment"> */</span></div><div class="line"><a name="l00143"></a><span class="lineno"> 143</span> <span class="comment">/* 1973 JUN 12, and published in the book */</span></div><div class="line"><a name="l00144"></a><span class="lineno"> 144</span> <span class="comment">/* "SOLVING LEAST SQUARES PROBLEMS", Prentice-HalL, 1974. */</span></div><div class="line"><a name="l00145"></a><span class="lineno"> 145</span> <span class="comment">/* Revised FEB 1995 to accompany reprinting of the book by SIAM. */</span></div><div class="line"><a name="l00146"></a><span class="lineno"> 146</span> </div><div class="line"><a name="l00147"></a><span class="lineno"> 147</span> <span class="comment">/* COMPUTE.. MATRIX (C, S) SO THAT (C, S)(A) = (SQRT(A**2+B**2)) */</span></div><div class="line"><a name="l00148"></a><span class="lineno"> 148</span> <span class="comment">/* (-S,C) (-S,C)(B) ( 0 ) */</span></div><div class="line"><a name="l00149"></a><span class="lineno"> 149</span> <span class="comment">/* COMPUTE SIG = SQRT(A**2+B**2) */</span></div><div class="line"><a name="l00150"></a><span class="lineno"> 150</span> <span class="comment">/* SIG IS COMPUTED LAST TO ALLOW FOR THE POSSIBILITY THAT */</span></div><div class="line"><a name="l00151"></a><span class="lineno"> 151</span> <span class="comment">/* SIG MAY BE IN THE SAME LOCATION AS A OR B . */</span></div><div class="line"><a name="l00152"></a><span class="lineno"> 152</span> <span class="comment">//int g1(double* a, double* b, double* cterm, double* sterm, double* sig);</span></div><div class="line"><a name="l00153"></a><span class="lineno"> 153</span> <span class="comment">//</span></div><div class="line"><a name="l00154"></a><span class="lineno"> 154</span> <span class="comment">// June 18, 2008 -- Added a helper class to the bottom - Ted Kim</span></div><div class="line"><a name="l00155"></a><span class="lineno"> 155</span> <span class="comment">//</span></div><div class="line"><a name="l00156"></a><span class="lineno"> 156</span> <span class="comment">// Included string for support of memcpy</span></div><div class="line"><a name="l00157"></a><span class="lineno"> 157</span> <span class="preprocessor">#include <string.h></span></div><div class="line"><a name="l00158"></a><span class="lineno"> 158</span> <span class="keyword">template</span><<span class="keyword">class</span> T></div><div class="line"><a name="l00159"></a><span class="lineno"><a class="line" href="classActiveSetNNLS.html"> 159</a></span> <span class="keyword">class </span><a class="code" href="classActiveSetNNLS.html">ActiveSetNNLS</a> {</div><div class="line"><a name="l00160"></a><span class="lineno"> 160</span>  <span class="keyword">public</span>:</div><div class="line"><a name="l00161"></a><span class="lineno"> 161</span>  <a class="code" href="classActiveSetNNLS.html">ActiveSetNNLS</a>(<span class="keywordtype">int</span> rows, <span class="keywordtype">int</span> maxCols) :</div><div class="line"><a name="l00162"></a><span class="lineno"> 162</span>  _rows( rows ),</div><div class="line"><a name="l00163"></a><span class="lineno"> 163</span>  _maxCols( maxCols ) {</div><div class="line"><a name="l00164"></a><span class="lineno"> 164</span>  _workA = <span class="keyword">new</span> T[_rows * _maxCols];</div><div class="line"><a name="l00165"></a><span class="lineno"> 165</span>  _workW = <span class="keyword">new</span> T[_maxCols];</div><div class="line"><a name="l00166"></a><span class="lineno"> 166</span>  _workZ = <span class="keyword">new</span> T[_rows];</div><div class="line"><a name="l00167"></a><span class="lineno"> 167</span>  _workIndex = <span class="keyword">new</span> <span class="keywordtype">int</span>[_maxCols];</div><div class="line"><a name="l00168"></a><span class="lineno"> 168</span> </div><div class="line"><a name="l00169"></a><span class="lineno"> 169</span>  _maxIter = 1;</div><div class="line"><a name="l00170"></a><span class="lineno"> 170</span>  }</div><div class="line"><a name="l00171"></a><span class="lineno"> 171</span> </div><div class="line"><a name="l00172"></a><span class="lineno"> 172</span>  ~<a class="code" href="classActiveSetNNLS.html">ActiveSetNNLS</a>() {</div><div class="line"><a name="l00173"></a><span class="lineno"> 173</span>  <span class="keyword">delete</span>[] _workA;</div><div class="line"><a name="l00174"></a><span class="lineno"> 174</span>  <span class="keyword">delete</span>[] _workW;</div><div class="line"><a name="l00175"></a><span class="lineno"> 175</span>  <span class="keyword">delete</span>[] _workZ;</div><div class="line"><a name="l00176"></a><span class="lineno"> 176</span>  <span class="keyword">delete</span>[] _workIndex;</div><div class="line"><a name="l00177"></a><span class="lineno"> 177</span>  }</div><div class="line"><a name="l00178"></a><span class="lineno"> 178</span> </div><div class="line"><a name="l00179"></a><span class="lineno"> 179</span>  <span class="keywordtype">bool</span> solve(T* A, <span class="keywordtype">int</span> numCols, T* b, T* x, T& rNorm) {</div><div class="line"><a name="l00180"></a><span class="lineno"> 180</span>  <span class="keywordtype">int</span> workMode;</div><div class="line"><a name="l00181"></a><span class="lineno"> 181</span> </div><div class="line"><a name="l00182"></a><span class="lineno"> 182</span>  <span class="comment">// make copy of A, since nnls() clobbers it</span></div><div class="line"><a name="l00183"></a><span class="lineno"> 183</span>  memcpy(_workA, A, numCols * _rows * <span class="keyword">sizeof</span>(T));</div><div class="line"><a name="l00184"></a><span class="lineno"> 184</span> </div><div class="line"><a name="l00185"></a><span class="lineno"> 185</span>  <span class="comment">// do it</span></div><div class="line"><a name="l00186"></a><span class="lineno"> 186</span>  nnls(_workA, _rows, _rows, numCols, b, x, &rNorm,</div><div class="line"><a name="l00187"></a><span class="lineno"> 187</span>  _workW, _workZ, _workIndex, &workMode, _maxIter);</div><div class="line"><a name="l00188"></a><span class="lineno"> 188</span> </div><div class="line"><a name="l00189"></a><span class="lineno"> 189</span>  <span class="keywordflow">return</span> (workMode == 1);</div><div class="line"><a name="l00190"></a><span class="lineno"> 190</span>  }</div><div class="line"><a name="l00191"></a><span class="lineno"> 191</span> </div><div class="line"><a name="l00192"></a><span class="lineno"> 192</span>  <span class="keywordtype">int</span>& maxIter() { <span class="keywordflow">return</span> _maxIter;}</div><div class="line"><a name="l00193"></a><span class="lineno"> 193</span> </div><div class="line"><a name="l00194"></a><span class="lineno"> 194</span>  T* getDual() {<span class="keywordflow">return</span> _workW;}</div><div class="line"><a name="l00195"></a><span class="lineno"> 195</span> </div><div class="line"><a name="l00196"></a><span class="lineno"> 196</span>  <span class="keyword">private</span>:</div><div class="line"><a name="l00197"></a><span class="lineno"> 197</span>  <span class="keywordtype">int</span> _rows;</div><div class="line"><a name="l00198"></a><span class="lineno"> 198</span>  <span class="keywordtype">int</span> _maxCols;</div><div class="line"><a name="l00199"></a><span class="lineno"> 199</span> </div><div class="line"><a name="l00200"></a><span class="lineno"> 200</span>  T* _workA;</div><div class="line"><a name="l00201"></a><span class="lineno"> 201</span>  T* _workW;</div><div class="line"><a name="l00202"></a><span class="lineno"> 202</span>  T* _workZ;</div><div class="line"><a name="l00203"></a><span class="lineno"> 203</span>  <span class="keywordtype">int</span>* _workIndex;</div><div class="line"><a name="l00204"></a><span class="lineno"> 204</span> </div><div class="line"><a name="l00205"></a><span class="lineno"> 205</span>  <span class="comment">// maximum iterations of NNLS</span></div><div class="line"><a name="l00206"></a><span class="lineno"> 206</span>  <span class="keywordtype">int</span> _maxIter;</div><div class="line"><a name="l00207"></a><span class="lineno"> 207</span> };</div><div class="line"><a name="l00208"></a><span class="lineno"> 208</span> <span class="preprocessor">#endif // NNLS_ACTIVESETNNLS_H_</span></div><div class="ttc" id="classActiveSetNNLS_html"><div class="ttname"><a href="classActiveSetNNLS.html">ActiveSetNNLS</a></div><div class="ttdef"><b>Definition:</b> ActiveSetNNLS.h:159</div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="dir_4945428d57d0e875e99234d97a50fad9.html">nmflibrary</a></li><li class="navelem"><a class="el" href="dir_9d477b5039e518965255ec87deca3c41.html">nnls</a></li><li class="navelem"><b>ActiveSetNNLS.h</b></li>
<li class="footer">Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.14 </li>
</ul>
</div>
</body>
</html>