Skip to content

Commit

Permalink
Minor fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbbcbail committed Aug 19, 2024
1 parent 58bc24e commit b0ad7cb
Show file tree
Hide file tree
Showing 19 changed files with 38 additions and 16 deletions.
Binary file modified data/Fig1-designProcess/blend1Subset.pickle
Binary file not shown.
Binary file modified data/Fig1-designProcess/blend2Subset.pickle
Binary file not shown.
Binary file modified data/Fig1-designProcess/blend3Subset.pickle
Binary file not shown.
Binary file modified data/Fig1-designProcess/distinct1Subset.pickle
Binary file not shown.
Binary file modified data/Fig1-designProcess/distinct2Subset.pickle
Binary file not shown.
Binary file modified data/Fig1-designProcess/distinct3Subset.pickle
Binary file not shown.
Binary file modified data/Fig1-designProcess/distinctSubset.pickle
Binary file not shown.
Binary file modified data/Fig1-designProcess/fullData.pickle
Binary file not shown.
Binary file modified data/Fig1-designProcess/hullSubset.pickle
Binary file not shown.
Binary file modified data/Fig1-designProcess/outliersSubset.pickle
Binary file not shown.
12 changes: 12 additions & 0 deletions data/solverData.csv
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,15 @@ Uni-criterion: clusterCenters,greedySwap,1000,2,10,0.13878262508660555,0.7724079
"Uni-criterion: preserveMetric, mean",worstOfRandom,1000,10,10,0.031927124597132206,9.503260009237106
"Uni-criterion: preserveMetric, mean",bestOfRandom,1000,10,10,0.027917416766285896,1.460277122561562
"Uni-criterion: preserveMetric, mean",greedySwap,1000,10,10,0.132963459007442,0.5640211475433015
"Uni-criterion: preserveMetric, hull",greedyMinSubset,200,2,10,0.08583308400011447,0.0
"Uni-criterion: sum, outlierness",greedySwap,200,2,40,0.03175995800029341,-81.35404458341424
"Uni-criterion: distinctness, distances",greedySwap,200,2,60,0.16693012500036275,-83.95544350897778
"Uni-criterion: preserveMetric, hull",greedyMinSubset,200,2,9,0.07353841700023622,0.0
"Uni-criterion: sum, outlierness",greedySwap,200,2,40,0.03256029200019839,-69.60149355751726
"Uni-criterion: distinctness, distances",greedySwap,200,2,60,0.15679762499985372,-72.5809741971094
"Multi-criterion: 100*(earthMoversDistance) + 1*(distinctness, distances)",greedySwap,200,2,80,8.897876584000187,-38.19786578061197
"Multi-criterion: 10*(earthMoversDistance) + 1*(distinctness, distances)",greedySwap,200,2,80,9.382594166999297,-71.67868194859224
"Multi-criterion: 1*(earthMoversDistance) + 1*(distinctness, distances)",greedySwap,200,2,80,10.003441083000325,-76.19767611430132
"Uni-criterion: distinctness, distances",greedyMixed,200,2,32,0.06363425000017742,-42.57843298944509
"Uni-criterion: distinctness, distances",greedyMixed,200,2,24,0.04308179100007692,-46.946516069915035
"Uni-criterion: distinctness, distances",greedyMixed,200,2,93,0.19906350000019302,-75.52440490189333
Binary file modified figures/Fig1-designProcess/blend.pdf
Binary file not shown.
Binary file modified figures/Fig1-designProcess/express.pdf
Binary file not shown.
Binary file modified figures/Fig1-designProcess/tune.pdf
Binary file not shown.
12 changes: 10 additions & 2 deletions flexibleSubsetSelection/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@

# --- Logger -------------------------------------------------------------------

def setup(name: str = "flexibleSubsetSelection", level: int = logging.NOTSET):
def setup(name: str = "flexibleSubsetSelection",
level: int = logging.NOTSET) -> logging.Logger:
"""
Sets up the logger for the package.
Sets up logging for the package.
Inputs:
name: The name of the logger, defaults to package level name.
level: The level to set the logger to from Python logging.
Returns:
log: The Python logger object to be used for logging in the package.
"""
log = logging.getLogger(name)
if not log.hasHandlers():
Expand Down
3 changes: 1 addition & 2 deletions flexibleSubsetSelection/loss.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# --- Imports ------------------------------------------------------------------
# --- Imports and Setup --------------------------------------------------------

# Standard library
from functools import partial
import logging
from typing import Any, Callable, Dict, List

# Third party
Expand Down
7 changes: 5 additions & 2 deletions flexibleSubsetSelection/objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,12 @@ def entropy(array: np.ndarray) -> float:
probabilities = np.array(list(counts.values()))/total
return np.sum(probabilities * np.log(probabilities))

from ott.problems.linear import linear_problem

def sinkhorn(subset, fullData, solveFunction):
geometry = pointcloud.PointCloud(fullData, subset)
sinkhornOutput = solveFunction(geometry)
geometry = pointcloud.PointCloud(fullData, subset, epsilon=1)
problem = linear_problem.LinearProblem(geometry)
sinkhornOutput = solveFunction(problem)
return sinkhornOutput.reg_ot_cost


Expand Down
8 changes: 4 additions & 4 deletions flexibleSubsetSelection/sets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# --- Imports ------------------------------------------------------------------
# --- Imports and Setup --------------------------------------------------------

# Standard library
import logging
from pathlib import Path
from typing import Literal

Expand All @@ -20,6 +19,7 @@
# Setup logger
log = logger.setup(name=__name__)


# --- Dataset and Subset Classes -----------------------------------------------

class Set:
Expand Down Expand Up @@ -328,9 +328,9 @@ def __repr__(self) -> str:
"""
string = f"Subset(size={self.size}"
if self.solveTime is not None:
string = ", ".join(string, f"time={round(self.solveTime, 4)}s")
string = ", ".join(string, f"time={self.solveTime:.4f}s")
if self.loss is not None:
string = ", ".join(string, f"loss={round(self.loss, 4)})")
string = ", ".join(string, f"loss={self.loss:.4f})")
return string

def __str__(self) -> str:
Expand Down
12 changes: 6 additions & 6 deletions flexibleSubsetSelection/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ def __init__(self):
self._startTime = None

def start(self):
"""Start a new timer"""
"""Start a new timer."""
if self._startTime is not None:
raise TimerError(f"Timer is running. Use .stop() to stop it")
raise TimerError(f"Timer is running. Use .stop() to stop it.")

self._startTime = time.perf_counter()

def stop(self) -> None:
"""Stop the timer, and return the elapsed time"""
"""Stop the timer, and return the elapsed time."""
if self._startTime is None:
raise TimerError(f"Timer is not running. Use .start() to start it")
raise TimerError(f"Timer is not running. Use .start() to start it.")

self.elapsedTime = time.perf_counter() - self._startTime
self._startTime = None

def __enter__(self):
"""Start a new timer as a context manager"""
"""Start a new timer as a context manager."""
self.start()
return self

def __exit__(self, *exc_info):
"""Stop the context manager timer"""
"""Stop the context manager timer."""
self.stop()

0 comments on commit b0ad7cb

Please sign in to comment.