Skip to content

Commit

Permalink
Move special preprocess to MDS
Browse files Browse the repository at this point in the history
  • Loading branch information
msluszniak committed Nov 9, 2023
1 parent 00bc689 commit 9d514b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
18 changes: 0 additions & 18 deletions lib/scholar/linear/isotonic_regression.ex
Original file line number Diff line number Diff line change
Expand Up @@ -309,24 +309,6 @@ defmodule Scholar.Linear.IsotonicRegression do
}
end

@doc """
Preprocesses the `model` for prediction.
Returns an updated `model`. This is a special version of `preprocess/1` that
does not trim duplicates so it can be used in defns. It is not recommended
to use this function directly.
"""
defn special_preprocess(model) do
%__MODULE__{
model
| preprocess:
Scholar.Interpolation.Linear.fit(
model.x_thresholds,
model.y_thresholds
)
}
end

deftransform check_preprocess(model) do
if model.preprocess == {} do
raise ArgumentError,
Expand Down
13 changes: 12 additions & 1 deletion lib/scholar/manifold/mds.ex
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ defmodule Scholar.Manifold.MDS do
increasing: true
)

model = Scholar.Linear.IsotonicRegression.special_preprocess(disparities_flat_model)
model = special_preprocess(disparities_flat_model)

disparities_flat =
Scholar.Linear.IsotonicRegression.predict(model, similarities_flat_w)
Expand Down Expand Up @@ -398,4 +398,15 @@ defmodule Scholar.Manifold.MDS do
{best, best_stress, best_iter} = mds_main_loop(x, init, key, opts)
%__MODULE__{embedding: best, stress: best_stress, n_iter: best_iter}
end

defnp special_preprocess(model) do
%Scholar.Linear.IsotonicRegression{
model
| preprocess:
Scholar.Interpolation.Linear.fit(
model.x_thresholds,
model.y_thresholds
)
}
end
end

0 comments on commit 9d514b3

Please sign in to comment.