Skip to content

Instantly share code, notes, and snippets.

@seifip
Created March 16, 2023 08:57
Show Gist options
  • Save seifip/24ca21f6e3280d265577237b77ff150d to your computer and use it in GitHub Desktop.
Save seifip/24ca21f6e3280d265577237b77ff150d to your computer and use it in GitHub Desktop.
def create_dimers(design_pairs, sparse_factor=0.05, max_c=50, min_hard=25, min_soft=45, soft_threshold=0.8, rand_seed=seed):
num_observations, num_pairings = design_pairs.shape
inv_max_CT = max_c - min_hard
m_val = 1
c_at_threshold = max_c - min_soft + m_val
b_val = -np.log(1 - soft_threshold) / np.log(c_at_threshold / m_val)
dimer_distribution = sp.stats.bernoulli(sparse_factor)
pairing_is_dimer = dimer_distribution.rvs(size=num_pairings, random_state=rand_seed)
specific_inv_CT_dist = sp.stats.truncpareto(b=b_val, c=inv_max_CT + m_val, loc=-m_val)
specific_inv_CTs = specific_inv_CT_dist.rvs(size=num_pairings, random_state=rand_seed + 1) * pairing_is_dimer
specific_CTs = max_c - specific_inv_CTs
return specific_CTs, specific_inv_CTs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment