Skip to content

Commit

Permalink
PUBDEV-8547 - print eif model into console in the long run of the alh…
Browse files Browse the repository at this point in the history
…orithm
  • Loading branch information
valenad1 committed Jan 26, 2022
1 parent 0b4c503 commit d521136
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ public void computeImpl() {
new ExtendedIsolationForestModel.ExtendedIsolationForestOutput(ExtendedIsolationForest.this));
_model.delete_and_lock(_job);
buildIsolationTreeEnsemble();
_model._output._model_summary = createModelSummaryTable();
LOG.info(_model.toString());
} finally {
if(_model != null)
_model.unlock(_job);
Expand Down Expand Up @@ -195,18 +193,26 @@ private void buildIsolationTreeEnsemble() {

boolean manualInterval = _parms._score_tree_interval > 0 && (tid +1) % _parms._score_tree_interval == 0;
boolean finalScoring = _parms._ntrees == (tid + 1);
boolean scored = false;

_model._output._scored_train[tid + 1] = new ScoreKeeper();
if (_parms._score_each_iteration || manualInterval || finalScoring || (timeToScore && _parms._score_tree_interval == 0)) {
_model._output._scored_train[tid + 1] = new ScoreKeeper();
timeLastScoreStart = System.currentTimeMillis();
ModelMetrics.MetricBuilder metricsBuilder = new ScoreExtendedIsolationForestTask(_model).doAll(_train).getMetricsBuilder();
ModelMetrics modelMetrics = metricsBuilder.makeModelMetrics(_model, _parms.train(), null, null);
_model._output._training_metrics = modelMetrics;
_model._output._scored_train[tid + 1].fillFrom(modelMetrics);
scored = true;
timeLastScoreEnd = System.currentTimeMillis();
}

final boolean printout = (_parms._score_each_iteration || finalScoring || (sinceLastScore > _parms._score_interval && scored));
if (printout) {
_model._output._model_summary = createModelSummaryTable();
_model._output._scoring_history = createScoringHistoryTable();
LOG.info(_model.toString());
}
}
_model._output._scoring_history = createScoringHistoryTable();
}
}

Expand Down Expand Up @@ -287,7 +293,7 @@ protected TwoDimTable createScoringHistoryTable() {

int rows = 0;
for (int i = 0; i < sks.length; i++) {
if (i != 0 && Double.isNaN(sks[i]._anomaly_score)) continue;
if (i != 0 && sks[i] != null && Double.isNaN(sks[i]._anomaly_score) || sks[i] == null) continue;
rows++;
}
TwoDimTable table = new TwoDimTable(
Expand All @@ -299,7 +305,7 @@ protected TwoDimTable createScoringHistoryTable() {
"");
int row = 0;
for( int i = 0; i<sks.length; i++ ) {
if (i != 0 && Double.isNaN(sks[i]._anomaly_score)) continue;
if (i != 0 && sks[i] != null && Double.isNaN(sks[i]._anomaly_score) || sks[i] == null) continue;
int col = 0;
DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
table.set(row, col++, fmt.print(_model._output._training_time_ms[i]));
Expand Down

0 comments on commit d521136

Please sign in to comment.