Re: Filtering data from numerical minimization

• To: mathgroup at smc.vnet.net
• Subject: [mg116905] Re: Filtering data from numerical minimization
• From: DrMajorBob <btreat1 at austin.rr.com>
• Date: Fri, 4 Mar 2011 03:38:16 -0500 (EST)

```I forgot a detail in the second solution (mapping Reverse):

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

As it was, the ListPlot mapped the inverse function.

Bobby

On Thu, 03 Mar 2011 06:37:55 -0600, Sebastian Hofer <sebhofer at gmail.com>
wrote:

> On Wed, Mar 2, 2011 at 11:30 PM, DrMajorBob <btreat1 at austin.rr.com>
> wrote:
>
>> 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
>>
>
>
> This is simpler indeed and also preserves a lot more points than my
> original
> code.
> Thanks!

--
DrMajorBob at yahoo.com

```

• Prev by Date: Re: Patterns with conditions
• Next by Date: Re: Patterns with conditions
• Previous by thread: Re: Filtering data from numerical minimization
• Next by thread: Re: Filtering data from numerical minimization