Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nesterov line search #39

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
# tensorpack
A collection of tensor methods from the Meyer lab.

To add it to your Python package, add the following line to `requirements.txt` and remake `venv`:
```
git+https://github.com/meyer-lab/tensorpack.git@main
```
# tensor-impute
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test:
poetry run pytest -s -v -x

coverage.xml:
poetry run pytest --junitxml=junit.xml --cov=tensorpack --cov-report xml:coverage.xml
poetry run pytest --junitxml=junit.xml --cov=timpute --cov-report xml:coverage.xml

clean:
rm -rf coverage.xml
597 changes: 106 additions & 491 deletions poetry.lock

Large diffs are not rendered by default.

20 changes: 9 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@ license = "MIT"

[tool.poetry.dependencies]
python = ">=3.11,<3.13"
numpy = "^1.26"
tensorly = "^0.8.1"
matplotlib = "^3.5.0"
tqdm = "^4.65"
numpy = "^2.1"
tensorly = "^0.8"
matplotlib = "^3.9"
tqdm = "^4.67"
seaborn = "^0.13"
xarray = "^2023"
tensorpack = "^0.11"
xarray = "^2024"
scikit-learn = "^1.1.3"
openpyxl = "^3.1.2"
setuptools = "^69.5.1"
pyright = "^1.1.389"

[tool.poetry.dev-dependencies]
pytest = "^8.3"
pytest-cov = "^3.0.0"
tensordata = {git = "https://github.com/meyer-lab/tensordata.git", branch = "main"}
pytest-cov = "^6.0"
tensordata = {git = "https://github.com/meyer-lab/tensordata.git", rev = "6afaec35c552c3ee91990db74c740728ddf37a55"}
pyright = "^1.1.389"
isort = "^5.13"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
12 changes: 0 additions & 12 deletions setup.py

This file was deleted.

3 changes: 2 additions & 1 deletion timpute/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import tensorly as tl

from .decomposition import Decomposition
import tensorly as tl
3 changes: 2 additions & 1 deletion timpute/data/import_hmsData.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

import numpy as np
import pandas as pd
import os
import xarray as xa


Expand Down
16 changes: 7 additions & 9 deletions timpute/decomposition.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import pickle
from typing import Optional

import numpy as np
import tensorly as tl
from tqdm import tqdm

from .tracker import Tracker
from .impute_helper import calcR2X, chord_drop, entry_drop
from .initialization import initialize_fac
from .impute_helper import entry_drop, chord_drop
from .impute_helper import calcR2X
from .method_CLS import perform_CLS

from copy import deepcopy
from tqdm import tqdm
from .tracker import Tracker


class Decomposition:
Expand Down Expand Up @@ -43,7 +42,7 @@ def imputation(
init="random",
maxiter: int = 50,
seed=1,
callback: Tracker = None,
callback: Optional[Tracker] = None,
printRuntime=False,
):
"""
Expand Down Expand Up @@ -135,7 +134,7 @@ def imputation(
np.random.seed(int(x * seed))
CPinit = initialize_fac(missingCube.copy(), rr, init)
elif isinstance(init, tl.cp_tensor.CPTensor):
CPinit = deepcopy(init)
CPinit = init.cp_copy()
else:
raise ValueError(f'Initialization method "{init}" not recognized')

Expand All @@ -155,7 +154,6 @@ def imputation(
missingCube.copy(),
rank=rr,
n_iter_max=maxiter,
mask=mask,
init=CPinit,
callback=callback,
tol=tol,
Expand Down
10 changes: 6 additions & 4 deletions timpute/figures/common.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""
This file contains functions that are used in multiple figures.
"""
import seaborn as sns
from string import ascii_lowercase
import matplotlib
from matplotlib import gridspec, pyplot as plt

import matplotlib
import seaborn as sns
from matplotlib import gridspec
from matplotlib import pyplot as plt
from matplotlib.lines import Line2D

