Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

model_beta.c

Go to the documentation of this file.
00001 /*****************************************************************************
00002    Major portions of this software are copyrighted by the Medical College
00003    of Wisconsin, 1994-2000, and are released under the Gnu General Public
00004    License, Version 2.  See the file README.Copyright for details.
00005 ******************************************************************************/
00006    
00007 /*
00008   This file contains routines to initialize and implement the 
00009   beta distribution function signal model.
00010 
00011   File:     model_beta.c
00012   Author:   B. Douglas Ward
00013   Date:     11 December 1997
00014 */
00015 
00016 
00017 /*---------------------------------------------------------------------------*/
00018 
00019 #include <math.h>
00020 #include "NLfit_model.h"
00021 
00022 void signal_model 
00023 (
00024   float * gs,                /* parameters for signal model */
00025   int ts_length,             /* length of time series data */
00026   float ** x_array,          /* independent variable matrix */
00027   float * ts_array           /* estimated signal model time series */  
00028 );
00029 
00030 
00031 /*---------------------------------------------------------------------------*/
00032 /*
00033   Routine to initialize the signal model by defining the number of parameters
00034   in the signal model, the name of the signal model, and the default values
00035   for the minimum and maximum parameter constraints.
00036 */
00037 
00038 DEFINE_MODEL_PROTOTYPE
00039 
00040 MODEL_interface * initialize_model ()
00041 {
00042   MODEL_interface * mi = NULL;
00043 
00044 
00045   /*----- allocate memory space for model interface -----*/
00046   mi = (MODEL_interface *) XtMalloc (sizeof(MODEL_interface));
00047 
00048 
00049   /*----- define interface for the differential - exponential model -----*/   
00050 
00051   /*----- name of this model -----*/
00052   strcpy (mi->label, "Beta");
00053 
00054   /*----- this is a signal model -----*/
00055   mi->model_type = MODEL_SIGNAL_TYPE;
00056 
00057   /*----- number of parameters in the model -----*/
00058   mi->params = 5;
00059 
00060   /*----- parameter labels -----*/
00061   strcpy (mi->plabel[0], "t0");
00062   strcpy (mi->plabel[1], "tf");
00063   strcpy (mi->plabel[2], "k");
00064   strcpy (mi->plabel[3], "alpha");
00065   strcpy (mi->plabel[4], "beta");
00066 
00067   /*----- minimum and maximum parameter constraints -----*/
00068   mi->min_constr[0] =    27.0;    mi->max_constr[0] =    77.0;
00069   mi->min_constr[1] =    78.0;    mi->max_constr[1] =   250.0;
00070   mi->min_constr[2] = -5000.0;    mi->max_constr[2] =  5000.0;
00071   mi->min_constr[3] =    0.00;    mi->max_constr[3] =    10.0;
00072   mi->min_constr[4] =    0.00;    mi->max_constr[4] =    10.0;
00073   
00074   /*----- function which implements the model -----*/
00075   mi->call_func = &signal_model;
00076 
00077 
00078   /*----- return pointer to the model interface -----*/
00079   return (mi);
00080 }
00081 
00082 
00083 /*---------------------------------------------------------------------------*/
00084 /*
00085   Routine to calculate the time series which results from using the
00086   differential exponential drug response signal model with the specified
00087   model parameters.
00088 
00089   Definition of model parameters:
00090 
00091      gs[0] = time delay of response (t0)  
00092      gs[1] = end of response (tf)
00093      gs[2] = multiplicative constant (k)
00094      gs[3] = beta distribution parameter (alpha)
00095      gs[4] = beta distribution parameter (beta)
00096 */
00097 
00098 void signal_model 
00099 (
00100   float * gs,                /* parameters for signal model */
00101   int ts_length,             /* length of time series data */
00102   float ** x_array,          /* independent variable matrix */
00103   float * ts_array           /* estimated signal model time series */  
00104 )
00105 
00106 {
00107   int it;                           /* time index */     
00108   float t;                          /* time */
00109   float fval;                       /* time series value at time t */  
00110   float x;                          /* rescaled t */
00111   float t0, tf, k, alpha, beta;     /* parameters */
00112 
00113 
00114   t0 = gs[0];
00115   tf = gs[1];
00116   k  = gs[2];
00117   alpha = gs[3];
00118   beta  = gs[4];
00119 
00120   for (it = 0;  it < ts_length;  it++)
00121     {
00122       t = x_array[it][1];
00123       if ((t <= t0) || (t >= tf) || (t0 >= tf))
00124         fval = 0.0;
00125       else
00126         {
00127           x = (t - t0) / (tf - t0);
00128           fval = k * exp((alpha-1.0)*log(x)) * exp((beta-1.0)*log(1.0-x));
00129         }
00130       ts_array[it] = fval;
00131     }
00132 }
00133   
00134 
00135 
00136 
00137 
00138 
 

Powered by Plone

This site conforms to the following standards: