[mlpack-git] [mlpack/mlpack] Random projection trees (#726)

Ryan Curtin notifications at github.com
Fri Aug 5 10:08:05 EDT 2016


> +
> +  return true;
> +}
> +
> +template<typename BoundType, typename MatType>
> +void RPTreeMaxSplit<BoundType, MatType>::GetRandomDirection(
> +    arma::Col<ElemType>& direction)
> +{
> +  arma::Col<ElemType> origin;
> +
> +  origin.zeros(direction.n_rows);
> +
> +  for (size_t k = 0; k < direction.n_rows; k++)
> +    direction[k] = math::Random(-1.0, 1.0);
> +
> +  ElemType length = metric::EuclideanDistance::Evaluate(origin, direction);

I think you could simplify this:

```
direction.randu(); // Fill with [0, 1].
direction -= 0.5; // Shift to [-0.5, 0.5].
const double norm = arma::norm(direction); // Get length for normalization.
if (norm == 0)
{
  const size_t k = math::RandInt(direction.n_rows);
  direction[k] = 1.0;
  length = 1.0;
}

// Normalize.
direction /= length;
```

---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/mlpack/mlpack/pull/726/files/e14a26f3e209af0608cb61ecaa5e30f253e72e9b#r73697623
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.cc.gatech.edu/pipermail/mlpack-git/attachments/20160805/8d0ef4f6/attachment.html>


More information about the mlpack-git mailing list