MathGroup Archive 2011

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

Search the Archive

Re: Filtering data from numerical minimization

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116925] Re: Filtering data from numerical minimization
  • From: Sebastian Hofer <sebhofer at gmail.com>
  • Date: Fri, 4 Mar 2011 03:41:54 -0500 (EST)

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!


  • Prev by Date: evaluation-- one or many levels, your thoughts?
  • Next by Date: Re: Vector Runge-Kutta ODE solver with compilation?
  • Previous by thread: Re: Filtering data from numerical minimization
  • Next by thread: problem to define a complex quantity