Byte-Welt Forum

Zurück   Byte-Welt Forum > Projekte / Projects > Swogl / JCuda / JOCL > JCuda

Antwort
 
Themen-Optionen Thema durchsuchen
Alt 12.04.2012, 08:55   #31
Unregistered starter
Gast/Guest
 
Beiträge: n/a
Standard Re: Counting entries in Excel table

Hi Marco. I tried to have a closer look to the code but i didn't do nothing (unfortunately).
  Mit Zitat antworten
Alt 12.04.2012, 20:24   #32
Marco13
Super-Moderator
 
Registriert seit: 05.08.2008
Beiträge: 1.416
Marco13 befindet sich auf einem aufstrebenden Ast
Standard Re: Counting entries in Excel table

Hello

I tried to continue, but it is still not entirely clear which combinations have to be computed. According to the example that you posted here, why is the first computation

Code:
               Healthy Sick
       C/C       3       0
       C/C       0       4
and not
Code:
               Healthy Sick
       C/C       3       4
       C/C       3       4
?

The current attempt: (It fills the "count" tables with some "dummy" data that is similar to the example that you posted, just for testing)

Java Code:
  1. public class JCudaFisherTestMain
  2. {
  3.     private static Map<String, Integer> valueToIndex;
  4.     private static Map<Integer, String> indexToValue;
  5.    
  6.     private static void initMapping()
  7.     {
  8.         valueToIndex = new LinkedHashMap<String, Integer>();
  9.         valueToIndex.put("A/A",  0);
  10.         valueToIndex.put("A/C",  1);
  11.         valueToIndex.put("A/G",  2);
  12.         valueToIndex.put("A/T",  3);
  13.         valueToIndex.put("C/A",  4);
  14.         valueToIndex.put("C/C",  5);
  15.         valueToIndex.put("C/G",  6);
  16.         valueToIndex.put("C/T",  7);
  17.         valueToIndex.put("G/A",  8);
  18.         valueToIndex.put("G/C",  9);
  19.         valueToIndex.put("G/G", 10);
  20.         valueToIndex.put("G/T", 11);
  21.         valueToIndex.put("T/A", 12);
  22.         valueToIndex.put("T/C", 13);
  23.         valueToIndex.put("T/G", 14);
  24.         valueToIndex.put("T/T", 15);
  25.         valueToIndex.put("NoCall", 16);
  26.         valueToIndex.put("-/-", 17);
  27.         valueToIndex.put("-/A", 18);
  28.         valueToIndex.put("-/C", 19);
  29.         valueToIndex.put("-/G", 20);
  30.         valueToIndex.put("-/T", 21);
  31.         valueToIndex.put("A/-", 22);
  32.         valueToIndex.put("C/-", 23);
  33.         valueToIndex.put("G/-", 24);
  34.         valueToIndex.put("T/-", 25);
  35.         indexToValue = reverse(valueToIndex);
  36.     }
  37.    
  38.  
  39.    
  40.     public static void main(String[] args) throws Exception
  41.     {
  42.         initMapping();
  43.        
  44.         SimpleTableData table = SimpleTableData.read("FirstTable.csv");
  45.         List<Integer> sickColumns = Arrays.asList(
  46.             2, 3, 13, 14, 15, 16, 17, 18,
  47.             19, 20, 21, 22, 25, 27
  48.         );
  49.         Set<Integer> set = new LinkedHashSet<Integer>();
  50.         for (int i=1; i<table.getNumCols(); i++)
  51.         {
  52.             set.add(i);
  53.         }
  54.         set.removeAll(sickColumns);
  55.         List<Integer> healthyColumns = new ArrayList<Integer>(set);
  56.  
  57.         SimpleTableData sickTable = SimpleTableData.create(table, sickColumns);        
  58.         SimpleTableData healthyTable = SimpleTableData.create(table, healthyColumns);        
  59.  
  60.         int printedRows = 5;
  61.        
  62.         System.out.println("Start of sick table");
  63.         System.out.println(sickTable.toString(printedRows));
  64.  
  65.         System.out.println("Start of healthy table");
  66.         System.out.println(healthyTable.toString(printedRows));
  67.        
  68.         int sickCount[] = createCountMatrix(sickTable);
  69.         int healthyCount[] = createCountMatrix(healthyTable);
  70.        
  71.         int numRows = table.getNumRows();
  72.         int numCols = valueToIndex.size();
  73.        
  74.         int handledRows = numRows;
  75.         int handledCols = numCols;
  76.        
  77.         boolean dummy = true;
  78.         if (dummy)
  79.         {
  80.             initDummy(healthyCount, sickCount, numCols);
  81.             handledRows = 3;
  82.             handledCols = 6;
  83.         }
  84.        
  85.         System.out.println("Start of sick count table");
  86.         System.out.println(toString2D(sickCount, numCols, printedRows));
  87.  
  88.         System.out.println("Start of healthy count table");
  89.         System.out.println(toString2D(healthyCount, numCols, printedRows));
  90.      
  91.         FisherExactTestCore f = new FisherExactTestCore(1000000);
  92.         for (int r=0; r<handledRows; r++)
  93.         {
  94.             System.out.println("Probe "+table.get(r, 0)+":");
  95.             for (int c0=0; c0<handledCols; c0++)
  96.             {
  97.               int index0 = c0+r*numCols;
  98.               int h0 = healthyCount[index0];
  99.               int s0 = sickCount[index0];
  100.              
  101.               System.out.println("At col0="+c0+" with name "+indexToValue.get(c0)+" found h0="+h0+" and s0="+s0);
  102.              
  103.               if (h0 != 0 && s0 != 0)
  104.               {
  105.                   float result = f.getTwoTailedP(h0, 0, 0, s0);
  106.                   System.out.printf("%8s %3s %3s\n", "", "H", "S");
  107.                   System.out.printf("%8s %3s %3s\n", indexToValue.get(c0), String.valueOf(h0), String.valueOf(0));
  108.                   System.out.printf("%8s %3s %3s  ", indexToValue.get(c0), String.valueOf(0), String.valueOf(s0));
  109.                   System.out.printf("result: %f (special case)\n\n", result);
  110.               }
  111.               if (h0 != 0)
  112.               {
  113.                   for (int c1=0; c1<handledCols; c1++)
  114.                   {
  115.                       int index1 = c1+r*numCols;
  116.                       int h1 = healthyCount[index1];
  117.                       int s1 = sickCount[index1];
  118.                      
  119.                       System.out.println("At col1="+c1+" with name "+indexToValue.get(c1)+" found h1="+h1+" and s1="+s1);
  120.                      
  121.                       if (s1 != 0)
  122.                       {
  123.                           float result = f.getTwoTailedP(h0, h1, s0, s1);
  124.                           System.out.printf("%8s %3s %3s\n", "", "H", "S");
  125.                           System.out.printf("%8s %3s %3s\n", indexToValue.get(c0), String.valueOf(h0), String.valueOf(s0));
  126.                           System.out.printf("%8s %3s %3s  ", indexToValue.get(c1), String.valueOf(h1), String.valueOf(s1));
  127.                           System.out.printf("result: %f\n\n", result);
  128.                       }
  129.                   }
  130.               }
  131.             }
  132.         }
  133.     }
  134.    
  135.     private static void initDummy(int h[], int s[], int numCols)
  136.     {
  137. //        AM_10001 0 0 3 0 0 0
  138. //        AM_10002 0 0 0 0 3 0
  139. //        AM_10003 0 0 1 8 0 7        
  140.  
  141.         h[0+0*numCols] = 0;
  142.         h[1+0*numCols] = 0;
  143.         h[2+0*numCols] = 3;
  144.         h[3+0*numCols] = 0;
  145.         h[4+0*numCols] = 0;
  146.         h[5+0*numCols] = 0;
  147.  
  148.         h[0+1*numCols] = 0;
  149.         h[1+1*numCols] = 0;
  150.         h[2+1*numCols] = 0;
  151.         h[3+1*numCols] = 0;
  152.         h[4+1*numCols] = 3;
  153.         h[5+1*numCols] = 0;
  154.  
  155.         h[0+2*numCols] = 0;
  156.         h[1+2*numCols] = 0;
  157.         h[2+2*numCols] = 1;
  158.         h[3+2*numCols] = 8;
  159.         h[4+2*numCols] = 0;
  160.         h[5+2*numCols] = 7;
  161.        
  162. //        AM_10001 0 0 4 0 0 0
  163. //        AM_10002 1 0 0 2 0 0
  164. //        AM_10003 0 0 3 0 5 1
  165.        
  166.         s[0+0*numCols] = 0;
  167.         s[1+0*numCols] = 0;
  168.         s[2+0*numCols] = 4;
  169.         s[3+0*numCols] = 0;
  170.         s[4+0*numCols] = 0;
  171.         s[5+0*numCols] = 0;
  172.  
  173.         s[0+1*numCols] = 1;
  174.         s[1+1*numCols] = 0;
  175.         s[2+1*numCols] = 0;
  176.         s[3+1*numCols] = 2;
  177.         s[4+1*numCols] = 0;
  178.         s[5+1*numCols] = 0;
  179.  
  180.         s[0+2*numCols] = 0;
  181.         s[1+2*numCols] = 0;
  182.         s[2+2*numCols] = 3;
  183.         s[3+2*numCols] = 0;
  184.         s[4+2*numCols] = 5;
  185.         s[5+2*numCols] = 1;
  186.     }
  187.    
  188.     private static <K, V> Map<V, K> reverse(Map<K, V> input)
  189.     {
  190.         Map<V, K> result = new LinkedHashMap<V, K>();
  191.         for (Entry<K, V> entry : input.entrySet())
  192.         {
  193.             result.put(entry.getValue(), entry.getKey());
  194.         }
  195.         return result;
  196.     }
  197.  
  198.  
  199.     private static int[] createCountMatrix(TableData tableData)
  200.     {
  201.         int result[] = new int[valueToIndex.size() * tableData.getNumRows()];
  202.         for (int r=0; r<tableData.getNumRows(); r++)
  203.         {
  204.             for (int c=0; c<tableData.getNumCols(); c++)
  205.             {
  206.                 String value = tableData.get(r, c);
  207.                 Integer index = valueToIndex.get(value);
  208.                 if (index != null)
  209.                 {
  210.                     int arrayIndex = r * valueToIndex.size() + index;
  211.                     result[arrayIndex]++;
  212.                 }
  213.             }
  214.         }
  215.         return result;
  216.     }
  217.    
  218.     public static String toString2D(int a[], int columns, int maxRows)
  219.     {
  220.         StringBuilder sb = new StringBuilder();
  221.         int row = 0;
  222.         for (int i=0; i<a.length; i++)
  223.         {
  224.             if (i>0 && i % columns == 0)
  225.             {
  226.                 sb.append("\n");
  227.                 row++;
  228.                 if (maxRows > 0 && row >= maxRows)
  229.                 {
  230.                     sb.append("...\n");
  231.                     break;
  232.                 }
  233.             }
  234.             sb.append(String.format("%4s ", String.valueOf(a[i])));
  235.         }
  236.         return sb.toString();
  237.     }
  238.    
  239. }
