Skip to content

Conversation

@santiago-imelio
Copy link
Contributor

Hello! This is work in progress but I would love to get some feedback on how this looks so far.

Specifically on the while code, not sure if I'm passing things correctly (loss_fn and min_samples are being passed as tensor shapes because otherwise they turn into Nx.Defn.Expr 0_o).

Ideally, RANSAC could take any fit-predict model as base estimator, so I'd love to hear suggestions on how to go about implementing that (could be something similar to the loss_fn pattern, but not sure).

@@ -0,0 +1,159 @@
defmodule RANSACRegression do
Copy link
Contributor

Choose a reason for hiding this comment

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

Remember to namespace the module :)

opts = NimbleOptions.validate!(opts, @opts_schema)

inliers_mask = fit_n(x, y, opts)
n_inliers = Nx.to_number(Nx.sum(inliers_mask))
Copy link
Contributor

Choose a reason for hiding this comment

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

You want to avoid Nx.to_number because it means fit then cannot be called from another defn. The best way is to write some tests calling this function directly and also from another defn.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@josevalim Hey! thanks for the suggestions. I've been looking for a way to use n_inliers without converting to number but failed to do so. Since it is a Nx.Defn.Expr, I cannot use it for indexing. Any suggestion on how to approach this? The objective is to extract from x and y the inliers, meaning the indices from inliers_mask such that the value is 1.

@josevalim
Copy link
Contributor

Specifically on the while code, not sure if I'm passing things correctly (loss_fn and min_samples are being passed as tensor shapes because otherwise they turn into Nx.Defn.Expr 0_o).

Everything that is not an option is assumed to be an expression and converted to a tensor or nx.defn.expr. But that's generally good. When it is an expression, it can be cached and optimised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants