MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: NMinimize eats all memory b/c of unnecessary symbolic work

  • To: mathgroup at smc.vnet.net
  • Subject: [mg120734] Re: NMinimize eats all memory b/c of unnecessary symbolic work
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Mon, 8 Aug 2011 04:19:35 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

Eliminating Subscript should help with the memory issue:

n = 8*10^8;
k = 20;
a = N@Log@Prime@Range@k;
b = Table[Symbol["b" <> StringTake["0" <> ToString@i, -2]], {i, k}];
c = Times @@ (2 b + 1);
d = Sequence @@ Thread[b >= 0];
constraints = {c > n, d};
Minimize[{a.b, constraints}, b, Integers]

I didn't wait for that to complete, assuming it ever could.

It should help, as well, to find an upper bound for the variables,  
changing "d" to

d = Sequence @@ Thread[bound > b >= 0];

I'll leave that to you.

Bobby

On Sun, 07 Aug 2011 05:15:37 -0500, Daniel Jensen <jensend at iname.com>  
wrote:

> The following code is a fairly naive way to find the least number whose
> square has n divisors (the minimum should be its log and the x_i the
> powers in its prime factorization). If I look at the case n00 and use
> ten variables instead of twenty, this uses somewhere around 600MB of
> memory. With the value of n I'm actually trying to find the answer for,
> I need around 20 variables to be sure of not missing the actual
> solution, and it quickly uses up all available memory and then thrashes
> swap.
>
> n=8*10^6;
> a = Table[N[Log[Prime[i]]], {i, 20}];
> b = Table[Subscript[x, i], {i, 20}];
> cond = Fold[And, Product[2 Subscript[x, i] + 1, {i, 20}] > n,
>     Table[Subscript[x, i] >= 0, {i, 20}]] && b \[Element] Integers;
> NMinimize[{a.b, cond}, b, MaxIterations -> 1000]
>
> It turns out that the problem isn't related to integer programming etc
> at all (removing the restriction to the integers doesn't help).
>
> My best guess is that the problem is that Mathematica is wasting all
> that memory expanding Product[2 Subscript[x, i] + 1, {i, 20}]. If I
> replace the product with just Product[Subscript[x, i],{i,20}] and change
> the constraints to be >= 1 rather than 0 I get results without a hassle
> and without the kernel using more than 50MB of memory. (Though that
> preserves the inequality constraint and doesn't change the task of
> minimizing the objective function, it does mess up the integrality
> requirement- I get even results, which correspond to half-integers in
> the actual problem.)
>
> Searching the Web, I found one person who had a somewhat similar
> problem; in their case, they had an objective function which was getting
> evaluated symbolically at a huge cost. They were able to remedy it by
> making the function only accept numeric input. I don't seem to be able
> to do that with the constraint.
>
> Any thoughts on how to fix this?
>


-- 
DrMajorBob at yahoo.com




  • Prev by Date: Problems with NETLink C#
  • Next by Date: Re: Re: Strange behaviour of NMinimize when doing curve fitting
  • Previous by thread: NMinimize eats all memory b/c of unnecessary symbolic work
  • Next by thread: Re: NMinimize eats all memory b/c of unnecessary symbolic work