Tuesday, 27 August 2013

Replace values located close to themselves with the mean value

Replace values located close to themselves with the mean value

I'm not sure if SO is the proper place for asking this, if it's not, I
will remove the question and try it in some other place. Said that I'm
trying to do the following:

I have a List<double> and want to replace the block of values whose values
are situated very close (say 0.75 in this example) to a single value,
representing the mean of the replaced values. The values that are
isolated, or alone, should not be modified. Also the replaced block can't
be longer than 5.
Computing the mean value for each interval from 0, 5, 10.. would not
provide the expected results.
It happened many times that LINQ power surprised me gladly and I would be
happy if someone could guide me in the creation of this little method.
What I've thought is to first find the closest values for each one,
calculate the distance, if the distance is less than minimum (0.75 in this
example) then assign those values to the same block.
When all values are assigned to their blocks run a second loop that
replaces each block (with one value, or many values) to its mean.
The problem that I have in this approach is to assign the "block": if
several values are together, I need to check if the evaluating value is
contained in another block, and if it so, the new value should be in that
block too. I don't know if this is the right way of doing this or I'm over
complicating it.
Thanks for reading, and any help is appreciated.

No comments:

Post a Comment