Skip to content

Commit

Permalink
Revert "Growth rate SDE w/ examples"
Browse files Browse the repository at this point in the history
  • Loading branch information
xingzhis authored Aug 21, 2024
1 parent 0815ecc commit 5df2e2b
Show file tree
Hide file tree
Showing 34 changed files with 221 additions and 49,967 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,3 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST

old/
old2/
47 changes: 3 additions & 44 deletions MIOFlow/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,14 @@
'git_url': 'https://github.com/KrishnaswamyLab/MIOFlow/tree/main/',
'lib_path': 'MIOFlow'},
'syms': { 'MIOFlow.constants': {},
'MIOFlow.datasets': { 'MIOFlow.datasets.branch_data_clean': ('datasets.html#branch_data_clean', 'MIOFlow/datasets.py'),
'MIOFlow.datasets.branch_data_data': ('datasets.html#branch_data_data', 'MIOFlow/datasets.py'),
'MIOFlow.datasets.construct_diamond': ('datasets.html#construct_diamond', 'MIOFlow/datasets.py'),
'MIOFlow.datasets.make_branch_cond': ('datasets.html#make_branch_cond', 'MIOFlow/datasets.py'),
'MIOFlow.datasets': { 'MIOFlow.datasets.construct_diamond': ('datasets.html#construct_diamond', 'MIOFlow/datasets.py'),
'MIOFlow.datasets.make_diamonds': ('datasets.html#make_diamonds', 'MIOFlow/datasets.py'),
'MIOFlow.datasets.make_diamonds_partial_holdout': ( 'datasets.html#make_diamonds_partial_holdout',
'MIOFlow/datasets.py'),
'MIOFlow.datasets.make_dying_example_gaus': ( 'datasets.html#make_dying_example_gaus',
'MIOFlow/datasets.py'),
'MIOFlow.datasets.make_dying_example_unif': ( 'datasets.html#make_dying_example_unif',
'MIOFlow/datasets.py'),
'MIOFlow.datasets.make_dyngen_data': ('datasets.html#make_dyngen_data', 'MIOFlow/datasets.py'),
'MIOFlow.datasets.make_eb_data': ('datasets.html#make_eb_data', 'MIOFlow/datasets.py'),
'MIOFlow.datasets.make_gaussian_rect': ('datasets.html#make_gaussian_rect', 'MIOFlow/datasets.py'),
'MIOFlow.datasets.make_jacks': ('datasets.html#make_jacks', 'MIOFlow/datasets.py'),
'MIOFlow.datasets.make_rings': ('datasets.html#make_rings', 'MIOFlow/datasets.py'),
'MIOFlow.datasets.make_swiss_roll': ('datasets.html#make_swiss_roll', 'MIOFlow/datasets.py'),
'MIOFlow.datasets.make_tree': ('datasets.html#make_tree', 'MIOFlow/datasets.py'),
'MIOFlow.datasets.make_uniform_rect': ('datasets.html#make_uniform_rect', 'MIOFlow/datasets.py'),
'MIOFlow.datasets.make_worm_data': ('datasets.html#make_worm_data', 'MIOFlow/datasets.py'),
'MIOFlow.datasets.relabel_data': ('datasets.html#relabel_data', 'MIOFlow/datasets.py'),
'MIOFlow.datasets.rings': ('datasets.html#rings', 'MIOFlow/datasets.py')},
Expand Down Expand Up @@ -79,22 +68,6 @@
'MIOFlow.losses': { 'MIOFlow.losses.Density_loss': ('losses.html#density_loss', 'MIOFlow/losses.py'),
'MIOFlow.losses.Density_loss.__call__': ('losses.html#density_loss.__call__', 'MIOFlow/losses.py'),
'MIOFlow.losses.Density_loss.__init__': ('losses.html#density_loss.__init__', 'MIOFlow/losses.py'),
'MIOFlow.losses.EnergyLoss': ('losses.html#energyloss', 'MIOFlow/losses.py'),
'MIOFlow.losses.EnergyLoss.__call__': ('losses.html#energyloss.__call__', 'MIOFlow/losses.py'),
'MIOFlow.losses.EnergyLoss.__init__': ('losses.html#energyloss.__init__', 'MIOFlow/losses.py'),
'MIOFlow.losses.EnergyLossGrowthRate': ('losses.html#energylossgrowthrate', 'MIOFlow/losses.py'),
'MIOFlow.losses.EnergyLossGrowthRate.__call__': ( 'losses.html#energylossgrowthrate.__call__',
'MIOFlow/losses.py'),
'MIOFlow.losses.EnergyLossGrowthRate.__init__': ( 'losses.html#energylossgrowthrate.__init__',
'MIOFlow/losses.py'),
'MIOFlow.losses.EnergyLossGrowthRateSeq': ('losses.html#energylossgrowthrateseq', 'MIOFlow/losses.py'),
'MIOFlow.losses.EnergyLossGrowthRateSeq.__call__': ( 'losses.html#energylossgrowthrateseq.__call__',
'MIOFlow/losses.py'),
'MIOFlow.losses.EnergyLossGrowthRateSeq.__init__': ( 'losses.html#energylossgrowthrateseq.__init__',
'MIOFlow/losses.py'),
'MIOFlow.losses.EnergyLossSeq': ('losses.html#energylossseq', 'MIOFlow/losses.py'),
'MIOFlow.losses.EnergyLossSeq.__call__': ('losses.html#energylossseq.__call__', 'MIOFlow/losses.py'),
'MIOFlow.losses.EnergyLossSeq.__init__': ('losses.html#energylossseq.__init__', 'MIOFlow/losses.py'),
'MIOFlow.losses.Local_density_loss': ('losses.html#local_density_loss', 'MIOFlow/losses.py'),
'MIOFlow.losses.Local_density_loss.__call__': ( 'losses.html#local_density_loss.__call__',
'MIOFlow/losses.py'),
Expand All @@ -106,25 +79,12 @@
'MIOFlow.losses.MMD_loss.guassian_kernel': ('losses.html#mmd_loss.guassian_kernel', 'MIOFlow/losses.py'),
'MIOFlow.losses.OT_loss': ('losses.html#ot_loss', 'MIOFlow/losses.py'),
'MIOFlow.losses.OT_loss.__call__': ('losses.html#ot_loss.__call__', 'MIOFlow/losses.py'),
'MIOFlow.losses.OT_loss.__init__': ('losses.html#ot_loss.__init__', 'MIOFlow/losses.py'),
'MIOFlow.losses.density_specified_OT_loss': ('losses.html#density_specified_ot_loss', 'MIOFlow/losses.py'),
'MIOFlow.losses.density_specified_OT_loss.__call__': ( 'losses.html#density_specified_ot_loss.__call__',
'MIOFlow/losses.py'),
'MIOFlow.losses.density_specified_OT_loss.__init__': ( 'losses.html#density_specified_ot_loss.__init__',
'MIOFlow/losses.py')},
'MIOFlow.losses.OT_loss.__init__': ('losses.html#ot_loss.__init__', 'MIOFlow/losses.py')},
'MIOFlow.models': { 'MIOFlow.models.Autoencoder': ('models.html#autoencoder', 'MIOFlow/models.py'),
'MIOFlow.models.Autoencoder.__init__': ('models.html#autoencoder.__init__', 'MIOFlow/models.py'),
'MIOFlow.models.Autoencoder.decode': ('models.html#autoencoder.decode', 'MIOFlow/models.py'),
'MIOFlow.models.Autoencoder.encode': ('models.html#autoencoder.encode', 'MIOFlow/models.py'),
'MIOFlow.models.Autoencoder.forward': ('models.html#autoencoder.forward', 'MIOFlow/models.py'),
'MIOFlow.models.GrowthRateModel': ('models.html#growthratemodel', 'MIOFlow/models.py'),
'MIOFlow.models.GrowthRateModel.__init__': ('models.html#growthratemodel.__init__', 'MIOFlow/models.py'),
'MIOFlow.models.GrowthRateModel.forward': ('models.html#growthratemodel.forward', 'MIOFlow/models.py'),
'MIOFlow.models.GrowthRateSDEModel': ('models.html#growthratesdemodel', 'MIOFlow/models.py'),
'MIOFlow.models.GrowthRateSDEModel.__init__': ( 'models.html#growthratesdemodel.__init__',
'MIOFlow/models.py'),
'MIOFlow.models.GrowthRateSDEModel.forward': ( 'models.html#growthratesdemodel.forward',
'MIOFlow/models.py'),
'MIOFlow.models.ToyModel': ('models.html#toymodel', 'MIOFlow/models.py'),
'MIOFlow.models.ToyModel.__init__': ('models.html#toymodel.__init__', 'MIOFlow/models.py'),
'MIOFlow.models.ToyModel.forward': ('models.html#toymodel.forward', 'MIOFlow/models.py'),
Expand All @@ -151,8 +111,7 @@
'MIOFlow.plots.plot_comparision': ('plots.html#plot_comparision', 'MIOFlow/plots.py'),
'MIOFlow.plots.plot_gene_trends': ('plots.html#plot_gene_trends', 'MIOFlow/plots.py'),
'MIOFlow.plots.plot_losses': ('plots.html#plot_losses', 'MIOFlow/plots.py')},
'MIOFlow.train': { 'MIOFlow.train.subset_threshold': ('train.html#subset_threshold', 'MIOFlow/train.py'),
'MIOFlow.train.train': ('train.html#train', 'MIOFlow/train.py'),
'MIOFlow.train': { 'MIOFlow.train.train': ('train.html#train', 'MIOFlow/train.py'),
'MIOFlow.train.train_ae': ('train.html#train_ae', 'MIOFlow/train.py'),
'MIOFlow.train.training_regimen': ('train.html#training_regimen', 'MIOFlow/train.py')},
'MIOFlow.utils': { 'MIOFlow.utils.config_criterion': ('utils.html#config_criterion', 'MIOFlow/utils.py'),
Expand Down
190 changes: 9 additions & 181 deletions MIOFlow/datasets.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/07_datasets.ipynb.

# %% auto 0
__all__ = ['construct_diamond', 'make_diamonds', 'make_diamonds_partial_holdout', 'make_swiss_roll', 'make_tree',
'make_worm_data', 'make_eb_data', 'make_dyngen_data', 'relabel_data', 'rings', 'make_rings', 'make_jacks',
'branch_data_clean', 'branch_data_data', 'make_branch_cond', 'make_uniform_rect', 'make_gaussian_rect',
'make_dying_example_unif', 'make_dying_example_gaus']
__all__ = ['construct_diamond', 'make_diamonds', 'make_swiss_roll', 'make_tree', 'make_worm_data', 'make_eb_data',
'make_dyngen_data', 'relabel_data', 'rings', 'make_rings', 'make_jacks']

# %% ../nbs/07_datasets.ipynb 3
import os
Expand Down Expand Up @@ -85,23 +83,7 @@ def make_diamonds(
df.set_index('samples')
return df

# %% ../nbs/07_datasets.ipynb 5
def make_diamonds_partial_holdout(
points_per_petal:int=200,
petal_width:float=0.25,
colors:int=5,
scale_factor:float=30,
use_gaussian:bool=True,
drop_colors = [4,5]
):
df = make_diamonds(points_per_petal, petal_width, colors, scale_factor, use_gaussian)
df['branch'] = 0
df['branch'][int(df.shape[0]/2):] = 1
df = df[~(df.samples.isin(drop_colors)& (df.branch==0))]
df.drop('branch', axis=1, inplace=True)
return df

# %% ../nbs/07_datasets.ipynb 8
# %% ../nbs/07_datasets.ipynb 6
def make_swiss_roll(n_points=1500):
'''
Arguments:
Expand All @@ -118,7 +100,7 @@ def make_swiss_roll(n_points=1500):
df.samples -= np.min(df.samples)
return df

# %% ../nbs/07_datasets.ipynb 9
# %% ../nbs/07_datasets.ipynb 7
def make_tree():
'''
Arguments:
Expand All @@ -139,7 +121,7 @@ def make_tree():
df = pd.DataFrame(np.hstack((branches.reshape(-1, 1), tree_phate)), columns='samples d1 d2 d3 d4 d5'.split())
return df

# %% ../nbs/07_datasets.ipynb 10
# %% ../nbs/07_datasets.ipynb 8
from .constants import WORM_FILE
def make_worm_data():
data = np.load(WORM_FILE)
Expand All @@ -153,7 +135,7 @@ def make_worm_data():
df.set_index('samples')
return df

# %% ../nbs/07_datasets.ipynb 11
# %% ../nbs/07_datasets.ipynb 9
from .constants import EB_BODIES_FILE,EB_BODIES_PSEUDO_4,EB_BODIES_PSEUDO_6,EB_BODIES_PSEUDO_25,EB_BODIES_PSEUDO_82

def make_eb_data(phate=False, phate_dims=5,n_sample='all', random_state=1):
Expand Down Expand Up @@ -181,7 +163,7 @@ def make_eb_data(phate=False, phate_dims=5,n_sample='all', random_state=1):
, df['pt4'], df['pt6'], df['pt25']], axis=1)
return df

# %% ../nbs/07_datasets.ipynb 12
# %% ../nbs/07_datasets.ipynb 10
from .constants import (DYNGEN_INFO_FILE, DYNGEN_EXPR_FILE)
from phate import PHATE
import warnings
Expand Down Expand Up @@ -261,7 +243,7 @@ def relabel_data(df,min_bin=0, n_bins=10, column='d1', samples_key='samples'):
dff.loc[locs, samples_key] = i
return dff

# %% ../nbs/07_datasets.ipynb 14
# %% ../nbs/07_datasets.ipynb 12
import numpy as np, seaborn as sns, pandas as pd, matplotlib.pyplot as plt

def rings(
Expand Down Expand Up @@ -354,7 +336,7 @@ def make_rings(N:int, M:int = None,
df.set_index('samples')
return df

# %% ../nbs/07_datasets.ipynb 16
# %% ../nbs/07_datasets.ipynb 14
def make_jacks(
n_axes = 3,
points = 1000,
Expand Down Expand Up @@ -423,157 +405,3 @@ def make_jacks(
df['samples'] = classes
df.set_index('samples')
return df

# %% ../nbs/07_datasets.ipynb 18
def branch_data_clean(t, e):
shapes = (len(e), len(t))
t = t.reshape(1,-1)
e = e.reshape(-1, 1)
ts = np.tile(t, (shapes[0], 1))[...,None]
es = np.tile(e, (1, shapes[1]))[...,None]
x = np.tile(t, (shapes[0], 1))
y = e * t**2
data = np.stack([x,y], axis=2)
data = np.concatenate((ts, es, data), axis=-1)
data = data.reshape(shapes[0]*shapes[1], -1)
return data
def branch_data_data(data, n_colors=5, repeats=5, noise=0.05, seed=32):
data = np.tile(data, (repeats,1))
df = pd.DataFrame(data, columns=['t', 'e1', 'd1', 'd2'])
np.random.seed(seed)
noise = np.random.normal(0, noise, (data.shape[0], 2))
df[['d1', 'd2']] += noise
_, bin_edges = np.histogram(df['t'], bins=n_colors)
bin_indices = np.digitize(df['t'], bin_edges)
bin_indices[bin_indices > n_colors] = n_colors
df.insert(0, 'samples', bin_indices)
df.drop(columns=['t'], inplace=True)
df.samples -=1
return df
def make_branch_cond(nt=20, ne=3, n_colors=5, repeats=10, noise=0.1, seed=32):
t = np.linspace(0,1,nt)
e = np.linspace(-1,1,ne)
data = branch_data_clean(t, e)
df = branch_data_data(data, n_colors, repeats, noise, seed)
return df

# %% ../nbs/07_datasets.ipynb 20
import numpy as np
import pandas as pd

def make_uniform_rect(x_bounds, y_bounds, num_points):
"""
Generates uniformly distributed points within a rectangular box.
Parameters:
- x_bounds: Tuple (x_min, x_max) defining the bounds on the X-axis.
- y_bounds: Tuple (y_min, y_max) defining the bounds on the Y-axis.
- num_points: The number of points to generate.
Returns:
- points: A 2D numpy array where each row is a point [x, y].
"""
x_min, x_max = x_bounds
y_min, y_max = y_bounds

x_points = np.random.uniform(x_min, x_max, num_points)
y_points = np.random.uniform(y_min, y_max, num_points)

points = np.column_stack((x_points, y_points))

return points

import numpy as np
import pandas as pd

def make_gaussian_rect(x_bounds, y_bounds, num_points):
"""
Generates Gaussian distributed points within a rectangular box.
Parameters:
- x_bounds: Tuple (x_min, x_max) defining the bounds on the X-axis.
- y_bounds: Tuple (y_min, y_max) defining the bounds on the Y-axis.
- num_points: The number of points to generate.
Returns:
- points: A 2D numpy array where each row is a point [x, y].
"""
x_min, x_max = x_bounds
y_min, y_max = y_bounds

# Calculate the mean and standard deviation based on the bounds
x_mean = (x_min + x_max) / 2
y_mean = (y_min + y_max) / 2
x_std = (x_max - x_min) / 3 # 99.7% of data within bounds for ±3 std
y_std = (y_max - y_min) / 6

# Generate Gaussian distributed points within the rectangle
x_points = np.random.normal(x_mean, x_std, num_points)
y_points = np.random.normal(y_mean, y_std, num_points)

# Clip the points to stay within the specified bounds
x_points = np.clip(x_points, x_min, x_max)
y_points = np.clip(y_points, y_min, y_max)

# Combine the points into a 2D array (each row is a point [x, y])
points = np.column_stack((x_points, y_points))

return points

def make_dying_example_unif(n_pts_per_bin=50, seed=223):
np.random.seed(seed)
tp0 = make_uniform_rect((-1.5, -0.4), (-0.5, 0.5), n_pts_per_bin*2)
tp1 = make_uniform_rect((-0.6, 0.6), (-0.5, 0.5), n_pts_per_bin*2)
tp2 = make_uniform_rect((0.4, 1.6), (-0.5, 0.5), n_pts_per_bin*2)
tp3 = make_uniform_rect((1.4, 2.6), (0., 0.5), n_pts_per_bin)
tp4 = make_uniform_rect((2.4, 3.1), (0., 0.5), n_pts_per_bin)
# concatenate, but add a column for the timepoint, make it a dataframe
# Create dataframes and add a timepoint column

df_tp0 = pd.DataFrame(tp0, columns=['d1', 'd2'])
df_tp0['samples'] = 0

df_tp1 = pd.DataFrame(tp1, columns=['d1', 'd2'])
df_tp1['samples'] = 1

df_tp2 = pd.DataFrame(tp2, columns=['d1', 'd2'])
df_tp2['samples'] = 2

df_tp3 = pd.DataFrame(tp3, columns=['d1', 'd2'])
df_tp3['samples'] = 3

df_tp4 = pd.DataFrame(tp4, columns=['d1', 'd2'])
df_tp4['samples'] = 4

# Concatenate the dataframes
df = pd.concat([df_tp0, df_tp1, df_tp2, df_tp3, df_tp4], ignore_index=True)
return df

def make_dying_example_gaus(n_pts_per_bin=50, seed=223):
np.random.seed(seed)
tp0 = make_gaussian_rect((-1.5, -0.4), (-0.5, 0.5), n_pts_per_bin*2)
tp1 = make_gaussian_rect((-0.6, 0.6), (-0.5, 0.5), n_pts_per_bin*2)
tp2 = make_gaussian_rect((0.4, 1.6), (-0.5, 0.5), n_pts_per_bin*2)
tp3 = make_gaussian_rect((1.4, 2.6), (0., 0.5), n_pts_per_bin)
tp4 = make_gaussian_rect((2.4, 3.1), (0., 0.5), n_pts_per_bin)
# concatenate, but add a column for the timepoint, make it a dataframe
# Create dataframes and add a timepoint column

df_tp0 = pd.DataFrame(tp0, columns=['d1', 'd2'])
df_tp0['samples'] = 0

df_tp1 = pd.DataFrame(tp1, columns=['d1', 'd2'])
df_tp1['samples'] = 1

df_tp2 = pd.DataFrame(tp2, columns=['d1', 'd2'])
df_tp2['samples'] = 2

df_tp3 = pd.DataFrame(tp3, columns=['d1', 'd2'])
df_tp3['samples'] = 3

df_tp4 = pd.DataFrame(tp4, columns=['d1', 'd2'])
df_tp4['samples'] = 4

# Concatenate the dataframes
df = pd.concat([df_tp0, df_tp1, df_tp2, df_tp3, df_tp4], ignore_index=True)
return df
Loading

0 comments on commit 5df2e2b

Please sign in to comment.