Line graph algorithm
-
More of an algorithm question than a C++ question, but here goes anyway: A sequence of numbers needs to be plotted as a graph on the screen. There are many more numbers than pixels available, therefore the current implementation "compresses" groups of numbers so that it can represent each group as a single pixel. eg: Assume the following trivial sequence of numbers: { 1, 2, 3, 3, 2, 1, 1, 2, 3 } Also assume that I only have 3 available pixels in which to display these values, such that: pixel 0 = { 1, 2, 3 } pixel 1 = { 3, 2, 1 } pixel 2 = { 1, 2, 3 } What is the best way to get a "best fit" of the numbers, so that the graph retains as much of its meaning as possible? As far as I see it, I can take the minimum, maximum or average values of each group, but this is not always useful. For example, given the above groupings, I will end up with a flat line graph, which is obviously not representative of the data! As I mentioned above, the software already exists to do this, but the results are not always satisfactory and are occasionally outright misleading. I really need a good algorithm that will retain as much of the "shape" of the graph as possible. Thanks for any help! :)
-
More of an algorithm question than a C++ question, but here goes anyway: A sequence of numbers needs to be plotted as a graph on the screen. There are many more numbers than pixels available, therefore the current implementation "compresses" groups of numbers so that it can represent each group as a single pixel. eg: Assume the following trivial sequence of numbers: { 1, 2, 3, 3, 2, 1, 1, 2, 3 } Also assume that I only have 3 available pixels in which to display these values, such that: pixel 0 = { 1, 2, 3 } pixel 1 = { 3, 2, 1 } pixel 2 = { 1, 2, 3 } What is the best way to get a "best fit" of the numbers, so that the graph retains as much of its meaning as possible? As far as I see it, I can take the minimum, maximum or average values of each group, but this is not always useful. For example, given the above groupings, I will end up with a flat line graph, which is obviously not representative of the data! As I mentioned above, the software already exists to do this, but the results are not always satisfactory and are occasionally outright misleading. I really need a good algorithm that will retain as much of the "shape" of the graph as possible. Thanks for any help! :)
Actually, in terms of MSE the average *is* the best option. It's an unfortunate example which you brings, but the general case favors the average. I can make another suggestion, if it's acceptable: plot *3* graphs: average, mix, and max. For each "pixel" plot in one color the min, in another the max, and in a 3rd color the average of the "group" of values which that pixel represents. That way you'll get a better feel, I believe. -- Nitzan
-
More of an algorithm question than a C++ question, but here goes anyway: A sequence of numbers needs to be plotted as a graph on the screen. There are many more numbers than pixels available, therefore the current implementation "compresses" groups of numbers so that it can represent each group as a single pixel. eg: Assume the following trivial sequence of numbers: { 1, 2, 3, 3, 2, 1, 1, 2, 3 } Also assume that I only have 3 available pixels in which to display these values, such that: pixel 0 = { 1, 2, 3 } pixel 1 = { 3, 2, 1 } pixel 2 = { 1, 2, 3 } What is the best way to get a "best fit" of the numbers, so that the graph retains as much of its meaning as possible? As far as I see it, I can take the minimum, maximum or average values of each group, but this is not always useful. For example, given the above groupings, I will end up with a flat line graph, which is obviously not representative of the data! As I mentioned above, the software already exists to do this, but the results are not always satisfactory and are occasionally outright misleading. I really need a good algorithm that will retain as much of the "shape" of the graph as possible. Thanks for any help! :)
Consider pairs of pixels. Look at the data that is mapped onto two pixels and search for minimum and maximum. Put the one that comes first into the first pixel, the other into the second pixel. This way "noisy" data will look noisy. HTH Henrik