Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: thanks and further question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg89134] Re: thanks and further question
  • From: dh <dh at metrohm.ch>
  • Date: Mon, 26 May 2008 06:24:32 -0400 (EDT)
  • References: <g15qu8$phv$1@smc.vnet.net>


Ho Francisco,

hope that you are fully restored.

If you need the penultimate result, you must save it, e.g. like:

cur=4,pen=0;(*some suitable values*)

NestWhileList[pen=cur;cur=expr1,expr0,test]

here is an example:

cur=4;pen=0;

NestWhileList[(pen=cur;cur=#/2)&,4,Abs[#-penold]>10^-2&]

hope this helps, Daniel



Francisco Gutierrez wrote:

> Many thanks (with a time lag, due to a terrible flu) to Daniel, Szabolcs, and the other friends who offered me solutions.

>    

>   My problems is that I want something like a NestWhileList which compares the penultimate and the last results until they are very near. I want this because full convergence is not guaranteed.

>    

>   I think I'd rather show all my code, with the risk of cluttering this message. This is a clustering code, so it implies having a list of centers and a dataset.

>    

>   First two auxiliary functions:

>    

>   losmus[punto_,prototipo_,centro_]:=Module[{alfin=Map[Total,Table[(punto-prototipo[[i]])^2,{i,1,Length[punto]}]]},Total[Table[alfin[[centro]]/alfin[[i]],{i,1,Length[alfin]}]]^-1 //N]

>    

>   update[dataset_,primeros_]:=Map[Total,Transpose[Table[(dataset[[i]]*primeros[[i]]^2),{i,1,Length[dataset]}]]]/Total[Table[primeros[[i]]^2,{i,1,Length[primeros]}]]

>    

>   Then the main function, which finds centers and level of belonging of each point:

>    

>   veamos[dataset_,prototipos_]:=Module[{centros=Range[Length[prototipos]], musitos},musitos=Table[Table[losmus[dataset[[i]], prototipos,centros[[j]]], {i,1, Length[dataset]}],{j,1,Length[centros]}]; Table[update[dataset, musitos[[i]]],{i,1,Length[musitos]}]]

>    

>   And then this, which works well with the majority of examples, but which clearly might not work:

>    

>   FixedPointList[veamos[dataset,#] &,prototipos, 10]

>    

>   So, as said above, what I want is to create a criterion that makes the function stop whenever the difference between the last two centers is less than, say, 0.01 (using, for example, an Euclidean distance or in general any type of distance).

>    

>   Thanks

>   Francisco

>    

>    

> 





-- 



Daniel Huber

Metrohm Ltd.

Oberdorfstr. 68

CH-9100 Herisau

Tel. +41 71 353 8585, Fax +41 71 353 8907

E-Mail:<mailto:dh at metrohm.com>

Internet:<http://www.metrohm.com>




  • Prev by Date: Re: Re: Re: Range of Use of Mathematica
  • Next by Date: Re: Re: Range of Use of Mathematica
  • Previous by thread: thanks and further question
  • Next by thread: message: can' find notebook, but it does...