You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hama.apache.org by "Edward J. Yoon (JIRA)" <ji...@apache.org> on 2009/10/28 05:38:00 UTC

[jira] Resolved: (HAMA-66) The determinant of a matrix

     [ https://issues.apache.org/jira/browse/HAMA-66?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Edward J. Yoon resolved HAMA-66.
--------------------------------

    Resolution: Won't Fix

This operation will be based on BSP instead of M/R.

> The determinant of a matrix
> ---------------------------
>
>                 Key: HAMA-66
>                 URL: https://issues.apache.org/jira/browse/HAMA-66
>             Project: Hama
>          Issue Type: New Feature
>          Components: matrix
>            Reporter: Edward J. Yoon
>
> This is my old map/reduce code to get the determinant of a matrix.
> Map: 
>   public void map(HStoreKey key, MapWritable value,
>       OutputCollector<Text, MapWritable> output, Reporter reporter)
>       throws IOException {
>     int r = Integer.parseInt(String.valueOf(key.getRow()));
>     checkObj.set(r, 0,  0.0);
>     double d = matrix_a.get(r, 0) * Math.pow(-1.0, r) * minor(r, 1);
>     checkObj.set(r, 0, 1.0);
>     MapWritable val = new MapWritable();
>     val.put(Constants.COLUMN, getBytesWritable(d));
>     output.collect(Constants.DETERMINANT, val);
>   }
>   private double minor(int processRow, int processColumn)
>       throws IOException {
>     double result = 0.0;
>     int i = 0;
>     if ((row - processColumn) == 0) {
>       return 1.0;
>     }
>     for (int r = 0; r < row; r++) {
>       double trans = checkObj.get(r, 0);
>       if (trans != 0.0) {
>         checkObj.set(r, 0, 0.0);
>         result += matrix_a.get(r, processColumn) * Math.pow(-1.0, i)
>             * minor(r, processColumn + 1);
>         checkObj.set(r, 0, 1.0);
>         i++;
>       }
>     }
>     return result;
>   }
> Reduce:
>   public void reduce(Text key, Iterator<MapWritable> values,
>       OutputCollector<Text, MapWritable> output, Reporter reporter)
>       throws IOException {
>     double sum = 0;
>     while (values.hasNext()) {
>       sum += getDouble(values.next().get(Constants.COLUMN));
>     }
>     MapWritable value = new MapWritable();
>     value.put(Constants.COLUMN, getBytesWritable(sum));
>     output.collect(key, value);
>   }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.