matplotlib.rcParams["legend.labelspacing"] = 0.2
matplotlib.rcParams["legend.fontsize"] = 8
Expand Down Expand Up @@ -68,4 +70,4 @@ def rgbs(color = 0, transparency = None):
if transparency is not None:
return tuple(list(color_rgbs[color]) + [transparency])
else:
return color_rgbs[color]
return color_rgbs[color]
6 changes: 4 additions & 2 deletions timpute/figures/figure2.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import math

import numpy as np
from figures import DATANAMES, METHODNAMES, METHODS, SAVENAMES

from .common import getSetup, rgbs, subplotLabel
from .figure_helper import loadImputation
from .common import getSetup, subplotLabel, rgbs
from figures import METHODS, METHODNAMES, SAVENAMES, DATANAMES

# poetry run python -m timpute.figures.figure2

Expand Down
6 changes: 4 additions & 2 deletions timpute/figures/figure3.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import math

import numpy as np
from figures import DATANAMES, DROPS, METHODNAMES, METHODS, SAVENAMES
from matplotlib.lines import Line2D

from .common import getSetup, rgbs, set_boxplot_color, subplotLabel
from .figure_helper import loadImputation
from .common import getSetup, subplotLabel, rgbs, set_boxplot_color
from figures import METHODS, METHODNAMES, SAVENAMES, DATANAMES, DROPS

# poetry run python -m timpute.figures.figure3

Expand Down
5 changes: 3 additions & 2 deletions timpute/figures/figure4.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import numpy as np
from figures import DATANAMES, METHODNAMES, METHODS, SAVENAMES

from .common import getSetup, rgbs, subplotLabel
from .figure_helper import loadImputation
from .common import getSetup, subplotLabel, rgbs
from figures import METHODS, METHODNAMES, SAVENAMES, DATANAMES

# poetry run python -m timpute.figures.figure4

Expand Down
6 changes: 4 additions & 2 deletions timpute/figures/figure5.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import numpy as np
from figures import DATANAMES, METHODNAMES, METHODS, SAVENAMES

from .common import getSetup, rgbs, subplotLabel
from .figure_data import bestComps
from .figure_helper import loadImputation
from .common import getSetup, subplotLabel, rgbs
from figures import METHODS, METHODNAMES, SAVENAMES, DATANAMES

# from matplotlib.legend_handler import HandlerErrorbar

# poetry run python -m timpute.figures.figure5
Expand Down
6 changes: 4 additions & 2 deletions timpute/figures/figure_data.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os

import numpy as np
from .figure_helper import runImputation, loadImputation
from figures import DROPS, METHODNAMES, METHODS, SAVENAMES

from ..generateTensor import generateTensor
from figures import METHODS, METHODNAMES, SAVENAMES, DROPS
from .figure_helper import loadImputation, runImputation

# poetry run python -m timpute.figures.figure_data

Expand Down
2 changes: 2 additions & 0 deletions timpute/figures/figure_helper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os

import numpy as np

from ..decomposition import Decomposition
from ..tracker import Tracker

Expand Down
9 changes: 5 additions & 4 deletions timpute/figures/memUsage.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# import psutil
import pickle
import argparse
import os
import numpy as np
import pickle
import resource
import argparse

from figures import METHODS, METHODNAMES, SAVENAMES
import numpy as np
from figures import METHODNAMES, METHODS, SAVENAMES

from ..decomposition import Decomposition
from ..generateTensor import generateTensor

Expand Down
6 changes: 4 additions & 2 deletions timpute/figures/supplements.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import pickle
from figures import METHODNAMES, SAVENAMES, DATANAMES, DROPS

import numpy as np
import pandas as pd
from .common import getSetup, rgbs
from figures import DATANAMES, DROPS, METHODNAMES, SAVENAMES

from ..decomposition import Decomposition
from .common import getSetup, rgbs

# poetry run python -m timpute.figures.supplements

Expand Down
Loading
Loading