Thread: normalize int data

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    normalize int data

    Hello everyone,


    I have a couple of integers, and I want to find a simple and effective way to normalize them into range [0, 1]. Any ideas and code refer?


    thanks in advance,
    George

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Not sure what you mean. If you mean map from one interval to another, then something like this:
    Code:
    int Min = //Minimum value in your interval
    int Max = //Maximum value in your interval
    int Value = //Value to normalize, maybe from traversing an array
    
    double NormalizedValue = (double)(Value - Min) / (double)(Max - Min);
    (just be sure that Max > Min)

    Using this, in the interval 1 - 5, 1 would map to 0.0, 5 would map to 1.0 and 3 would map to 0.5.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks Magos,


    I heard there is also a logarithm based normalization approach, do you know how to implement in this way?

    Quote Originally Posted by Magos View Post
    Not sure what you mean. If you mean map from one interval to another, then something like this:
    Code:
    int Min = //Minimum value in your interval
    int Max = //Maximum value in your interval
    int Value = //Value to normalize, maybe from traversing an array
    
    double NormalizedValue = (double)(Value - Min) / (double)(Max - Min);
    (just be sure that Max > Min)

    Using this, in the interval 1 - 5, 1 would map to 0.0, 5 would map to 1.0 and 3 would map to 0.5.

    regards,
    George

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  4. Converted from Dev-C++ 4 to Dev-C++ 5
    By Wraithan in forum C++ Programming
    Replies: 8
    Last Post: 12-03-2005, 07:45 AM
  5. Replies: 4
    Last Post: 11-23-2003, 07:15 AM