Coder Social home page Coder Social logo

Type error in optimize_embedding about umap HOT 3 OPEN

tkonopka avatar tkonopka commented on May 18, 2024
Type error in optimize_embedding

from umap.

Comments (3)

tkonopka avatar tkonopka commented on May 18, 2024

Thanks for reporting. That config seems to match the default (a=NA, b=NA, spread=1) so am not sure why you are seeing the warning. Could you confirm that is indeed the configuration, please?

It is helpful that you traced to optimize_embedding and that none of the inputs are character, but the root cause doesn't spring to mind. Would you be able to share a minimal example, especially your config settings (see above). And just to be sure, are you using version 0.2.10?

Sorry this is not immediately helpful, but let's investigate further.

from umap.

dkassler avatar dkassler commented on May 18, 2024

Yes, I'm using umap 2.10. Did a little more detective work, and this is what I've found:

The umap config settings I'm using (umap_config) appear to have the same values as umap.defaults when printed, but that's only because of the print method for class umap.config. In actuality, my config file had "NA" instead of NA and 1L instead of 1 because it was (incorrectly) parsed from a YAML file.

> cbind(umap.defaults, sapply(umap.defaults, class), umap_config, sapply(umap_config, class))
                     umap.defaults             umap_config            
n_neighbors          15            "numeric"   15          "integer"  
n_components         2             "numeric"   2           "integer"  
metric               "euclidean"   "character" "euclidean" "character"
n_epochs             200           "numeric"   200         "integer"  
input                "data"        "character" "data"      "character"
init                 "spectral"    "character" "spectral"  "character"
min_dist             0.1           "numeric"   0.1         "numeric"  
set_op_mix_ratio     1             "numeric"   1           "integer"  
local_connectivity   1             "numeric"   1           "integer"  
bandwidth            1             "numeric"   1           "integer"  
alpha                1             "numeric"   1           "integer"  
gamma                1             "numeric"   1           "integer"  
negative_sample_rate 5             "numeric"   5           "integer"  
a                    NA            "logical"   "NA"        "character"
b                    NA            "logical"   "NA"        "character"
spread               1             "numeric"   1           "integer"  
random_state         NA            "logical"   "NA"        "character"
transform_state      NA            "logical"   "NA"        "character"
knn                  NA            "logical"   "NA"        "character"
knn_repeats          1             "numeric"   1           "integer"  
verbose              FALSE         "logical"   FALSE       "logical"  
umap_learn_args      NA            "logical"   "NA"        "character"

If you run the two different configs you get:

> umap(mtcars)
umap embedding of 32 items in 2 dimensions
object components: layout, data, knn, config
> umap(mtcars, config = umap_config)
Error: Not compatible with requested type: [type=character; target=double].
In addition: Warning messages:
1: umap: parameters 'spread', 'a', 'b' are set to non-default values;
 parameter 'spread' will be ignored.
 (Embedding will be controlled via 'a' and 'b')
 
2: In umap.prep.config(config, ...) : NAs introduced by coercion
3: In umap.prep.config(config, ...) : NAs introduced by coercion

To reproduce in a minimal example, I'm attaching a dput of my config file.

umap_config <- structure(list(n_neighbors = 15L, n_components = 2L, metric = "euclidean", 
    n_epochs = 200L, input = "data", init = "spectral", min_dist = 0.1, 
    set_op_mix_ratio = 1L, local_connectivity = 1L, bandwidth = 1L, 
    alpha = 1L, gamma = 1L, negative_sample_rate = 5L, a = "NA", 
    b = "NA", spread = 1L, random_state = "NA", transform_state = "NA", 
    knn = "NA", knn_repeats = 1L, verbose = FALSE, umap_learn_args = "NA"), class = "umap.config")

As for why in my initial debug I found abg = c(NA, NA, 1, 0) instead of showing as character, I don't know because I can't reproduce that. Must have been something else I did to that environment, because reproducing it with a minimal example in a fresh environment just shows abg = c("NA", "NA", "1", "0") which is obviously the character vector the function is having problems with.

So case closed, this is user error on my part. That said, it might be nice for the function to do some type checking early on and throw more verbose error messages about that?

from umap.

tkonopka avatar tkonopka commented on May 18, 2024

Thanks for the detailed investigation. Glad you found the root cause and can work around this for now.

As you suggest, additional input validation would be useful. Most inputs should be numeric values, apart from 'metric', 'input', 'init', and 'umap_learn_args'. If you'd like to make a PR, I'd be happy to incorporate into a new version!

from umap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.