bioFAM / mofapy2

Multi-omics factor analysis v2
https://biofam.github.io/MOFA2/
GNU Lesser General Public License v3.0
36 stars 28 forks source link

Model with one latent factor less than specified #3

Closed flcello closed 3 years ago

flcello commented 3 years ago

Hi,

It seems to me like the model is built with one factor less than specified in set_model_options():

from mofapy2.run.entry_point import entry_point

ent = entry_point()

ent.set_data_options(
    scale_groups = False, 
    scale_views = False
    )

ent.set_data_matrix([[data]], likelihoods = ["gaussian"])

ent.set_model_options(
    factors = 3, 
    spikeslab_weights = False, 
    ard_factors = False,
    ard_weights = False
    )

ent.set_train_options(
    iter = 1000, 
    convergence_mode = "slow", 
    startELBO = 1, 
    freqELBO = 1, 
    dropR2 = 0.000, 
    gpu_mode = False, 
    verbose = False, 
    seed = 1
    )

ent.build()
ent.run()

This should result in a model with 3 factors, but from the first iteration on I only get 2 factors:

######################################
## Training the model with seed 1 ##
######################################

ELBO before training: -160245.23 

Iteration 1: time=0.01, ELBO=-38881.59, deltaELBO=121363.642 (75.73619616%), Factors=2
Iteration 2: time=0.03, ELBO=-35202.00, deltaELBO=3679.586 (2.29622203%), Factors=2
Iteration 3: time=0.02, ELBO=-34646.27, deltaELBO=555.731 (0.34680037%), Factors=2
...
gtca commented 3 years ago

Hey, thanks for the report!

If you drop the dropR2 parameter, it should work as expected. It should be set to None (as default) in order not to drop any factors. I think that would solve this issue.

To expand a bit on this topic, in order to set a threshold and not to drop a factor at the first iteration, there's a start_drop parameter to the training options that can be set to 2: ent.set_train_options(..., start_drop=2). The reason behind this is that the factors are dropped in the beginning of each iteration. Together these things don't make much sense though... What do you think, @rargelaguet?

flcello commented 3 years ago

perfect, thanks for clarifying!