javamathlinearization

Mathematical equation to linearize numerical sequence


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.

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.


Solution

  • 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