0

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.

user1695505
  • 265
  • 2
  • 13
  • 2
    I don't fully understand the problem. Can you add an input/output of the problem? – Luiggi Mendoza Oct 31 '12 at 05:11
  • Don't get your question, I don't think linearize is the right word here. In your example, the result seems to be just the indexes of the sorted inputs. How do you get 0 .. 4? Why not 2 .. 6 or other numbers? Are inputs and outputs integers? – Mathias Oct 31 '12 at 05:58
  • or are the 2 series your inputs, and you are trying to find a linear model connecting them? – Mathias Oct 31 '12 at 06:00
  • Mathias - Since I am given a series of random, yet unique, numbers I want a way to order them numerically beginning at 0. So in a given set of numbers {1,2,4,7,10} they would be sorted the exact same, yet the number would be "deflated" to 0,1,2,3,4 by using the known variables to manipulate the number so that 10*f(x)=4 (ofcourse it needn't be 10 TIMES f(x), just simply integrating 10 into the equation in some way). – user1695505 Oct 31 '12 at 07:09
  • 1
    You seem to want to start with an ordered set of (possibly) random integers of length _n_; let's call the sequende *S*. You sort the set, and assign to each member an index or position within the set. After this step you've created a sequence reading {0,1,2,..n-1) which we'll call *I*. Then given a different ordering of the same integers in *S*, call it *T*, you want to calculate the permutation difference between *S* and *T* and then apply that same permutation difference to *I*. Does that describe your question? – Jim Garrison Oct 31 '12 at 08:06
  • Jim, my primary objective is to avoid the sort process, that would require me reading (2n) more times. I was hoping to develop a mathematical algorithm (mathematical so that Googlers can apply to any language not JUST Java [eg: please re-open my question]) that would perform the sort process. If I am able to deflate numbers on a scale reliably then I would be able to assign values to elements corresponding to their deflated number (eg: int array[4] == 10 using my examples above). This would save me a tremendous amount of time in sorting my array. – user1695505 Nov 01 '12 at 04:24

1 Answers1

1

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

Community
  • 1
  • 1
darkpbj
  • 2,892
  • 4
  • 22
  • 32
  • This seems to be what I'm looking for. I'm reading on Linear Regression utilizing the Least Squares model now. Once I figure out how to apply it one-dimensionally that will solve the problem. I will post back with results! – user1695505 Oct 31 '12 at 05:35