Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Line graph algorithm

Line graph algorithm

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++algorithmsdata-structureshelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Miszou
    wrote on last edited by
    #1

    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! :)

    N U 2 Replies Last reply
    0
    • M Miszou

      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! :)

      N Offline
      N Offline
      Nitzan Shaked
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • M Miszou

        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! :)

        U Offline
        U Offline
        User 834161
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups