SIVIC API  0.9.26
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
svk2SiteExchangeCostFunction.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2009-2016 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_EXCHANGE_COST_COST_FUNCTION_H
43 #define SVK_2_SITE_EXCHANGE_COST_COST_FUNCTION_H
44 
46 
47 
48 using namespace svk;
49 
50 
51 /*
52  * Cost function for ITK optimizer:
53  * This represents a 2 site exchange model for conversion of pyr->lactate
54  */
56 {
57 
58  public:
59 
61  itkNewMacro( Self );
62 
63 
68  {
69  // this model has 2 signals, Pyr and Lac
70  this->InitNumberOfSignals();
71  this->TR = 0;
72  }
73 
74 
78  virtual void GetKineticModel( const ParametersType& parameters ) const
79  {
80 
81  double T1all = parameters[0];
82  double Kpl = parameters[1];
83 
84  // cout << "GUESSES: " << T1all << " " << Kpl << endl;
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 time to peak pyrvaute/urea
89  int arrivalTime = GetArrivalTime( this->GetSignal(0) );
90 
91 
92  // Use fitted model params and initial concentration/intensity to calculate the lactacte intensity at
93  // each time point
94 
95  // ==============================================================
96  // DEFINE COST FUNCTION
97  // Pre arrival time and post arrival time are separate functions
98  // - Before the arrival time the pyr and lac models are just the
99  // observed input signals.
100  // - At and after the arrival time the model is:
101  // pyr(t) = pyr(arrivalTime) * e^(-kt)
102  // where k is the sum of contributions from T1 decay and convsion to lactate at rate Kpl
103  // lac(t) = lac(arrivalTime) * e^(-kt)
104  // ==============================================================
105  for ( int t = 0; t < this->numTimePoints; t++ ) {
106 
107  if (t < arrivalTime ) {
108  this->GetModelSignal(0)[t] = this->GetSignalAtTime(0, t);
109  this->GetModelSignal(1)[t] = this->GetSignalAtTime(1, t);
110  }
111 
112  if (t >= arrivalTime ) {
113 
114  // PYRUVATE
115  this->GetModelSignal(0)[t] = this->GetSignalAtTime(0, arrivalTime)
116  * exp( -((1/T1all) + Kpl) * ( t - arrivalTime) );
117 
118  // LACTATE
119  this->GetModelSignal(1)[t] = this->GetSignalAtTime(1, arrivalTime) // T1 decay of lac signal
120  * exp( -( t - arrivalTime )/T1all)
121  - this->GetSignalAtTime(0, arrivalTime )
122  * exp( -( t - arrivalTime )/T1all)
123  * ( exp( -Kpl * ( t - arrivalTime )) - 1 );
124 
125  }
126 
127  }
128 
129  }
130 
131 
136  virtual unsigned int GetNumberOfParameters(void) const
137  {
138  int numParameters = 2;
139  return numParameters;
140  }
141 
142 
146  virtual void InitNumberOfSignals(void)
147  {
148  // pyruvate and lactate
149  this->SetNumberOfSignals(2);
150  }
151 
152 
156  virtual void InitOutputDescriptionVector(vector<string>* outputDescriptionVector ) const
157  {
158  outputDescriptionVector->resize( this->GetNumberOfOutputPorts() );
159  (*outputDescriptionVector)[0] = "pyr";
160  (*outputDescriptionVector)[1] = "lac";
161  (*outputDescriptionVector)[2] = "T1all";
162  (*outputDescriptionVector)[3] = "Kpl";
163  }
164 
165 
170  virtual void InitParamBounds( float* lowerBounds, float* upperBounds )
171  {
172  upperBounds[0] = 50./this->TR; // T1all
173  lowerBounds[0] = 8. /this->TR; // T1all
174 
175  upperBounds[1] = 0.09 * this->TR; // Kpl
176  lowerBounds[1] = 0.00 * this->TR; // Kpl
177  }
178 
179 
183  virtual void InitParamInitialPosition( ParametersType* initialPosition )
184  {
185  if (this->TR == 0 ) {
186  cout << "ERROR: TR Must be set before initializing parameters" << endl;
187  exit(1);
188  }
189  (*initialPosition)[0] = 12 / this->TR; // T1all (s)
190  (*initialPosition)[1] = 0.01 * this->TR; // Kpl (1/s)
191  }
192 
193 
197  virtual void GetParamFinalScaledPosition( ParametersType* finalPosition )
198  {
199  if (this->TR == 0 ) {
200  cout << "ERROR: TR Must be set before scaling final parameters" << endl;
201  exit(1);
202  }
203  (*finalPosition)[0] *= this->TR; // T1all (s)
204  (*finalPosition)[1] /= this->TR; // Kpl (1/s)
205  }
206 
207 
208  private:
209 
213  int GetArrivalTime( float* firstSignal) const
214  {
215  int arrivalTime = 0;
216  float maxValue0 = firstSignal[0];
217  int t;
218 
219  for(t = arrivalTime; t < this->numTimePoints; t++ ) {
220  if( firstSignal[t] > maxValue0) {
221  maxValue0 = firstSignal[t];
222  arrivalTime = t;
223  }
224  }
225  //cout << "t: " << arrivalTime << " " << firstSignal[arrivalTime] << " " << this->numTimePoints<< endl;
226  return arrivalTime;
227  }
228 
229 
230 
231 };
232 
233 
234 #endif// SVK_2_SITE_EXCHANGE_COST_COST_FUNCTION_H
Definition: svkKineticModelCostFunction.h:53
svk2SiteExchangeCostFunction Self
Definition: svk2SiteExchangeCostFunction.h:60
virtual void InitParamBounds(float *lowerBounds, float *upperBounds)
Definition: svk2SiteExchangeCostFunction.h:170
virtual void InitParamInitialPosition(ParametersType *initialPosition)
Definition: svk2SiteExchangeCostFunction.h:183
virtual void GetParamFinalScaledPosition(ParametersType *finalPosition)
Definition: svk2SiteExchangeCostFunction.h:197
virtual unsigned int GetNumberOfParameters(void) const
Definition: svk2SiteExchangeCostFunction.h:136
virtual void InitOutputDescriptionVector(vector< string > *outputDescriptionVector) const
Definition: svk2SiteExchangeCostFunction.h:156
virtual void GetKineticModel(const ParametersType &parameters) const
Definition: svk2SiteExchangeCostFunction.h:78
svk2SiteExchangeCostFunction()
Definition: svk2SiteExchangeCostFunction.h:67
Superclass::ParametersType ParametersType
Definition: svkKineticModelCostFunction.h:64
Definition: svk2SiteExchangeCostFunction.h:55
virtual void InitNumberOfSignals(void)
Definition: svk2SiteExchangeCostFunction.h:146