MathGroup Archive 2009

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

Search the Archive

Re: Re: optimization

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96584] Re: [mg96534] Re: [mg96523] optimization
  • From: Francisco Gutierrez <fgutiers2002 at yahoo.com>
  • Date: Mon, 16 Feb 2009 16:40:25 -0500 (EST)

Many thanks Bob. This is extremely useful and clear.By the way, I believe
 it is a perfect example of the reason why this list is so useful.If he cost is a little bit of noise, it is quite low with respect to the benefits.Fg
--- On Mon, 2/16/09, Bob Hanlon <hanlonr at cox.net> wrote:

From: Bob Hanlon <hanlonr at cox.net>
Subject: [mg96584] [mg96534] Re: [mg96523] optimization
To: mathgroup at smc.vnet.net
Date: Monday, February 16, 2009, 6:54 AM

A simplification

u = Array[a, {3, 2}];

MapThread[Equal, {Map[Apply[Plus, #] &, u], Table[1, {Length[u]}]}] ===

 Thread[Total /@ u == 1]

True

Another simplification

largo = Flatten[u];

MapThread[Greater, {largo, Table[0, {Length[largo]}]}] ==
 Thread[largo > 0]

True

Fix error

Flatten[Thread[Total /@ u == 1]; Thread[largo > 0]]

{a(1,1)>0,a(1,2)>0,a(2,1)>0,a(2,2)>0,a(3,1)>0,a(3,2)>0}

Note that the semi-colon suppresses all of the first expression (i.e., the 
constraints that the rows sum to 1). You intended

Join[Thread[Total /@ u == 1], Thread[largo > 0]]

Nested tables can be written as a single Table

Table[Table[a[k, i], {k, 1, 5}], {i, 1, 3}] ==
 Table[a[k, i], {i, 3}, {k, 5}]

True

You don't need to Flatten prior to using Total

Total[Flatten[u]] == Total[u, 2]

True

You have a circular definition for u (u defined in terms of u)

paso2[individuo_, centro_, m_] := Module[
  {largo, a, u},
  u = Array[a, {Length[individuo], Length[centro]}];
  largo = Flatten[u];
  NMinimize[{Total[
     Table[
      EuclideanDistance[individuo[[k]], centro[[i]]]*u[[k, i]]^m,
      {i, Length[centro]}, {k, Length[individuo]}], 2],
    Join[Thread[Total /@ u == 1], Thread[largo > 0]]}, largo]]


Bob Hanlon

---- Francisco Gutierrez <fgutiers2002 at yahoo.com> wrote:

=============
Dear Friends:I have the following optimization function:
paso2[individuo_,centro_,m_]:=Module[{largo,u=Array[u,{Length[individuo=
],Length[centro]}]},largo=Flatten[u];NMinimize[{Total[Flatten[Table[Table=
[EuclideanDistance[individuo[[k]],centro[[i]]]*u[[k,i]]^m,{k,1,Length[indiv=
iduo]}],{i,1,Length[centro]}]]], Flatten[MapThread[Equal,{Map[Apply[Plus,#]=
&,u],Table[1,{Length[u]}]}];MapThread[Greater,{largo,Table[0,{Length[largo]=
}]}]]},largo]]
in Mathematica 7.
However, this function is obviously not capturing the restriction that u[i,=
j]+u[i,k]==1For example, u[1,1]+u[1,2] should sum up to 1this restricti=
on corresponding to the following piece of code: Flatten[MapThread[Equal,{M=
ap[Apply[Plus,#]&,u],Table[1,{Length[u]}]}]
How can I solve this?In general, what I am doing wrong so as to not repeat =
the error?ThanksFrancisco Guti=E9rrez



  • Prev by Date: Re: Re: Benchmark performance Under AIX
  • Next by Date: Mathematica Training in Amsterdam
  • Previous by thread: Re: optimization
  • Next by thread: Why does Derivative fail in this case?