<commit_before>package hex.coxph;

import Jama.Matrix;
import hex.*;
import hex.DataInfo.Row;
import hex.DataInfo.TransformType;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import water.*;
import water.fvec.Chunk;
import water.fvec.Frame;
import water.fvec.NewChunk;
import water.fvec.Vec;
import water.rapids.ast.prims.mungers.AstGroup;
import water.util.*;

import java.util.Arrays;

/**
 * Cox Proportional Hazards Model
 */
public class CoxPH extends ModelBuilder<CoxPHModel,CoxPHModel.CoxPHParameters,CoxPHModel.CoxPHOutput> {

  private static final int MAX_TIME_BINS = 100000;

  @Override public ModelCategory[] can_build() { return new ModelCategory[] { ModelCategory.CoxPH }; }
  @Override public BuilderVisibility builderVisibility() { return BuilderVisibility.Stable; }
  @Override public boolean isSupervised() { return true; }

  public CoxPH(boolean startup_once) {
    super(new CoxPHModel.CoxPHParameters(), startup_once);
  }

  public CoxPH( CoxPHModel.CoxPHParameters parms ) { super(parms); init(false); }
  @Override protected CoxPHDriver trainModelImpl() { return new CoxPHDriver(); }

  /** Initialize the ModelBuilder, validating all arguments and preparing the
   *  training frame.  This call is expected to be overridden in the subclasses
   *  and each subclass will start with "super.init();".  This call is made
   *  by the front-end whenever the GUI is clicked, and needs to be fast;
   *  heavy-weight prep needs to wait for the trainModel() call.
  */
  @Override public void init(boolean expensive) {
    super.init(expensive);

    if (_parms._train != null && _parms.train() == null) {
      error("train", "Invalid training frame (Frame key = " + _parms._train + " not found)");
    }

    if (_parms._train != null && _parms.train() != null) {
      if (_parms._start_column != null) {
        if (_parms.startVec().isNumeric()) {
          if (expensive) {
            try {
              CollectTimes.collect(_parms.stopVec());
            } catch (CollectTimesException e) {
              error("stop_column", e.getMessage());
            }
          }
        } else {
          error("start_column", "start time must be undefined or of type numeric");
        }
      }

      if ((_parms._stop_column != null) && ! _parms.stopVec().isNumeric())
        error("stop_column", "stop time must be of type numeric");

      if ((_parms._response_column != null) && ! _response.isInt() && (! _response.isCategorical()))
        error("response_column", "response/event column must be of type integer or factor");

      if (_parms._start_column != null && _parms._stop_column != null) {
        if (_parms.startVec().min() >= _parms.stopVec().max())<commit_msg>CoxPH: Fix validation of Stop Times<commit_after>package hex.coxph;

import Jama.Matrix;
import hex.*;
import hex.DataInfo.Row;
import hex.DataInfo.TransformType;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import water.*;
import water.fvec.Chunk;
import water.fvec.Frame;
import water.fvec.NewChunk;
import water.fvec.Vec;
import water.rapids.ast.prims.mungers.AstGroup;
import water.util.*;

import java.util.Arrays;

/**
 * Cox Proportional Hazards Model
 */
public class CoxPH extends ModelBuilder<CoxPHModel,CoxPHModel.CoxPHParameters,CoxPHModel.CoxPHOutput> {

  private static final int MAX_TIME_BINS = 100000;

  @Override public ModelCategory[] can_build() { return new ModelCategory[] { ModelCategory.CoxPH }; }
  @Override public BuilderVisibility builderVisibility() { return BuilderVisibility.Stable; }
  @Override public boolean isSupervised() { return true; }

  public CoxPH(boolean startup_once) {
    super(new CoxPHModel.CoxPHParameters(), startup_once);
  }

  public CoxPH( CoxPHModel.CoxPHParameters parms ) { super(parms); init(false); }
  @Override protected CoxPHDriver trainModelImpl() { return new CoxPHDriver(); }

  /** Initialize the ModelBuilder, validating all arguments and preparing the
   *  training frame.  This call is expected to be overridden in the subclasses
   *  and each subclass will start with "super.init();".  This call is made
   *  by the front-end whenever the GUI is clicked, and needs to be fast;
   *  heavy-weight prep needs to wait for the trainModel() call.
  */
  @Override public void init(boolean expensive) {
    super.init(expensive);

    if (_parms._train != null && _parms.train() == null) {
      error("train", "Invalid training frame (Frame key = " + _parms._train + " not found)");
    }

    if (_parms._train != null && _parms.train() != null) {
      if ((_parms._start_column != null) && (! _parms.startVec().isNumeric())) {
        error("start_column", "start time must be undefined or of type numeric");
      }

      if (_parms._stop_column != null) {
        if (! _parms.stopVec().isNumeric())
          error("stop_column", "stop time must be of type numeric");
        else
          if (expensive) {
            try {
              CollectTimes.collect(_parms.stopVec());
            } catch (CollectTimesException e) {
              error("stop_column", e.getMessage());
            }
          }
      }

      if ((_parms._response_column != null) && ! _response.isInt() && (! _response.isCategorical()))
        error("response_column", "response/event column must be of type integer or factor");

      if (_parms._start_column != null && _parms._stop_column != null) {
        if (_parms.startVec().min() >= _parms.stopVec().max())
{'fraction_non_alphanumeric': 0.1218274111675127, 'fraction_numerical': 0.002175489485134155, 'mean_word_length': 3.4672064777327933, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6335443', 'n_tokens_mistral': 1668, 'n_tokens_neox': 1605, 'n_words': 450}