Skip to content

Conversation

@rcurtin
Copy link
Member

@rcurtin rcurtin commented Jan 31, 2024

I went through and documented all the functions in core/math/. The result is this updated core.md page where all examples are tested:

https://www.ratml.org/misc/mlpack-markdown-doc/core.html

There were quite a number of changes I made here, and many things are removed:

  • ClampNonNegative(), ClampNonPositive(), and ClampRange() are removed, preferring instead std::max() and std::min(). That code dates back to ~2007 or so, and the code claimed empirical improvements. I couldn't reproduce any of them, and these implementations were generally noticeably slower than, say, std::max(lo, std::min(x, hi)).

  • RemoveRows() can be expressed as a simple call to .rows() in a matrix, so I removed that. I had to refactor LocalCoordinateCoding and SparseCoding to track the active atoms instead of the inactive atoms as a result; basically, RemoveRows() let you give a vector of row indexes to remove, and .rows() requires the rows you want to keep. So I had to "invert" what we were keeping track of.

  • VectorPower() was never used anywhere, so I removed it. (I forget what used it years ago.)

  • Center() is so simple that I just inlined its implementation.

  • WhitenUsingSVD(), Orthogonalize(), Svec(), SvecIndex(), SymKronId(), and Sign() weren't used anywhere, so I removed them. I believe a couple of those are used in ensmallen and are in that codebase now.

  • ObtainDistinctSamples() can be replaced with arma::randperm() and so it is now removed.

I also made a couple small bugfixes:

  • Loading grayscale images had a bug; STB will return the actual number of channels in the image even if loading was done in grayscale, and in that case we shouldn't set info.Channels(). See the STB documentation.

  • ColumnsToBlocks had a minor offset calculation bug when the margin size is greater than 1 pixel. Easy fix.

Lastly, I chose not to document MakeAlias() at this time, because there is the outstanding issue of how it should be refactored, since there is another implementation (slightly different) of the same function in src/mlpack/methods/ann/.

Whatever empirical improvements were seen in 2007 aren't seen today; a simpler
implementation with std::max() and std::min() appears to always outperform by
a relatively small margin.  So, prefer the less-maintenance approach instead,
and depend on the standard library.
Copy link
Member

@shrit shrit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good, we should merge this as soon as possible.

Three minor observations:

  1. In this PR I can see load.md and index.md files but I remember that I have reviewed these previously, also if not I did not find the link in here.
  2. We have the Mahalanobis distance, but it is not here, maybe not yet ?
    Screenshot 2024-02-06 at 13-22-57 https __www ratml org
  3. For the RBF kernel I did not know we could just compute it based on the distance, does this mean that it will work on any arbitrary distance or do we need to have the point vectors already declared, if this is the case we should mention that these are related.
    Screenshot 2024-02-06 at 13-40-47 https __www ratml org

Comment on lines 117 to 121
for (size_t j = 0; j < atoms; ++j)
{
if (arma::accu(codes.row(j) != 0) == 0)
inactiveAtoms.push_back(j);
if (arma::any(codes.row(j) != 0))
activeAtoms.push_back((arma::uword) j);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just define j as arma::uword instead of casting it later, but eventually it should be the same

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, that's easier; done in 9b8a4ec. 👍

Copy link

@mlpack-bot mlpack-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second approval provided automatically after 24 hours. 👍

@rcurtin
Copy link
Member Author

rcurtin commented Feb 21, 2024

Everything looks good, we should merge this as soon as possible.

Ha, then life happened to me... 😄

Three minor observations:

  1. In this PR I can see load.md and index.md files but I remember that I have reviewed these previously, also if not I did not find the link in here.

Those were actually part of #3603, which should be merged very shortly.

  1. We have the Mahalanobis distance, but it is not here, maybe not yet ?

Yep, this class was actually documented as part of #3603, and in this PR I only took care of core/math/ (not yet core/metrics/), so MahalanobisDistance will be added, just haven't done it yet.

  1. For the RBF kernel I did not know we could just compute it based on the distance, does this mean that it will work on any arbitrary distance or do we need to have the point vectors already declared, if this is the case we should mention that these are related.

Hm, I thought maybe this was already clear enough given how it's written---you can call Evaluate(3.0) and it will give a result, no need to even know about the points. Maybe the example that's already there demonstrates this well enough?

// Evaluate the kernel value when the distance between two points is already
// computed.
const double distance = 1.5;
const double k3 = g.Evaluate(distance);

@rcurtin
Copy link
Member Author

rcurtin commented Feb 21, 2024

I'll merge this one too once the build passes. Thanks for the review @shrit, sorry it took me so long to get back to 😄

@rcurtin rcurtin merged commit 23dc135 into mlpack:master Feb 23, 2024
@rcurtin rcurtin deleted the core-docs branch February 23, 2024 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants