Changeset 1734 for trunk/psLib/src/math/psMinimize.c
- Timestamp:
- Sep 8, 2004, 1:32:03 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psMinimize.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psMinimize.c
r1719 r1734 9 9 * @author George Gusciora, MHPCC 10 10 * 11 * @version $Revision: 1.3 4$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-09-08 06:02:23 $11 * @version $Revision: 1.35 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-09-08 23:32:03 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 15 * 16 * XXX: must follow coding name standards on local functions. 17 * 15 18 */ 16 19 17 20 /*****************************************************************************/ 18 19 21 /* INCLUDE FILES */ 20 21 22 /*****************************************************************************/ 22 23 #include <stdlib.h> … … 46 47 47 48 /*****************************************************************************/ 48 49 49 /* DEFINE STATEMENTS */ 50 51 50 /*****************************************************************************/ 51 52 52 #define MAX_LMM_ITERATIONS 100 53 53 #define MAX_MINIMIZE_ITERATIONS 100 … … 91 91 92 92 /*****************************************************************************/ 93 94 93 /* TYPE DEFINITIONS */ 95 96 94 /*****************************************************************************/ 95 97 96 typedef struct 98 97 { … … 121 120 122 121 /*****************************************************************************/ 123 124 122 /* GLOBAL VARIABLES */ 125 126 123 /*****************************************************************************/ 127 124 125 static psMinimizeChi2PowellFunc Chi2PowellFunc = NULL; 126 //static psMinimizePowellFunc PowellFunc = NULL; 127 static psVector *myValue; 128 static psVector *myError; 129 130 /*****************************************************************************/ 131 /* FILE STATIC VARIABLES */ 132 /*****************************************************************************/ 133 128 134 // None 129 135 130 136 /*****************************************************************************/ 131 132 /* FILE STATIC VARIABLES */133 134 /*****************************************************************************/135 136 // None137 138 /*****************************************************************************/139 140 137 /* FUNCTION IMPLEMENTATION - LOCAL */ 141 142 138 /*****************************************************************************/ 143 139 … … 543 539 544 540 /*****************************************************************************/ 545 546 541 /* FUNCTION IMPLEMENTATION - PUBLIC */ 547 548 542 /*****************************************************************************/ 549 543 … … 850 844 return (initialGuess); 851 845 } 846 /****************************************************************************** 847 GUS 848 849 XXX: bug report for the psMatrix covar argument. 850 *****************************************************************************/ 851 bool psMinimizeLM(psMinimization *min, 852 psImage *covar, 853 psVector *params, 854 const psVector *paramMask, 855 const psArray *coords, 856 psMinimizeLMFunc func) 857 { 858 /* 859 psVector *beta = psVectorAlloc(params->n, PS_TYPE_F32); 860 psImage *alpha = psImageAlloc(params->n, params->n, PS_TYPE_F32); 861 psVector *deriv; 862 int i; 863 int k; 864 float tmp; 865 866 tmp = func(deriv, params, coords); 867 for (k=0;k<params->n;k++) { 868 beta->data.F32[k] = 0.0; 869 for (i=0;i<params->n;i++) { 870 beta->data.F32[k]+= deriv 871 } 872 */ 873 return(false); 874 } 875 852 876 853 877 /****************************************************************************** … … 856 880 error for each data point (yErr). 857 881 858 NOTE: yErr is currently ignored.882 XXX: NOTE: yErr is currently ignored. 859 883 *****************************************************************************/ 860 884 psPolynomial1D* psVectorFitPolynomial1D(psPolynomial1D* myPoly, … … 1505 1529 1506 1530 /****************************************************************************** 1507 This routine must minimize a possibly multi-dimensional function. 1531 This routine must minimize a possibly multi-dimensional function. The 1532 function to be minimized "func" is: 1533 float func(psVector *params, psArray *coords) 1534 The "params" are the parameters of the function which are varied. The data 1535 points at which the function is varied are in the argument "coords" which is 1536 a psArray of psVectors: each vector represents a different coordinate. 1537 1538 XXX: We do not use Brent's method. 1539 1540 XXX: We do not use the 1508 1541 *****************************************************************************/ 1509 1542 bool psMinimizePowell(psMinimization *min, … … 1672 1705 return(false); 1673 1706 } 1707 1708 /****************************************************************************** 1709 This routine is to be used with the psMinimizeChi2Powell() function below. 1710 and the psMinimizePowell() function above. 1711 1712 The basic idea is calculate chi-squared for a set of params/coords/errors. 1713 This functions uses globale variables to receive the function pointer, the 1714 data values, and the data errors. 1715 *****************************************************************************/ 1716 float myPowellChi2Func(const psVector *params, 1717 const psArray *coords) 1718 { 1719 float chi2 = 0.0; 1720 float d; 1721 int i; 1722 psVector *tmp; 1723 1724 tmp = Chi2PowellFunc(params, coords); 1725 for (i=0;i<coords->n;i++) { 1726 d = (tmp->data.F32[i] - myValue->data.F32[i]) / myError->data.F32[i]; 1727 chi2+= d * d; 1728 } 1729 psFree(tmp); 1730 return(chi2); 1731 } 1732 1733 1734 /****************************************************************************** 1735 This routine must minimize the chi-squared match of a set of data points and 1736 values for a possibly multi-dimensional function. 1737 1738 The basic idea is to use the psMinimizePowell() function defined above. In 1739 order to do so, we defined above a function myPowellChi2Func() which takes 1740 the "func" function and returns chi-squared over the params/coords/values. 1741 We then use that function myPowellChi2Func() in the call to 1742 psMinimizePowell(). 1743 *****************************************************************************/ 1744 bool psMinimizeChi2Powell(psMinimization *min, 1745 psVector *params, 1746 const psVector *paramMask, 1747 const psArray *coords, 1748 const psVector *value, 1749 const psVector *error, 1750 psMinimizeChi2PowellFunc func) 1751 { 1752 myValue = (psVector *) value; 1753 myError = (psVector *) error; 1754 Chi2PowellFunc = func; 1755 1756 return(psMinimizePowell(min, params, paramMask, coords, myPowellChi2Func)); 1757 }
Note:
See TracChangeset
for help on using the changeset viewer.
