copasi API
0.1
|
00001 #ifndef COPASI_API_OBJECTIVE_FUNCTIONS 00002 #define COPASI_API_OBJECTIVE_FUNCTIONS 00003 #include "copasi_api.h" 00004 00005 /************************************************** 00006 List of available optimization functions 00007 ***************************************************/ 00008 double fit_time_course(copasi_model , tc_matrix ); 00009 double fit_input_output(copasi_model , tc_matrix ); 00010 double bimodality(copasi_model , tc_matrix ); 00011 double oscillation(copasi_model , tc_matrix ); 00012 double nonmonotonicity(copasi_model , tc_matrix ); 00013 double adaptive_response(copasi_model , tc_matrix ); 00014 double coefficient_of_variation(copasi_model , tc_matrix ); 00015 00016 /*************************************************** 00017 Data structure for storing function name and pointer 00018 ***************************************************/ 00019 typedef struct 00020 { 00021 const char * name; //name of objective function 00022 int minmax; //-1 for minimize, +1 for maximize 00023 double (*f)(copasi_model, tc_matrix); //pointer to objective function 00024 } 00025 CopasiAPIOptimizationFunctionPtr; 00026 00027 /********************************************** 00028 Add new optimization functions to this array 00029 **********************************************/ 00030 CopasiAPIOptimizationFunction 00031 CopasiAPIOptimizationFunctions[] = 00032 { 00033 {"fit time-course data", -1, &fit_time_course}, 00034 {"fit input-output data", -1, &fit_input_output}, 00035 {"bimodal", 1, &bimodality}, 00036 {"oscillation", 1, &oscillation}, 00037 {"non-monotonicity", -1, &nonmonotonicity}, 00038 {"adaptive response", -1, &adaptive_response}, 00039 {"low coefficient of variation", -1, &coefficient_of_variation}, 00040 0 00041 }; 00042 00043 /********************************************** 00044 Function definitions 00045 **********************************************/ 00046 00047 double bimodality(copasi_model model, tc_matrix input) 00048 { 00049 int bins = 100, i, j, k, i1, i2; 00050 double minval, maxval, dx, score=0.0; 00051 int hi1, hi2, lo1; 00052 tc_matrix result = simulateStochastic(model, tc_getMatrixValue(input, 0, 0), tc_getMatrixValue(input, 0, 1), tc_getMatrixValue(input, 0, 2)); 00053 tc_matrix hist; 00054 00055 hist = tc_createMatrix(100, result.cols()-1); 00056 dx = 1.0/ (double)results.rows; 00057 00058 for (j=0; j < result.cols; ++j) 00059 { 00060 minval = maxval = tc_getMatrixValue(result, j, 0); 00061 for (i=0; i < result.rows(); ++i) 00062 { 00063 if (tc_getMatrixValue(result, j, i) < minval) 00064 minval = tc_getMatrixValue(result, j, i); 00065 else 00066 if (tc_getMatrixValue(result, j, i) > maxval) 00067 maxval = tc_getMatrixValue(result, j, i); 00068 } 00069 00070 for (i=0; i < result.rows; ++i) 00071 { 00072 k = (int)(100 * (tc_getMatrixValue(result, i, j) - minval)/(maxval - minval)); 00073 tc_setMatrixValue(hist, k, j, tc_getMatrixValue(hist, k, j) + dx); 00074 } 00075 00076 //find modes 00077 //h1 and h2 are the two peaks, and lo1 is the valley between 00078 00079 hi1 = hi2 = lo1 = 0.0; 00080 for (i=0; i < result.rows; ++i) 00081 { 00082 if (tc_getMatrixValue(hist, i, j) > tc_getMatrixValue(hist, hi1, j)) 00083 hi1 = i; 00084 else 00085 if (tc_getMatrixValue(hist, i, j) > tc_getMatrixValue(hist, hi2, j)) 00086 hi2 = i; 00087 } 00088 00089 if (hi1 < hi2) 00090 { 00091 i1 = hi1; 00092 i2 = hi2; 00093 } 00094 else 00095 { 00096 i1 = hi2; 00097 i2 = hi1; 00098 } 00099 00100 lo1 = i1; 00101 00102 for (i=i1; i < i2; ++i) 00103 { 00104 if (tc_getMatrixValue(hist, i, j) < tc_getMatrixValue(hist, lo1, j)) 00105 lo1 = i; 00106 } 00107 00108 if ((tc_getMatrixValue(hist, hi1, j) - tc_getMatrixValue(hist, lo1, j)) > score) 00109 score = tc_getMatrixValue(hist, hi1, j) - tc_getMatrixValue(hist, lo1, j); 00110 } 00111 00112 tc_deleteMatrix(result); 00113 tc_deleteMatrix(hist); 00114 00115 return 0.0; 00116 } 00117 00118 double oscillation(copasi_model model, tc_matrix target) 00119 { 00120 return 0.0; 00121 } 00122 00123 double nonmonotonicity(copasi_model model, tc_matrix target) 00124 { 00125 return 0.0; 00126 } 00127 00128 double adaptive_response(copasi_model model, tc_matrix target) 00129 { 00130 return 0.0; 00131 } 00132 00133 double coefficient_of_variation(copasi_model model, tc_matrix target) 00134 { 00135 return 0.0; 00136 } 00137 00138 #endif 00139