Re: Re: Re: Re: finding periodicity in a set
- To: mathgroup at smc.vnet.net
- Subject: [mg39361] Re: [mg39321] Re: [mg39304] Re: [mg39283] Re: finding periodicity in a set
- From: Dr Bob <drbob at bigfoot.com>
- Date: Wed, 12 Feb 2003 03:53:50 -0500 (EST)
- References: <200302110941.EAA26056@smc.vnet.net>
- Reply-to: drbob at bigfoot.com
- Sender: owner-wri-mathgroup at wolfram.com
Great work, Mihajlo! It seems always a little more accurate except when n=2, and then it gives the same answer as my method. Bobby On Tue, 11 Feb 2003 04:41:58 -0500 (EST), Mihajlo Vanevic <mvane at eunet.yu> wrote: > Here is something similar to Dr Bob's idea for small sample size... > (but more accurate, I think) > > > << Statistics`DescriptiveStatistics` > > Clear[mihajlo2]; > > mihajlo2[xlist_, dr_:0.1, error_:0.01] := > Module[ > {xxlist, gaps, ratios, rationalRatios, lcm, intRatios, xvals, linefit, a, > b}, > xxlist = Mean /@ Split[Sort[xlist], #2 - #1 < error &]; > gaps = ListConvolve[{1., -1.}, xxlist]; > ratios = gaps/Min[gaps]; > rationalRatios = Rationalize[ratios, dr]; > lcm = LCM @@ Denominator[rationalRatios]; > intRatios = rationalRatios*lcm; > xvals = FoldList[Plus, lcm, intRatios]; > linefit = Fit[Transpose[{xvals, xxlist}], {1, x}, x]; > {a, b} = CoefficientList[linefit, x]; > {Mod[a, b], b, Max[xvals]} > ]; > > test: > > xlist := 0.202 + 1.618 Table[0.001 Random[] + Random[Integer, {3, 17}], > {20}]; > TableForm[Table[{{mihajlo2[xlist]}}, {50}]] > > > and > > xlist := 0.202 + 1.618 Table[0.001 Random[] + Random[Integer, {3, 17}], > {4}]; > TableForm[Table[{{mihajlo2[xlist]}}, {50}]] > > > Mihajlo > > ************************************************************** > * At 2003-02-10, 01:07:00 * Dr Bob, drbob at bigfoot.com wrote: > ************************************************************** >> Mihajlo's method doesn't work well with small sample sizes, so I'd >> suggest this: >> >> << Statistics`DescriptiveStatistics` >> xlist = 0.202 + 1.618 Table[0.001 Random[] + Random[Integer, {3, 17}], >> {20}]; >> error = 0.5; >> xxlist = Mean /@ Split[Sort[xlist], #2 - #1 < error &]; >> Fit[xxlist, {1, x, x^2}, x]; >> {a, b, c} = CoefficientList[, x]; >> {Mod[a, b], b} >> gaps = Subtract @@@ Transpose@{Rest@xxlist, Drop[xxlist, -1]}; >> ratios = gaps/Min@gaps; >> gcd[ratios_List] := Module[{n = 2, k}, >> While[n < 10 && (k = n/GCD @@ Round[n*ratios]) � n, n++]; >> k >> ] >> b2 = Min[gaps]/gcd@ratios; >> {a2 = Mean@Mod[xxlist, b2], b2} >> >> {1.18984, 1.39711} (* Mihajlo's method with Mean in place of First *) >> {0.207753, 1.6175} (* better *) >> >> With as few as four samples, this often returns the right period, while >> the other method rarely gets it right even with 20 samples. >> >> You shouldn't make the error estimate too small --- a fourth of the >> period is about right. (But you don't know the period in advance.) A >> more complete method would adjust the error estimate after estimating >> the period, to see if the answer changes. >> >> Bobby > > > > > > > -- majort at cox-internet.com Bobby R. Treat
- References:
- Re: Re: Re: finding periodicity in a set
- From: "Mihajlo Vanevic" <mvane@eunet.yu>
- Re: Re: Re: finding periodicity in a set