Marco13 ist offline   Mit Zitat antworten
Alt 12.04.2012, 20:41   #33
Marco13
Super-Moderator
 
Registriert seit: 05.08.2008
Beiträge: 1.416
Marco13 befindet sich auf einem aufstrebenden Ast
Standard Re: Counting entries in Excel table

Assuming that the "special case" should actually use the values from the 'count' tables, can you tell me whether the cases handled here are correct:
Java Code:
  1. public class JCudaFisherTestMain
  2. {
  3.     private static Map<String, Integer> valueToIndex;
  4.     private static Map<Integer, String> indexToValue;
  5.    
  6.     private static void initMapping()
  7.     {
  8.         valueToIndex = new LinkedHashMap<String, Integer>();
  9.         valueToIndex.put("A/A",  0);
  10.         valueToIndex.put("A/C",  1);
  11.         valueToIndex.put("A/G",  2);
  12.         valueToIndex.put("A/T",  3);
  13.         valueToIndex.put("C/A",  4);
  14.         valueToIndex.put("C/C",  5);
  15.         valueToIndex.put("C/G",  6);
  16.         valueToIndex.put("C/T",  7);
  17.         valueToIndex.put("G/A",  8);
  18.         valueToIndex.put("G/C",  9);
  19.         valueToIndex.put("G/G", 10);
  20.         valueToIndex.put("G/T", 11);
  21.         valueToIndex.put("T/A", 12);
  22.         valueToIndex.put("T/C", 13);
  23.         valueToIndex.put("T/G", 14);
  24.         valueToIndex.put("T/T", 15);
  25.         valueToIndex.put("NoCall", 16);
  26.         valueToIndex.put("-/-", 17);
  27.         valueToIndex.put("-/A", 18);
  28.         valueToIndex.put("-/C", 19);
  29.         valueToIndex.put("-/G", 20);
  30.         valueToIndex.put("-/T", 21);
  31.         valueToIndex.put("A/-", 22);
  32.         valueToIndex.put("C/-", 23);
  33.         valueToIndex.put("G/-", 24);
  34.         valueToIndex.put("T/-", 25);
  35.         indexToValue = reverse(valueToIndex);
  36.     }
  37.    
  38.  
  39.    
  40.     public static void main(String[] args) throws Exception
  41.     {
  42.         initMapping();
  43.        
  44.         SimpleTableData table = SimpleTableData.read("FirstTable.csv");
  45.         List<Integer> sickColumns = Arrays.asList(
  46.             2, 3, 13, 14, 15, 16, 17, 18,
  47.             19, 20, 21, 22, 25, 27
  48.         );
  49.         Set<Integer> set = new LinkedHashSet<Integer>();
  50.         for (int i=1; i<table.getNumCols(); i++)
  51.         {
  52.             set.add(i);
  53.         }
  54.         set.removeAll(sickColumns);
  55.         List<Integer> healthyColumns = new ArrayList<Integer>(set);
  56.  
  57.         SimpleTableData sickTable = SimpleTableData.create(table, sickColumns);        
  58.         SimpleTableData healthyTable = SimpleTableData.create(table, healthyColumns);        
  59.  
  60.         int printedRows = 5;
  61.        
  62.         System.out.println("Start of sick table");
  63.         System.out.println(sickTable.toString(printedRows));
  64.  
  65.         System.out.println("Start of healthy table");
  66.         System.out.println(healthyTable.toString(printedRows));
  67.        
  68.         int sickCount[] = createCountMatrix(sickTable);
  69.         int healthyCount[] = createCountMatrix(healthyTable);
  70.        
  71.         int numRows = table.getNumRows();
  72.         int numCols = valueToIndex.size();
  73.        
  74.         int handledRows = numRows;
  75.         int handledCols = numCols;
  76.        
  77.         System.out.println("Start of sick count table");
  78.         System.out.println(toString2D(sickCount, numCols, printedRows));
  79.  
  80.         System.out.println("Start of healthy count table");
  81.         System.out.println(toString2D(healthyCount, numCols, printedRows));
  82.      
  83.         int tasks[] = new int[4];
  84.         int t = 0;
  85.         for (int r=0; r<handledRows; r++)
  86.         {
  87.             for (int c0=0; c0<handledCols; c0++)
  88.             {
  89.               int index0 = c0+r*numCols;
  90.               int h0 = healthyCount[index0];
  91.               if (h0 != 0)
  92.               {
  93.                   for (int c1=0; c1<handledCols; c1++)
  94.                   {
  95.                       int index1 = c1+r*numCols;
  96.                       int s1 = sickCount[index1];
  97.                       if (s1 != 0)
  98.                       {
  99.                           int h1 = healthyCount[index1];
  100.                           int s0 = sickCount[index0];
  101.                          
  102.                           tasks[t*4+0] = h0;
  103.                           tasks[t*4+1] = h1;
  104.                           tasks[t*4+2] = s0;
  105.                           tasks[t*4+3] = s1;
  106.                           t++;
  107.                          
  108.                           if (t*4+0 >= tasks.length)
  109.                           {
  110.                               tasks = Arrays.copyOf(tasks, tasks.length*2);
  111.                           }
  112.                       }
  113.                   }
  114.               }
  115.             }
  116.         }
  117.  
  118.         FisherExactTestCore f = new FisherExactTestCore(1000000);
  119.         for (int i=0; i<t; i++)
  120.         {
  121.             int h0 = tasks[i*4+0];
  122.             int h1 = tasks[i*4+1];
  123.             int s0 = tasks[i*4+2];
  124.             int s1 = tasks[i*4+3];
  125.             float result = f.getTwoTailedP(h0, h1, s0, s1);
  126.             System.out.printf("Handle %3d %3d %3d %3d : %f\n", h0, h1, s0, s1, result);
  127.         }
  128.     }
  129.    
  130.     private static <K, V> Map<V, K> reverse(Map<K, V> input)
  131.     {
  132.         Map<V, K> result = new LinkedHashMap<V, K>();
  133.         for (Entry<K, V> entry : input.entrySet())
  134.         {
  135.             result.put(entry.getValue(), entry.getKey());
  136.         }
  137.         return result;
  138.     }
  139.  
  140.  
  141.     private static int[] createCountMatrix(TableData tableData)
  142.     {
  143.         int result[] = new int[valueToIndex.size() * tableData.getNumRows()];
  144.         for (int r=0; r<tableData.getNumRows(); r++)
  145.         {
  146.             for (int c=0; c<tableData.getNumCols(); c++)
  147.             {
  148.                 String value = tableData.get(r, c);
  149.                 Integer index = valueToIndex.get(value);
  150.                 if (index != null)
  151.                 {
  152.                     int arrayIndex = r * valueToIndex.size() + index;
  153.                     result[arrayIndex]++;
  154.                 }
  155.             }
  156.         }
  157.         return result;
  158.     }
  159.    
  160.     public static String toString2D(int a[], int columns, int maxRows)
  161.     {
  162.         StringBuilder sb = new StringBuilder();
  163.         int row = 0;
  164.         for (int i=0; i<a.length; i++)
  165.         {
  166.             if (i>0 && i % columns == 0)
  167.             {
  168.                 sb.append("\n");
  169.                 row++;
  170.                 if (maxRows > 0 && row >= maxRows)
  171.                 {
  172.                     sb.append("...\n");
  173.                     break;
  174.                 }
  175.             }
  176.             sb.append(String.format("%4s ", String.valueOf(a[i])));
  177.         }
  178.         return sb.toString();
  179.     }
  180.    
  181. }
