1. public double[][] sampleGibbsClassificationsIG(double[] observations, double[][] parameters) {
  2.  
  3. Random ran = new Random();
  4. double[][] observationClass = new double[observations.length][2];
  5. Double[][] probabilities = new Double[parameters.length][2];
  6. double[] IGparams = new double[2];
  7. Double constant = 0.0;
  8. double random = 0.0;
  9.  
  10.  
  11. for (int i = 0; i < observations.length; i++) {
  12.  
  13. random = ran.nextDouble();
  14. observationClass[i][0] = observations[i];
  15.  
  16. for (int k = 0; k < parameters.length; k++) {
  17.  
  18. IGparams[0] = parameters[k][0];
  19. IGparams[1] = parameters[k][1];
  20. probabilities[k][0] = (Double) (Distribution.computeIGDensityGeneral(observations[i], IGparams) * parameters[k][2]);
  21. constant += probabilities[k][0];
  22. //System.out.println("Probabilities: " + probabilities[k][0]);
  23. }
  24. //Comparator sorts the fields in descending order
  25. Arrays.sort(probabilities, new DoubleArrayComparator(0));
  26.  
  27. //Look now if the argumentum minimum over the sequence of the sum of the probabilities ist smaller than the random draw.
  28. for (int k = 0; k < parameters.length; k++) {
  29.  
  30. if (k == 0) {
  31. probabilities[k][1] = probabilities[k][0] / constant;
  32. } else {
  33. probabilities[k][1] = probabilities[k - 1][1] + probabilities[k][0]/constant;
  34. }
  35. //System.out.println("Probability: " + probabilities[k][1] + " random number: " + random);
  36. if(probabilities[k][1].compareTo((Double) random) >= 0) {
  37. observationClass[i][1] = k;
  38. break;
  39. }
  40. else continue;
  41.  
  42. }
  43.  
  44. constant = 0.0;
  45. }
  46.  
  47. return observationClass;
  48.  
  49.  
  50.  
  51. }