SIVIC API  0.9.26
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
svk2SitePerfCostFunction.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2009-2014 The Regents of the University of California.
3  * All Rights Reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * • Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * • Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * • None of the names of any campus of the University of California, the name
13  * "The Regents of the University of California," or the names of any of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
26  * OF SUCH DAMAGE.
27  */
28 
29 
30 
31 /*
32  * $URL$
33  * $Rev$
34  * $Author$
35  * $Date$
36  *
37  * Authors:
38  * Jason C. Crane, Ph.D.
39  * Beck Olson,
40  */
41 
42 #ifndef SVK_2_SITE_PERF_COST_COST_FUNCTION_H
43 #define SVK_2_SITE_PERF_COST_COST_FUNCTION_H
44 
46 
47 
48 using namespace svk;
49 
50 #define ARRIVAL_TIME 1
51 
52 /*
53  * Cost function for ITK optimizer:
54  */
56 {
57 
58  public:
59 
61  itkNewMacro( Self );
62 
63 
68  {
69  this->InitNumberOfSignals();
70  this->TR = 0;
71  }
72 
73 
78  virtual void GetKineticModel( const ParametersType& parameters ) const
79  {
80 
81  double T1all = parameters[0];
82  double Kpl = parameters[1];
83  double Ktrans = parameters[2];
84 
85  // use model params and initial signal intensity to calculate the metabolite signals vs time
86  // solved met(t) = met(0)*invlaplace(phi(t)), where phi(t) = sI - x. x is the matrix of parameters.
87 
88  // Find arrival time time to peak pyrvaute/urea
89  //arrivalTime = ARRIVAL_TIME;
90  int arrivalTime = GetArrivalTime( this->GetSignal(0) );
91 
92  //set up Arterial Input function ( from 2siteex
93  //float Ao = 5000;
94  //float alpha = .2;
95  //float beta = 4.0;
96 
97  //set up Arterial Input function
98  float Ao = 1e10;
99  float alpha = .3;
100  float beta = 2.0;
101 
102  float* inputFunction = new float [numTimePoints];
103  for(int t = 0; t < numTimePoints; t++ ) {
104  inputFunction [t] = Ao * powf((t),alpha) * exp(-(t)/beta);
105  }
106 
107  //float* convolutionMat = new float [numTimePoints];
108  //convolutionMat[0] = 0;
109  //cout << "GUESSES: " << T1all << " " << Kpl << endl;
110 
111  // use fitted model params and initial concentration/intensity to calculate the lactacte intensity at
112  // each time point
113  // solved met(t) = met(0)*invlaplace(phi(t)), where phi(t) = sI - x. x is the matrix of parameters.
114 
115  // DEFINE COST FUNCTION
116  for ( int t = 0; t < numTimePoints; t++ ) {
117 
118  if (t < arrivalTime ){
119  this->GetModelSignal(0)[t] = this->GetSignalAtTime(0, t);
120  this->GetModelSignal(1)[t] = this->GetSignalAtTime(1, t);
121  }
122 
123  if (t >= arrivalTime ) {
124 
125  // PYRUVATE
126  // convolutionMat[t] = inputFunction[t]+convolutionMat[t];
127  this->GetModelSignal(0)[t] = this->GetSignalAtTime(0, arrivalTime)
128  * exp( -((T1all) + Kpl) * ( t - arrivalTime) ) + (1-exp(-Ktrans*t))*inputFunction[t];
129 
130  // LACTATE (same in both cost functions):
131  //kineticModel1[t] = signal1[arrivalTime]
132  this->GetModelSignal(1)[t] = this->GetSignalAtTime(1, arrivalTime)
133  * exp( -( t - arrivalTime )*T1all)
134  - this->GetSignalAtTime(0, arrivalTime)
135  * exp( -( t - arrivalTime )*T1all)
136  * ( exp( -Kpl * ( t - arrivalTime )) - 1 );
137 
138  }
139 
140 
141 
142  // UREA
143  // determine convolution with arterial input function
144  // convolutionMat[0] = 0;
145  // for (int tau = -(numTimePoints); tau < (numTimePoints); tau ++){
146  // convolutionMat[t] = inputFunction[tau] * exp(-Ktrans * (t-tau)/K2) + convolutionMat[t-1];
147  // }
148  // kineticModel2[t] = Ktrans * TR * convolutionMat[t];
149 
150  // convolutionMat[t] = inputFuntion[t]*(1-exp(Ktrans*t));
151  // kineticModel2[t] = 0;
152 
153  //for (int tau = 0; tau < t; tau ++){
154  this->GetModelSignal(2)[t] = inputFunction[t]; //convolutionMat[t]* kineticModel2[t];
155  // }
156  //cout << "Estimated AIF(" << t << "): " << kineticModel2[t] << endl;
157 
158  }
159 
160  }
161 
162 
168  virtual unsigned int GetNumberOfParameters(void) const
169  {
170  int numParameters = 3;
171  return numParameters;
172  }
173 
174 
178  virtual void InitNumberOfSignals(void)
179  {
180  // pyruvate,lactate and urea
181  this->SetNumberOfSignals(3);
182  }
183 
184 
185 
189  virtual void InitOutputDescriptionVector(vector<string>* outputDescriptionVector ) const
190  {
191  outputDescriptionVector->resize( this->GetNumberOfOutputPorts() );
192  (*outputDescriptionVector)[0] = "pyr";
193  (*outputDescriptionVector)[1] = "lac";
194  (*outputDescriptionVector)[2] = "urea";
195  (*outputDescriptionVector)[3] = "T1all";
196  (*outputDescriptionVector)[4] = "Kpl";
197  (*outputDescriptionVector)[5] = "Ktrans";
198  }
199 
200 
204  virtual void InitParamBounds( float* lowerBounds, float* upperBounds )
205  {
206  upperBounds[0] = 28/this->TR; // T1all
207  lowerBounds[0] = 8/this->TR; // T1all
208 
209  upperBounds[1] = .05 * this->TR; // Kpl
210  lowerBounds[1] = 0.000 * this->TR; // Kpl
211 
212  upperBounds[2] = 0 * this->TR; // ktrans
213  lowerBounds[2] = 0 * this->TR; // ktrans
214 
215  upperBounds[3] = 1; // k2
216  lowerBounds[3] = 0; // k2
217 
218  }
219 
220 
224  virtual void InitParamInitialPosition( ParametersType* initialPosition )
225  {
226  if (this->TR == 0 ) {
227  cout << "ERROR: TR Must be set before initializing parameters" << endl;
228  exit(1);
229  }
230 
231  (*initialPosition)[0] = (1./35) / this->TR; // T1all (s)
232  (*initialPosition)[1] = 0.01 * this->TR; // Kpl (1/s)
233  (*initialPosition)[2] = 1 * this->TR; // ktrans (1/s)
234  (*initialPosition)[3] = (1./40) * this->TR; // k2 (1/s)
235  }
236 
237 
241  virtual void GetParamFinalScaledPosition( ParametersType* finalPosition )
242  {
243  if (this->TR == 0 ) {
244  cout << "ERROR: TR Must be set before scaling final parameters" << endl;
245  exit(1);
246  }
247 
248  (*finalPosition)[0] *= this->TR; // T1all (s)
249  (*finalPosition)[1] /= this->TR; // Kpl (1/s)
250  (*finalPosition)[2] /= this->TR; // ktrans (1/s)
251  (*finalPosition)[2] /= this->TR; // k2 (1/s)
252  }
253 
254 
255  private:
256 
260  int GetArrivalTime( float* firstSignal ) const
261  {
262  int arrivalTime = 0;
263  float maxValue0 = firstSignal[0];
264  int t;
265  for(t = arrivalTime; t < this->numTimePoints; t++ ) {
266  if( firstSignal[t] > maxValue0) {
267  maxValue0 = firstSignal[t];
268  arrivalTime = t;
269  }
270  }
271  //cout << "t: " << arrivalTime << " " << firstSignal[arrivalTime] << " " << numPts << endl;
272  return arrivalTime;
273  }
274 
275 
276 
277 };
278 
279 
280 
281 #endif// SVK_2_SITE_PERF_COST_COST_FUNCTION_H
Definition: svkKineticModelCostFunction.h:53
virtual unsigned int GetNumberOfParameters(void) const
Definition: svk2SitePerfCostFunction.h:168
virtual void InitNumberOfSignals(void)
Definition: svk2SitePerfCostFunction.h:178
virtual void GetKineticModel(const ParametersType &parameters) const
Definition: svk2SitePerfCostFunction.h:78
svk2SitePerfCostFunction Self
Definition: svk2SitePerfCostFunction.h:60
svk2SitePerfCostFunction()
Definition: svk2SitePerfCostFunction.h:67
virtual void InitParamInitialPosition(ParametersType *initialPosition)
Definition: svk2SitePerfCostFunction.h:224
virtual void InitParamBounds(float *lowerBounds, float *upperBounds)
Definition: svk2SitePerfCostFunction.h:204
Definition: svk2SitePerfCostFunction.h:55
virtual void GetParamFinalScaledPosition(ParametersType *finalPosition)
Definition: svk2SitePerfCostFunction.h:241
Superclass::ParametersType ParametersType
Definition: svkKineticModelCostFunction.h:64
virtual void InitOutputDescriptionVector(vector< string > *outputDescriptionVector) const
Definition: svk2SitePerfCostFunction.h:189