Marco13 ist offline   Mit Zitat antworten
Alt 13.04.2012, 10:31   #34
Unregistered starter
Gast/Guest
 
Beiträge: n/a
Standard Re: Counting entries in Excel table

Hi Marco. You have right and i'm sorry for the mistake. The proper matrix is the second:

Code:
            Healthy Sick
C/C           3       4
C/C           3       4
However, in cases like this, i can provide controls (if it is possible) to prevent the calculation because the Fisher's test is not significant. I've tested both projects and seem to be exact (maybe the dummy edition looks like better).
  Mit Zitat antworten
Alt 13.04.2012, 11:19   #35
Marco13
Super-Moderator
 
Registriert seit: 05.08.2008
Beiträge: 1.416
Marco13 befindet sich auf einem aufstrebenden Ast
Standard Re: Counting entries in Excel table

OK, the last version collects all matrices (a,b,c,d) that have to be computed, but some of them are not required (e.g. those where the rows are just swapped, or the values are equal).

Assuming that the "twoTailedP" value of ALL of these would have been computed, what would you do with these values? Is it important to sort out the values that are not needed? And by the way: How large are the tables in the real application? At the moment, they are rather small, I'm not sure whether the performance can be increased so much. The most time-consuming things may (!) be reading the files, creating the "count' tables and finding the (a,b,c,d) matrices that have to be computed, and not the computation of the P-values itself. But we'll see...
Marco13 ist offline   Mit Zitat antworten
Alt 14.04.2012, 15:19   #36
Unregistered starter
Gast/Guest
 
