-1

Edit, I have reformulated for more clarity (I hope): So to give some background, our app manages transactions belonging to accounts. For each account, we have detected a number of patterns composed of 3 amounts. For example:

  • Account 123456 :
  • pattern 1: (10, 200, 295 )
  • pattern 2: (200, 300, 1055
  • pattern 3: (310, 65, 200)
  • pattern n: ( x, y, z)

But what we actually want is something like (order of pattern doesn't matter BUT order inside a patter does):

  • Account 123456 :
  • pattern 1: (200, 200, 200 ) => best variance/standard deviation (= 0)
  • pattern 2: ( 310, 300, 295 ) => second best (= 7.64)
  • pattern 3: ( 10, 65, 1055) => third best (= 588.1)

Currently, we don't want to touch the detection algorithm and we are looking for a post-detection-process approach.

General Grievance
  • 4,555
  • 31
  • 31
  • 45

3 Answers3

0

Does the fact that the input is divided into three sets matter in any way? From your question I did not understand the relation.

My first instinct is to iterate through all combinations of 3, saving a variable diff with the sum of difference between the three numbers and another variable bestComb with the current best combination (minimum diff yet found). You would replace the diff and bestComb when you find a combination with lower difference.

  • Thanks so much for your time, I have reformulated the question because the first version was covering part of my reasoning and not the whole issue I am facing. – major_finley Feb 09 '17 at 04:37
0

You can try this logic approach:
1. Merge you Map keys and values in one array or any Collection.
2. Sort it as you like.
3. Go through you sorted array/Collection to find your deviation between numbers.
Example (Collection):

    Map<Integer,Integer> m = new HashMap<>();
    m.put(100, 20);
    m.put(20, 99);
    m.put(35, 40);

    ArrayList sortedArray = new ArrayList<Integer>();

    m.forEach((k,v)->{
        sortedArray.add(k);
        sortedArray.add(v);
    }); 
    // sortedArray stored all numbers
    Collections.sort(sortedArray); 

Now you can go through this collection to find need deviation.

 sortedArray.forEach(cnsmr ->{
        // some code
    });

Can you tell how you determine "expected value" for each element in sequences ??? I don't understand how you get best values without sequences of expected values. For example 7.64 for pattern 2.

Petya
  • 312
  • 2
  • 6
  • `default void forEach(Consumer super T> action)` – Jude Niroshan Feb 07 '17 at 12:06
  • The requirement is 3 numbers from each set. For the dataset, `(1000, 2000); (5000, 5); (4, 1)`, the result of your solution will yield `(5,4,1)`, but should be `(1000, 5, 4)`. – Shawn Xiong Feb 07 '17 at 12:17
  • I have not solved all the problem for him, but showed one of the areas in which it can work. How he will do it depends on his task and resources. – Petya Feb 07 '17 at 13:11
  • Thanks so much for your time, I have reformulated the question because the first version was covering part of my reasoning and not the whole issue I am facing. – major_finley Feb 09 '17 at 04:37
0

I think it's a NP problem therefore the best way is to loop through the set and explore all the combinations. If the data set will always be 3*2 (which is your example), then it will cost you 8 comparisons - not too bad.

Shawn Xiong
  • 470
  • 3
  • 14
  • Thanks so much for your time, I have reformulated the question because the first version was covering part of my reasoning and not the whole issue I am facing. Indeed your solution would work if I had a defined number of values. – major_finley Feb 09 '17 at 04:37