/* vector pp of parameters is as follows: ** pp[0]: principal eigenvalue ** pp[1]: fraction of 1st tensor ** pp[2]: phi for 1st tensor ** pp[3]: phi for 2nd tensor */ void _tenLevmarPeledCB(double *pp, double *xx, int mm, int nn, void *_pvlData) { /* char me[]="_tenLevmarPeledCB"; */ double tenA[7], tenB[7]; int ii; tenDwiGagePvlData *pvlData; double *egrad; AIR_UNUSED(mm); pvlData = AIR_CAST(tenDwiGagePvlData *, _pvlData); /* Form the tensors using the estimated parms */ _tenPeledRotate2D(tenA, pp[0], pvlData->ten1Eval[2], pp[2]); _tenPeledRotate2D(tenB, pp[0], pvlData->ten1Eval[2], pp[3]); egrad = AIR_CAST(double *, pvlData->nten1EigenGrads->data); /* skip past b0 gradient, HEY: not general purpose */ egrad += 3; for (ii=0; ii<nn; ii++) { double argA, argB, sigA, sigB; argA = -pvlData->tec2->bValue*TEN_T3V_CONTR(tenA, egrad + 3*ii); argB = -pvlData->tec2->bValue*TEN_T3V_CONTR(tenB, egrad + 3*ii); if (pvlData->levmarUseFastExp) { sigA = airFastExp(argA); sigB = airFastExp(argB); } else { sigA = exp(argA); sigB = exp(argB); } xx[ii] = pvlData->tec2->knownB0*(pp[1]*sigA + (1-pp[1])*sigB); } return; }
int main(int argc, char *argv[]) { char *me; unsigned int ii, NN; double min, max, *out; Nrrd *nout; me = argv[0]; if (5 != argc) { usage(me); } if (3 != (sscanf(argv[2], "%u", &NN) + sscanf(argv[1], "%lf", &min) + sscanf(argv[3], "%lf", &max))) { fprintf(stderr, "%s: couldn't parse %s %s %s double uint double", me, argv[1], argv[2], argv[3]); usage(me); } nout = nrrdNew(); if (nrrdAlloc_va(nout, nrrdTypeDouble, 2, AIR_CAST(size_t, 5), AIR_CAST(size_t, NN))) { fprintf(stderr, "%s: trouble allocating:\n%s", me, biffGetDone(NRRD)); exit(1); } out = AIR_CAST(double *, nout->data); for (ii=0; ii<NN; ii++) { double xx, rr, ff, gg; xx = AIR_AFFINE(0, ii, NN-1, min, max); rr = exp(xx); ff = airFastExp(xx); gg = airExp(xx); if (rr < 0 || ff < 0 || gg < 0 || !AIR_EXISTS(rr) || !AIR_EXISTS(ff) || !AIR_EXISTS(gg)) { fprintf(stderr, "%s: problem: %f -> real %f, approx %f %f\n", me, xx, rr, ff, gg); exit(1); } out[0] = rr; out[1] = ff; out[2] = (ff-rr)/rr; out[3] = gg; out[4] = (gg-rr)/rr; out += 5; } if (nrrdSave(argv[4], nout, NULL)) { fprintf(stderr, "%s: trouble saving:\n%s", me, biffGetDone(NRRD)); exit(1); } exit(0); }
/* ** 0 1 (2) ** texp N */ int main(int argc, char *argv[]) { char *me; unsigned int ii, NN; me = argv[0]; if (2 != argc || 1 != sscanf(argv[1], "%u", &NN)) { fprintf(stderr, "%s: need one uint as argument\n", me); exit(1); } for (ii=0; ii<NN; ii++) { double xx; xx = AIR_AFFINE(0.0, airDrandMT(), 1.0, -10, 10); printf("%f %f\n", exp(xx), airFastExp(xx)); } exit(0); }