Skip to content

cca_zoo_datasets.JoinData gives AttributeError: Module 'scipy' has no attribute 'zeros' #204

@JohannesWiesner

Description

@JohannesWiesner

I would like to simulate data with feature groups, but when doing:

from cca_zoo.datasets import JointData
n,p,q,latent_dimensions = 30,100,10,1
X,Y = JointData(view_features=[p,q],latent_dimensions=latent_dimensions,correlation=[0.9]).sample(n)

I currently get:

AttributeError: Module 'scipy' has no attribute 'zeros'

My cca_zoo version: 2.6.0
My scipy version: 1.13.1
My numpy version: 1.26.4

My self-written workaround:

# Random state for reproducibility
rng = np.random.RandomState(42)

# Parameters
n_samples = 100
n_features_X = 100
n_features_Y = 10
latent_correlation = 0.6

# Generate a latent variable
latent_dim = 1
latent_variable = rng.randn(n_samples, latent_dim)

# Generate X with structured covariance
# Define groups
group_sizes = [50, 25, 25]
group_correlations = [0.8, 0.7, 0.6]
X = np.zeros((n_samples, n_features_X))
current_feature = 0

for group_size, group_corr in zip(group_sizes, group_correlations):
    
    # Generate a group latent variable
    group_latent = latent_variable + rng.randn(n_samples, 1) * (1 - group_corr)
    
    # Generate group features
    group_features = group_latent @ rng.randn(1, group_size) + rng.randn(n_samples, group_size) * (1 - group_corr)
    X[:, current_feature:current_feature + group_size] = group_features
    current_feature += group_size

# Generate Y based on the latent variable
Y = latent_variable @ rng.randn(1, n_features_Y) + rng.randn(n_samples, n_features_Y) * (1 - latent_correlation)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions