Module: Umappp

Defined in:
lib/umappp.rb,
lib/umappp/version.rb

Overview

Uniform Manifold Approximation and Projection

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.default_parametersObject

View the default parameters defined within the Umappp C++ library structure.



14
15
16
17
# File 'lib/umappp.rb', line 14

def self.default_parameters
  # {method: :annoy, ndim: 2}.merge
  umappp_default_parameters
end

.run(embedding, method: :annoy, ndim: 2, **params) ⇒ Numo::SFloat

Runs the Uniform Manifold Approximation and Projection (UMAP) dimensional reduction technique.

Parameters:

  • embedding (Array, Numo::SFloat)
  • method (Symbol) (defaults to: :annoy)
  • ndim (Integer) (defaults to: 2)
  • tick (Integer)
  • local_connectivity (Numeric)
  • bandwidth (Numeric)
  • mix_ratio (Numeric)
  • spread (Numeric)
  • min_dist (Numeric)
  • a (Numeric)
  • b (Numeric)
  • repulsion_strength (Numeric)
  • initilaize (Umappp::InitMethod)
  • num_epochs (Integer)
  • learning_rate (Numeric)
  • negative_sample_rate (Numeric)
  • num_neighbors (Integer)
  • seed (Integer)
  • num_threads (Integer)
  • parallel_optimization (Boolean)

Returns:

  • (Numo::SFloat)

    the final embedding

Raises:

  • (ArgumentError)


43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/umappp.rb', line 43

def self.run(embedding, method: :annoy, ndim: 2, **params)
  unless (u = (params.keys - default_parameters.keys)).empty?
    raise ArgumentError, "[umappp.rb] unknown option : #{u.inspect}"
  end

  nnmethod = %i[annoy vptree].index(method.to_sym)
  raise ArgumentError, "method must be :annoy or :vptree" if nnmethod.nil?

  embedding2 = Numo::SFloat.cast(embedding)
  raise ArgumentError, "embedding must be a 2D array" if embedding2.ndim <= 1

  umappp_run(params, embedding2, ndim, nnmethod)
end