Method: Umappp.run
- Defined in:
- lib/umappp.rb
.run(embedding, method: :annoy, ndim: 2, **params) ⇒ Numo::SFloat
Runs the Uniform Manifold Approximation and Projection (UMAP) dimensional reduction technique.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/umappp.rb', line 43 def self.run(, method: :annoy, ndim: 2, **params) unless (u = (params.keys - default_parameters.keys)).empty? raise ArgumentError, "Unknown option(s): #{u.inspect}" end nnmethod = %i[annoy vptree].index(method.to_sym) raise ArgumentError, "method must be :annoy or :vptree" if nnmethod.nil? # Allow initialize: to be specified as a Symbol or String and # convert it to the corresponding Umappp::InitMethod enum. if params.key?(:initialize) init_val = params[:initialize] if init_val.is_a?(Symbol) || init_val.is_a?(String) init_sym = init_val.to_sym mapping = { spectral: InitMethod::SPECTRAL, spectral_only: InitMethod::SPECTRAL_ONLY, random: InitMethod::RANDOM, none: InitMethod::NONE } mapped = mapping[init_sym] unless mapped raise ArgumentError, "initialize must be one of :spectral, :spectral_only, :random, :none or a Umappp::InitMethod" end params[:initialize] = mapped end # If it's already a Umappp::InitMethod, we just pass it through. end = Numo::SFloat.cast() if .ndim != 2 raise ArgumentError, "embedding must be a 2D array, got #{.ndim}D with shape #{.shape.inspect}" end raise ArgumentError, "embedding must not be empty" if .empty? umappp_run(params, , ndim, nnmethod) end |