mantel/tests/models/common.py
2024-06-11 21:08:08 +10:00

27 lines
1.1 KiB
Python

import numpy as np
from hypothesis import strategies as st
MINIMUM_NETWORK_DIMENSION = 3
def generate_kohonen_samples(num_features):
"""Custom Hypothesis strategy to generate matrix X with consistent feature length."""
return st.lists(
st.lists(
st.floats(allow_nan=False, allow_infinity=False, min_value=-1e6, max_value=1e6),
min_size=num_features, max_size=num_features # Consistent feature length
),
min_size=1, max_size=100
).map(lambda x: np.array(x, dtype=np.float32))
def generate_kohonen_weights(width, height, feature_size):
"""Custom Hypothesis strategy to generate a weights matrix with specified dimensions and feature size."""
return st.lists(
st.lists(
st.lists(
st.floats(min_value=-10, max_value=10),
min_size=feature_size, max_size=feature_size # Each feature vector has a consistent feature size
),
min_size=width, max_size=width # Consistent width for each row
),
min_size=height, max_size=height # Consistent height for the matrix
).map(lambda x: np.array(x, dtype=np.float32))