Beiträge: n/a
Standard Re: Counting entries in Excel table

Hi Marco. Calculating the Fisher's test, i get a p-value that is the probability that determines whether or not to accept the initial hypothesis. Then the p-value must be less then alpha (the significance). Alpha is defined as 1-p (p is the p-value).
The greatness is never known in advance but depends on the microarray which is used. One type contains 1931 lines and a variable number of columns: 30 (like the table in my example), 100, 1.000 or even more depending on the experiment. One other type presents 1.000.000 rows and number of columns also this time variable. I hope this explains what you asked and thanks again Marco.
  Mit Zitat antworten
Alt 22.04.2012, 16:17   #37
Marco13
Super-Moderator
 
Registriert seit: 05.08.2008
Beiträge: 1.416
Marco13 befindet sich auf einem aufstrebenden Ast
Standard Re: Counting entries in Excel table

Just a short note: I'm rather busy at the moment, and will hardly have the chance to continue with this next week, but try to do so in the first week of May
Marco13 ist offline   Mit Zitat antworten
Alt 22.04.2012, 17:13   #38
Unregistered starter
Gast/Guest
 
Beiträge: n/a
Standard Re: Counting entries in Excel table

Ok Marco. No hurry (for now). Thanks.
  Mit Zitat antworten
Alt 30.04.2012, 20:05   #39
Marco13
Super-Moderator
 
