コード例 #1
0
 private Double[] getDataVec(List<DataRow> rows, Attribute param) {
   Double[] vect = new Double[rows.size()];
   int n = 0;
   for (DataRow row : rows) {
     vect[n] = param.getDoubleAttribute(row);
     n++;
   }
   return vect;
 }
コード例 #2
0
  @Override
  protected BufferedDataTable[] execute(BufferedDataTable[] inData, ExecutionContext exec)
      throws Exception {

    BufferedDataTable input = inData[0];

    // Get the condition attribute
    Attribute treatmentAttribute =
        new InputTableAttribute(this.treatmentAttribute.getStringValue(), input);

    // Get the library and reference condition names
    String libraryName = AbstractScreenTrafoModel.getAndValidateTreatment(reference);
    String referenceName = AbstractScreenTrafoModel.getAndValidateTreatment(library);

    // Get the parameter and make sure there all double value columns
    List<Attribute> parameters = getParameterList(input);

    // Split the columns according to groups contained in the condition column
    Map<String, List<DataRow>> groupedRows = AttributeUtils.splitRows(input, treatmentAttribute);
    List<DataRow> libraryRows = groupedRows.get(libraryName);
    List<DataRow> referenceRows = groupedRows.get(referenceName);

    int progress = parameters.size();
    BufTableUtils.updateProgress(exec, progress / 2, progress);

    // Initialize
    BufferedDataContainer container = exec.createDataContainer(new DataTableSpec(getListSpec()));
    MutualInformation mutualinfo = new MutualInformation();
    mutualinfo.set_base(logbase.getDoubleValue());
    mutualinfo.set_method(method.getStringValue());
    mutualinfo.set_axeslinking(linkaxes.getBooleanValue());

    DataCell[] cells = new DataCell[container.getTableSpec().getNumColumns()];
    int p = 0;

    // Calculate mutual information
    for (Attribute parameter : parameters) {

      Double[] x = getDataVec(libraryRows, parameter);
      Double[] y = getDataVec(referenceRows, parameter);
      mutualinfo.set_vectors(x, y);

      if (binning.getIntValue() == 0) {
        mutualinfo.set_binning();
      } else {
        mutualinfo.set_binning(binning.getIntValue());
      }
      int[] bins = mutualinfo.get_binning();

      Double[] res = mutualinfo.calculate();

      cells[0] = new StringCell(parameter.getName());
      cells[1] = new DoubleCell(res[0]);
      cells[2] = new DoubleCell(res[1]);
      cells[3] = new DoubleCell(res[2]);
      cells[4] = new IntCell(bins[0]);
      cells[5] = new IntCell(bins[1]);
      cells[6] = new DoubleCell(mutualinfo.get_logbase());
      cells[7] = new StringCell(mutualinfo.get_method());

      container.addRowToTable(new DefaultRow("row" + p, cells));

      BufTableUtils.updateProgress(exec, (progress + p++) / 2, progress);
      exec.checkCanceled();
    }

    container.close();
    return new BufferedDataTable[] {container.getTable()};
  }