Esempio n. 1
0
 /**
  * Given a two d array of doubles, create a table.
  *
  * @param data
  * @return
  */
 public static ExampleTable getTable(
     double[][] data,
     String[] inputNames,
     String[] outputNames,
     int[] inputs,
     int[] outputs,
     int count) {
   Column[] cols = new Column[data.length];
   int index = 0;
   for (int i = 0; i < inputs.length; i++, index++) {
     if (data.length != count) {
       double[] tmp = new double[count];
       System.arraycopy(data[index], 0, tmp, 0, count);
       data[index] = tmp;
     }
     cols[index] = new DoubleColumn(data[index]);
     cols[index].setLabel(inputNames[i]);
   }
   for (int i = 0; i < outputs.length; i++, index++) {
     if (data.length != count) {
       double[] tmp = new double[count];
       System.arraycopy(data[index], 0, tmp, 0, count);
       data[index] = tmp;
     }
     cols[index] = new DoubleColumn(data[index]);
     cols[index].setLabel(outputNames[i]);
   }
   MutableTable mt = new MutableTableImpl(cols);
   ExampleTable et = mt.toExampleTable();
   et.setInputFeatures(inputs);
   et.setOutputFeatures(outputs);
   return et;
 }
  /** ************************************************************************** */
  private void insertIndirectionAndPrediction(boolean isPrediction, int position) {

    int[] newIndirection = new int[indirection.length + 1];
    boolean[] newPrediction = new boolean[newIndirection.length];

    for (int i = 0; i < position; i++) {
      newIndirection[i] = indirection[i];
      newPrediction[i] = prediction[i];
    }

    if (isPrediction) {
      if (newTableHackVariable) newIndirection[position] = 0;
      else newIndirection[position] = predictionColumnsTable.getNumColumns();
    } else newIndirection[position] = original.getNumColumns();

    newPrediction[position] = isPrediction;

    for (int i = position + 1; i < newIndirection.length; i++) {
      newIndirection[i] = indirection[i - 1];
      newPrediction[i] = prediction[i - 1];
    }

    indirection = newIndirection;
    prediction = newPrediction;

    // also might need to modify predictionSet
    if (isPrediction) {

      int[] newPredictionSet = new int[predictionSet.length + 1];
      for (int i = 0; i < predictionSet.length; i++) newPredictionSet[i] = predictionSet[i];
      newPredictionSet[predictionSet.length] = getNumColumns();

      predictionSet = newPredictionSet;
    }

    for (int i = 0; i < predictionSet.length; i++)
      if (predictionSet[i] > position) predictionSet[i]++;

    // Arrays.sort(predictionSet);

  }
  /*
  	does it
  */
  public void doit() throws Exception {

    ParameterPoint pp = (ParameterPoint) pullInput(0);
    ExampleTable varET = (ExampleTable) pullInput(1);

    ParameterSpace ps = (new VariogramParamSpace()).getDefaultSpace();
    // not including the last param, PowerExponent
    int numParams = 9;

    // whether the parameter at index i is
    // coefficient (true) vs range (false)
    boolean[] cvr = new boolean[numParams];
    cvr[0] = true;
    cvr[1] = true;
    cvr[2] = false;
    cvr[3] = true;
    cvr[4] = false;
    cvr[5] = true;
    cvr[6] = false;
    cvr[7] = true;
    cvr[8] = true;

    double[] range = TableUtilities.getMinMax(varET, varET.getInputFeatures()[0]);
    double rMax = range[1];

    range = TableUtilities.getMinMax(varET, varET.getOutputFeatures()[0]);
    double cMax = range[1];
    if (debug) {
      System.out.println(this.getAlias() + ": Range Max:" + rMax + ", Coefficient Max:" + cMax);
    }

    double val = Double.NEGATIVE_INFINITY;
    double max = val;
    for (int i = 0; i < numParams; i++) {

      val = pp.getValue(i);

      if (cvr[i]) {
        max = cMax;
      } else {
        max = rMax;
      }

      if (Double.isNaN(val)) {
        ps.setMinValue(i, 0.0);
        ps.setMaxValue(i, max);
        ps.setResolution(i, this.allParametersResolution);
      } else {
        ps.setMinValue(i, val);
        ps.setMaxValue(i, val);
        ps.setResolution(i, 1);
      }
    }
    // the special case for the exponent
    if (Double.isNaN(val)) {
      int expIdx = 8;
      // leave the min at zero, change the max to 3
      ps.setMaxValue(expIdx, 3);
      ps.setResolution(expIdx, 30);
    }

    pushOutput(ps, 0);
  }
  LocalDBPredictionTable(DBExampleTable pet, DBDataSource dataSource, DBConnection conn) {
    super(pet, dataSource, conn);

    original = pet;

    newTableHackVariable = false;

    //    subset = pet.subset;
    num_original_columns = original.getNumColumns();

    predictionSet = new int[outputColumns.length];
    for (int j = 0; j < predictionSet.length; j++) predictionSet[j] = j + original.getNumColumns();

    // handle indirection and prediction
    indirection = new int[original.getNumColumns() + predictionSet.length];
    prediction = new boolean[indirection.length];

    for (int j = 0; j < original.getNumColumns(); j++) {
      //         indirection[j] = j;
      prediction[j] = false;
    }
    for (int j = 0; j < predictionSet.length; j++) {
      indirection[original.getNumColumns() + j] = j;
      prediction[original.getNumColumns() + j] = true;
    }

    predictionColumns = new Column[outputColumns.length];

    // this will make sure that the prediction columns are as long
    // as the redular columns and subsetted.
    int numRows = dataSource.getNumRows();

    for (int i = 0; i < outputColumns.length; i++) {
      int type = original.getColumnType(outputColumns[i]);
      switch (type) {
        case ColumnTypes.BOOLEAN:
          predictionColumns[i] = new BooleanColumn(numRows);
          predictionColumns[i].setLabel(original.getColumnLabel(outputColumns[i]) + " Predictions");
          break;
        case ColumnTypes.BYTE:
          predictionColumns[i] = new ByteColumn(numRows);
          predictionColumns[i].setLabel(original.getColumnLabel(outputColumns[i]) + " Predictions");
          break;
        case ColumnTypes.BYTE_ARRAY:
          predictionColumns[i] = new ContinuousByteArrayColumn(numRows, true);
          predictionColumns[i].setLabel(original.getColumnLabel(outputColumns[i]) + " Predictions");
          break;
        case ColumnTypes.CHAR:
          predictionColumns[i] = new CharColumn(numRows);
          predictionColumns[i].setLabel(original.getColumnLabel(outputColumns[i]) + " Predictions");
          break;
        case ColumnTypes.CHAR_ARRAY:
          predictionColumns[i] = new ContinuousCharArrayColumn(numRows, true);
          predictionColumns[i].setLabel(original.getColumnLabel(outputColumns[i]) + " Predictions");
          break;
        case ColumnTypes.DOUBLE:
          predictionColumns[i] = new DoubleColumn(numRows);
          predictionColumns[i].setLabel(original.getColumnLabel(outputColumns[i]) + " Predictions");
          break;
        case ColumnTypes.FLOAT:
          predictionColumns[i] = new FloatColumn(numRows);
          predictionColumns[i].setLabel(original.getColumnLabel(outputColumns[i]) + " Predictions");
          break;
        case ColumnTypes.INTEGER:
          predictionColumns[i] = new IntColumn(numRows);
          predictionColumns[i].setLabel(original.getColumnLabel(outputColumns[i]) + " Predictions");
          break;
        case ColumnTypes.LONG:
          predictionColumns[i] = new LongColumn(numRows);
          predictionColumns[i].setLabel(original.getColumnLabel(outputColumns[i]) + " Predictions");
          break;
        case ColumnTypes.OBJECT:
          predictionColumns[i] = new ObjectColumn(numRows);
          predictionColumns[i].setLabel(original.getColumnLabel(outputColumns[i]) + " Predictions");
          break;
        case ColumnTypes.SHORT:
          predictionColumns[i] = new ShortColumn(numRows);
          predictionColumns[i].setLabel(original.getColumnLabel(outputColumns[i]) + " Predictions");
          break;
        case ColumnTypes.STRING:
          predictionColumns[i] = new StringColumn(numRows);
          predictionColumns[i].setLabel(original.getColumnLabel(outputColumns[i]) + " Predictions");
          break;
        default:
          break;
      }
      predictionColumnsTable = new SubsetTableImpl(predictionColumns, subset);
      // (MutableTableImpl)DefaultTableFactory.getInstance().createTable(c);
    }
  }
 public int getColumnType(int position) {
   if (prediction[position]) return predictionColumnsTable.getColumnType(indirection[position]);
   else return original.getColumnType(position);
 }
 public boolean isColumnNumeric(int position) {
   if (prediction[position]) return predictionColumnsTable.isColumnNumeric(indirection[position]);
   else return original.isColumnNumeric(position);
 }
 public void setColumnIsScalar(boolean value, int position) {
   if (prediction[position])
     predictionColumnsTable.setColumnIsScalar(value, indirection[position]);
   else original.setColumnIsScalar(value, position);
 }
  public int getNumColumns() {
    if (newTableHackVariable) return original.getNumColumns();

    return (original.getNumColumns() + predictionColumnsTable.getNumColumns());
  }
 public String getColumnComment(int position) {
   if (prediction[position]) return predictionColumns[indirection[position]].getComment();
   else return original.getColumnComment(position);
 }