Registriert seit: 05.08.2008
Beiträge: 1.416
Marco13 befindet sich auf einem aufstrebenden Ast
Standard Re: Counting entries in Excel table

Hello

Attached you will find a first test of a strighforward JCuda implementation. Let me know whether this goes into the right direction.

bye
Angehängte Dateien
Dateityp: zip JCudaFisherTest 2012 04 30.zip (21,4 KB, 6x aufgerufen)
Marco13 ist offline   Mit Zitat antworten
Alt 03.05.2012, 13:03   #40
Unregistered starter
Gast/Guest
 
Beiträge: n/a
Standard Re: Counting entries in Excel table

Hi Marco. I finally try this first test (after many problems) and seems ok but seems that java and CUDA spends the same time for the execution:

Code:
For  13  13  13  13 : Java : 1,000000    CUDA : 1,000000
For  13   0  13   1 : Java : 0,999997    CUDA : 0,999997
For   1  13   0  13 : Java : 0,999997    CUDA : 0,999997
For   1   0   0   1 : Java : 1,000000    CUDA : 1,000000
For  14  14  14  14 : Java : 1,000002    CUDA : 1,000002
For   2   2   2   2 : Java : 1,000000    CUDA : 1,000000
Can you please explain (in easy words) how this example works ? What are the FisherTestKernel.cu and the FisherTestKernel.ptx files (and why creates, each execution time, the ptx file) ?
Is not possible to add the Probe Set ID after each for like this:

For AM_10001 13 13 13 13 : Java : 1,000000 CUDA : 1,000000
For AM_10001 13 0 13 1 : Java : 0,999997 CUDA : 0,999997
...

Thanks.
  Mit Zitat antworten
Antwort

Lesezeichen


Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
 
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche

Forumregeln
Es ist Ihnen erlaubt, neue Themen zu verfassen.
Es ist Ihnen erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.


Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
Help~ Any example about HashMap (counting the frequency of key) lemoncmf JCuda 3 30.04.2010 04:33
Excel/OpenOffice-Tabelle in Swing nachbauen L-ectron-X Java Standard Edition (J2SE) 17 07.08.2009 22:10
Excel und PowerPoint vollenden - AddIns für L-ectron-X Byte-Welt Fundgrube 0 19.04.2008 17:49
Excel: Bedingte Formatierung für Fortgeschrittene Snape Software 2 19.12.2007 15:27
[Erledigt] Excel swerflash Java Standard Edition (J2SE) 4 23.01.2007 13:09


Alle Zeitangaben in WEZ +2. Es ist jetzt 17:56 Uhr.


Powered by vBulletin® Version 3.8.2 (Deutsch)
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.