Mathematical equation to linearize numerical sequence

782 views Asked by At

I am looking for a mathematical formula (or logical/java programmatic method, but preferably raw mathematical) that will take a given, unique, series of numbers and linearize them.

EG: 1,2,4,7,10 ==> 0,1,2,3,4.

  • The linearized order must represent least to greatest such that using the same example numbers {0=1,1=2,2=4,3=7,4=10}, 10,2,7,4,1 ==> 4,1,3,2,0 with the same association to original values.
  • The numbers will range from constants in the range [n,m] and there will be c numbers.
  • n and m can be any positive numbers > 0, but m>n. and m-n != c.

This is being used with java to take a string of unique IDs associated with a constructor and order them 0,1,2,3,4 so that they can be assigned into a sorted array without actually sorting and just by deriving their base number and performing error checking to avoid filling an element twice or leaving a blank space.

This is being used to provide a "best guess" as to the location of these unique numbers in an array of size n. In doing this, I hope to achieve a more robust sorting algorithm that processes in a fraction of the time since it doesn't require actually going through the array more than once (max and min being determined when the array is initially populated).

By request, additional input/output:

int n=1350,m=1500,c=5;
/**
* Note that the items in output are the results,
*respective to element, of the mathematical 
*function applied against the elements of input.
**/
int[] input = {1350,1500,1365,1450,1490};
...some f(input[x]) happens here...
int[] output= {0   ,4   ,1   ,2   ,3   };

Naturally I understand you would need substantially more than 5 elements to determine with any measure of accuracy where the item would be, but rounding in combination with a check to see if the element is null before making the copy would still be faster than sorting the entire array by comparison.

1

There are 1 answers

1
darkpbj On BEST ANSWER

I would look into a good linear regression algorithm.

This has a link to some examples, just set all of your weights equal to 1:

Weighted Linear Regression in Java

Or there's some more code here

http://introcs.cs.princeton.edu/java/97data/LinearRegression.java.html

Just plug in the independent values as x and the dependent values as y and voila!

If you have any problem interpreting the data into linear form, y=mx+b:

http://en.wikipedia.org/wiki/Simple_linear_regression