[Date Index]
[Thread Index]
[Author Index]
Re: NMinimize
*To*: mathgroup at smc.vnet.net
*Subject*: [mg81775] Re: [mg81740] NMinimize
*From*: DrMajorBob <drmajorbob at bigfoot.com>
*Date*: Wed, 3 Oct 2007 02:33:30 -0400 (EDT)
*References*: <28656799.1191337430978.JavaMail.root@m35>
*Reply-to*: drmajorbob at bigfoot.com
It all depends on what the meaning of "do this" is. Without data, it's
hard to say.
Offhand, calculating Select again for every value of Di, De, and i -- when
it depends only on i -- can't be a good idea. For that, you can define
tiSelected[i_] :=
tiSelected[i] = Select[ti, i - 2880 <= #[[2]] <= i - 1 &]
or
tiSelected[i_] :=
tiSelected[i] = Pick[ti, ti[[All, 2]], x_ /; i - 2880 <= x <= i - 1]
and use tiSelected[i] in the NMinimize statement.
You can do even better, since this ALSO depends only on i:
Plus @@ ((func[15.2, Di, De, i, First@#, Last@#] &) /@
Select[ti, i - floor <= #[[2]] <= i - 1 &])
if Di and De are left in symbolic form for now. One way to do this is
Clear[di, de, func]
plus[i_] :=
plus[i] = func[15.2, di, de, i, First@#, Last@#] & /@ tiSelected[i]
(You can experiment with defining func before or after this. If before,
then don't Clear it. Evaluate plus[20001] and see what you get, each way.)
Another optimization comes from realizing that Plus@@Table is the same as
Sum and, so that
f[di_, de_] = Sum[data[[i - 20000]] - plus[i], {i, 22881, 25000}];
or -- better yet --
f[di_, de_] = Total@data[[881 ;; 3000]] - Sum[plus[i], {i, 22881, 25000}]
(double-check those limits) allows the final result to be
NMinimize[{f[di, de], 10^-8 <= di <= 10^-1,
10^-8 <= de <= 10^-1}, {di, de}]
f[di,de] will be a very large expression, so that level of optimization
may not work out... but "tiSelected" and "plus" should still be
worthwhile. In that case, defining func BEFORE plus may be best. (Or not.
Try it out.)
The functions change when ti and "data" change, of course, but not within
NMinimize. Without data I can't fully test it, but these are the kind of
"tricks" you'll need.
Bobby
On Tue, 02 Oct 2007 04:47:30 -0500, Raj <rajanikanth at gmail.com> wrote:
> hi!
> Could somebody tell me if there is a better way to do this in
> Mathematica:
>
> data = Flatten@Import["moistureAtDepth1.dat"];
> data = data[[20000 ;; 30000]];
> ti = Import["times.dat"];
> func[x_, Di_, De_, t_, t1_, t2_] :=
> (Erfc[x/Sqrt[2400 Di (t - t1)]] -
> Erfc[x/Sqrt[2400 Di (t - t2)]] +
> Erf[x/Sqrt[2400 De (t - t2) ]])
> parameters = {Di,De};
> NMinimize[ {Plus@@Table[ (data[[i-20000]] -
> Plus @@ ((func[15.2, Di, De, i, First@#, Last@#] &) /@
> Select[ti, i - 2880 <= #[[2]] <= i-1 &]))^2,{i,22881,25000}],
> 10^-8<=Di<=10^-1,10^-8<=De<=10^-1},parameters]
>
> I am interested in Optimizing the NMinimize line.
>
> Thanks,
>
> Raj
>
>
>
--
DrMajorBob at bigfoot.com
Prev by Date:
**Re: Re: Number of interval Intersections for a large number**
Next by Date:
**Re: Equivalent functionality to colorbar in Mathematica?**
Previous by thread:
**RE: NMinimize**
Next by thread:
**Re: NMinimize**
| |