       Re: Filtering data from numerical minimization

• To: mathgroup at smc.vnet.net
• Subject: [mg116879] Re: Filtering data from numerical minimization
• From: DrMajorBob <btreat1 at austin.rr.com>
• Date: Thu, 3 Mar 2011 05:57:47 -0500 (EST)

```This preserves more data points, and it's simpler:

noise = RandomReal[NormalDistribution[0, .75], m = 30];
data = Table[{x -> n, f -> n + noise[[n]]}, {n, 1, m}];
r = Reverse /@ data;
fdata = {x, f} /. LongestCommonSequence[r, Sort@r];
ListPlot@fdata

or

noise = RandomReal[NormalDistribution[0, .75], m = 30];
data = Transpose@{noise + Range@m, Range@m};
fdata = LongestCommonSequence[data, Sort@data];
ListPlot@fdata

Bobby

On Wed, 02 Mar 2011 03:37:36 -0600, Sebastian <sebhofer at gmail.com> wrote:

> Sorry for that, there is a typo in the code above. Also, I should have
> included a sample of my data. For completeness:
>
> DefineFilter[cond_, options : OptionsPattern[]] :=
>   Module[{ret},
>    ret = Switch[OptionValue[ReturnValue], "Position", True, _,
>      False];
>    Return@
>     With[{ret = ret},
>      Function[t,
>       Select[Table[
>         If[i == 1 || i == Length@t || cond[t, i],
>          If[ret, i, t[[i]]]], {i, 1, Length@t}], # =!= Null &]]];];
> Options[DefineFilter] = {ReturnValue -> "Value"};
> Attributes[DefineFilter] = {HoldAll};
>
> filter1 =
>   DefineFilter[(f /. #1[[#2 - 1]]) < (f /. #1[[#2]]) < (f /. #1[[#2 +
>           1]]) &];
>
> noise = RandomReal[NormalDistribution[0, .75], m = 30];
> data = Table[{x -> n, f -> n + %[[n]]}, {n, 1, m}];
> fdata = {x, f} /. filter1[data];
> ListPlot[fdata]
>
> I hope it works this time. Anyway, you are of course right and my code
> does drop points which could be kept, I'm aware of that. My data is
> not to big (a few hundreds of points at most) so the brute force
> method might actually be feasible. I will definitely try it out at
> some point and tell you the results. It may be a while though, as I
> have more pressing problems to work on at the moment.
>
> Best regards,
> Sebastian
>

--
DrMajorBob at yahoo.com

```

• Prev by Date: Re: Vector Runge-Kutta ODE solver with compilation?
• Next by Date: TransformedDistribution
• Previous by thread: Re: Filtering data from numerical minimization
• Next by thread: Re: Filtering data from numerical minimization