All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hex.genmodel.easy.BinaryColumnMapper Maven / Gradle / Ivy

There is a newer version: 3.46.0.5
Show newest version
package hex.genmodel.easy;

import hex.genmodel.GenModel;
import hex.genmodel.utils.MathUtils;

import java.util.HashMap;
import java.util.Map;

public class BinaryColumnMapper {

  private final GenModel _m;

  public BinaryColumnMapper(GenModel m) {
    _m = m;
  }

  public Map create() {
    String[] origNames = _m.getOrigNames();
    String[][] origDomainValues = _m.getOrigDomainValues();
    Map columnMapping = new HashMap<>(origNames.length);
    int pos = 0;
    // non-categorical
    for (int i = 0; i < _m.getOrigNumCols(); i++) {
      if (origDomainValues[i] == null) {
        columnMapping.put(origNames[i], pos);
        pos++;
      }
    }
    // categorical
    for (int i = 0; i < _m.getOrigNumCols(); i++) {
      String[] domainValues = origDomainValues[i];
      if (domainValues != null) {
        columnMapping.put(origNames[i], pos);
        pos += 1 + MathUtils.log2(domainValues.length - 1 + 1/* for NAs */);
      }
    }
    return columnMapping;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy