Changeset 2265 for trunk/psLib/src/dataManip/psMinimize.c
- Timestamp:
- Nov 1, 2004, 5:57:21 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/dataManip/psMinimize.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/dataManip/psMinimize.c
r2252 r2265 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.8 1$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-11-02 0 1:04:37$11 * @version $Revision: 1.82 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-11-02 03:57:21 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 1361 1361 min->value = func(params, coords); 1362 1362 psTrace(".psLib.dataManip.p_psLineMin", 2, 1363 "p_psLineMin() called with zero line vector. Return 0.0. Function valu sis %f\n", min->value);1363 "p_psLineMin() called with zero line vector. Return 0.0. Function value is %f\n", min->value); 1364 1364 return(0.0); 1365 1365 } … … 1469 1469 XXX: Define constants for default dummy number of iterations and tolerance. 1470 1470 1471 XXX: Must define behavior on various NULL inputs.1472 1473 1471 XXX: Check for F32 types? 1474 1472 *****************************************************************************/ 1473 #define PS_MINIMIZE_POWELL_LINEMIN_MAX_ITERATIONS 20 1474 #define PS_MINIMIZE_POWELL_LINEMIN_ERROR_TOLERANCE 0.01 1475 1475 1476 psBool psMinimizePowell(psMinimization *min, 1476 1477 psVector *params, … … 1485 1486 PS_PTR_CHECK_NULL(coords, NULL); 1486 1487 PS_PTR_CHECK_NULL(func, NULL); 1487 1488 1488 psS32 numDims = params->n; 1489 1489 PS_VECTOR_GEN_STATIC_RECYCLED(pQP, numDims, PS_TYPE_F32); … … 1492 1492 psS32 i = 0; 1493 1493 psS32 j = 0; 1494 psVector **v = NULL; 1495 psVector *myParamMask = NULL; // XXX: Use a recylced vector here. 1494 psVector *myParamMask = NULL; 1496 1495 psMinimization dummyMin; 1497 1496 float mul = 0.0; … … 1500 1499 psS32 biggestIter = 0; 1501 1500 float biggestDiff = 0.0; 1502 float term1 = 0.0;1503 float term2 = 0.0;1504 float fqp = 0.0;1505 float diff = 0.0;1506 1501 int iterationNumber = 0; 1507 1502 … … 1526 1521 1527 1522 // 1: Set v[i] to be the unit vectors for each dimension in params 1528 v = (psVector **) psAlloc(params->n * sizeof(psVector **)); 1523 1524 psArray *v = psArrayAlloc(numDims); 1529 1525 for (i=0;i<numDims;i++) { 1530 v[i] =psVectorAlloc(numDims, PS_TYPE_F32);1526 (v->data[i]) = (psVector *) psVectorAlloc(numDims, PS_TYPE_F32); 1531 1527 for (j=0;j<numDims;j++) { 1532 1528 if (i == j) { 1533 v[i]->data.F32[j] = 1.0;1529 ((psVector *) (v->data[i]))->data.F32[j] = 1.0; 1534 1530 } else { 1535 v[i]->data.F32[j] = 0.0;1531 ((psVector *) (v->data[i]))->data.F32[j] = 0.0; 1536 1532 } 1537 1533 } … … 1558 1554 "Current function value is %f\n", currFuncVal); 1559 1555 1560 diff = 0.0;1561 1556 biggestDiff = 0; 1562 1557 biggestIter = 0; 1563 1558 for (i=0;i<numDims;i++) { 1564 1559 if (myParamMask->data.U8[i] == 0) { 1565 dummyMin.maxIter = 20;1566 dummyMin.tol = 0.01;1567 mul = p_psLineMin(&dummyMin, Q, v[i], myParamMask, coords, func);1560 dummyMin.maxIter = PS_MINIMIZE_POWELL_LINEMIN_MAX_ITERATIONS; 1561 dummyMin.tol = PS_MINIMIZE_POWELL_LINEMIN_ERROR_TOLERANCE; 1562 mul = p_psLineMin(&dummyMin, Q, ((psVector *) v->data[i]), myParamMask, coords, func); 1568 1563 if (isnan(mul)) { 1569 1564 psError(__func__, "Could not perform line minimization (1).\n"); 1570 for (j=0;j<numDims;j++) {1571 psFree(v[j]);1572 }1573 1565 psFree(v); 1574 1566 return(false); … … 1608 1600 } 1609 1601 1610 mul = p_psLineMin( min, params, u, myParamMask, coords, func);1602 mul = p_psLineMin(&dummyMin, params, u, myParamMask, coords, func); 1611 1603 if (isnan(mul)) { 1612 1604 psError(__func__, "Could not perform line minimization. (2)\n"); 1613 for (i=0;i<numDims;i++) {1614 psFree(v[i]);1615 }1616 1605 psFree(v); 1617 1606 return(false); … … 1619 1608 1620 1609 // 6: 1621 if (min->value > currFuncVal) { 1622 for (i=0;i<numDims;i++) { 1623 psFree(v[i]); 1624 } 1610 if (dummyMin.value > currFuncVal) { 1625 1611 psFree(v); 1626 1612 min->iter = iterationNumber; … … 1637 1623 } 1638 1624 } 1639 fqp = func(pQP, coords); 1640 1641 term1 = (baseFuncVal - currFuncVal) - biggestDiff; 1625 float fqp = func(pQP, coords); 1626 float term1 = (baseFuncVal - currFuncVal) - biggestDiff; 1642 1627 term1*= term1; 1643 1628 term1*= 2.0 * (baseFuncVal - (2.0 * currFuncVal) + fqp); 1644 term2 = baseFuncVal - fqp;1629 float term2 = baseFuncVal - fqp; 1645 1630 term2*= term2 * biggestDiff; 1646 1631 if (term1 < term2) { 1647 1632 for (i=0;i<numDims;i++) { 1648 1633 if (myParamMask->data.U8[i] == 0) { 1649 v[biggestIter]->data.F32[i] = u->data.F32[i];1634 ((psVector *) v->data[biggestIter])->data.F32[i] = u->data.F32[i]; 1650 1635 } 1651 1636 } … … 1661 1646 // 8: Go to step 3 until the change is less than some tolerance. 1662 1647 if (fabs(baseFuncVal - currFuncVal) <= min->tol) { 1663 for (i=0;i<numDims;i++) {1664 psFree(v[i]);1665 }1666 1648 psFree(v); 1667 1649 min->iter = iterationNumber; … … 1672 1654 } 1673 1655 1674 for (i=0;i<numDims;i++) {1675 psFree(v[i]);1676 }1677 1656 psFree(v); 1678 1657 min->iter = iterationNumber;
Note:
See TracChangeset
for help on using the changeset viewer.
