Skip to content

Commit

Permalink
Merge pull request #263 from RubixML/fix-div-by-zero
Browse files Browse the repository at this point in the history
Fix Extra Tree Divide By Zero
  • Loading branch information
andrewdalpino authored Oct 15, 2022
2 parents 6763e47 + 924f79f commit 00bc019
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Graph/Trees/ExtraTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ protected function split(Labeled $dataset) : Split
$columns = (array) array_rand($columns, min($maxFeatures, count($columns)));

$randMax = getrandmax();

$bestColumn = $bestValue = $bestGroups = null;
$bestImpurity = INF;

Expand All @@ -91,14 +92,18 @@ protected function split(Labeled $dataset) : Split
$min = min($values);
$max = max($values);

$phi = $randMax / max(abs($max), abs($min));
$maxAbs = max(abs($max), abs($min));

$phi = $maxAbs != 0.0 ? $randMax / $maxAbs : $randMax;

$min = (int) floor($min * $phi);
$max = (int) ceil($max * $phi);

$value = rand($min, $max) / $phi;
} else {
$offset = array_rand(array_unique($values));
$values = array_unique($values);

$offset = array_rand($values);

$value = $values[$offset];
}
Expand Down

0 comments on commit 00bc019

Please sign in to comment.