MathGroup Archive 2011

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

Search the Archive

NMinimize eats all memory b/c of unnecessary symbolic work

  • To: mathgroup at smc.vnet.net
  • Subject: [mg120720] NMinimize eats all memory b/c of unnecessary symbolic work
  • From: Daniel Jensen <jensend at iname.com>
  • Date: Sun, 7 Aug 2011 06:15:37 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

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?




  • Prev by Date: Re: Can a Locator be Made to Track a Curve?
  • Next by Date: Re: Strange behaviour of NMinimize when doing curve fitting
  • Previous by thread: Re: Mathgroup on Google Groups
  • Next by thread: Re: NMinimize eats all memory b/c of unnecessary symbolic work