Skip to content

Commit

Permalink
Fix logging level setting bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cbbcbail committed Oct 10, 2024
1 parent 2fcf178 commit 88d0a93
Show file tree
Hide file tree
Showing 17 changed files with 4,234 additions and 69 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.
19 changes: 19 additions & 0 deletions data/solverData.csv
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,22 @@ Uni-criterion: clusterCenters,greedySwap,1000,2,10,0.13878262508660555,0.7724079
"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
"Uni-criterion: preserveMetric, hull",greedyMinSubset,200,2,9,0.21874955005478114,0.0
"Uni-criterion: sum, outlierness",greedySwap,200,2,40,0.07826007495168597,-90.13755098825027
"Uni-criterion: distinctness, distances",greedySwap,200,2,60,0.37014091794844717,-79.50227671177676
"Multi-criterion: 100*(earthMoversDistance) + 1*(distinctness, distances)",greedySwap,200,2,80,15.73197605391033,-32.55223216743509
"Multi-criterion: 10*(earthMoversDistance) + 1*(distinctness, distances)",greedySwap,200,2,80,16.175244768033735,-76.96445453840944
"Multi-criterion: 1*(earthMoversDistance) + 1*(distinctness, distances)",greedySwap,200,2,80,17.552692768978886,-83.85905074849741
"Uni-criterion: distinctness, distances",greedyMixed,200,2,20,0.10706425900571048,-48.77689734061066
"Uni-criterion: distinctness, distances",greedyMixed,200,2,34,0.17249133007135242,-58.143885051562634
"Uni-criterion: distinctness, distances",greedyMixed,200,2,44,0.22814954188652337,-70.88814419477815
"Uni-criterion: sum, outlierness",greedySwap,200,2,40,0.036993279005400836,-75.42053427241072
"Uni-criterion: preserveMetric, hull",greedyMinSubset,200,2,12,0.27527309604920447,0.0
"Uni-criterion: preserveMetric, hull",greedyMinSubset,200,2,7,0.203717328957282,0.0
"Uni-criterion: preserveMetric, hull",greedyMinSubset,200,2,9,0.25889185711275786,0.0
"Uni-criterion: preserveMetric, hull",greedyMinSubset,200,2,9,0.2248084848979488,0.0
"Uni-criterion: preserveMetric, hull",greedyMinSubset,200,2,8,0.2031262150267139,0.0
"Uni-criterion: sum, outlierness",greedySwap,200,2,40,0.035176230943761766,-66.43006587269934
"Uni-criterion: preserveMetric, hull",greedyMinSubset,200,2,7,0.1945001189596951,0.0
"Uni-criterion: preserveMetric, hull",greedyMinSubset,200,2,7,0.18785801599733531,0.0
"Uni-criterion: preserveMetric, hull",greedyMinSubset,200,2,7,0.234673575963825,0.0
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.
10 changes: 5 additions & 5 deletions flexibleSubsetSelection/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def setup(name: str = "flexibleSubsetSelection",
if not log.hasHandlers():
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(level)
formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s: %(message)s'
)
formatString = '%(asctime)s - %(name)s - %(levelname)s: %(message)s'
formatter = logging.Formatter(formatString)
handler.setFormatter(formatter)
log.addHandler(handler)
log.setLevel(level)
log.propagate = False

log.setLevel(level)
log.propagate = False
return log
43 changes: 1 addition & 42 deletions flexibleSubsetSelection/objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

# Third party
import ot
from ott.geometry import pointcloud

import numpy as np
from numpy.typing import ArrayLike
Expand Down Expand Up @@ -157,44 +156,4 @@ def entropy(array: np.ndarray) -> float:
counts = Counter(map(tuple, array))
total = sum(counts.values())
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, epsilon=1)
problem = linear_problem.LinearProblem(geometry)
sinkhornOutput = solveFunction(problem)
return sinkhornOutput.reg_ot_cost


import numpy as np
from scipy.spatial import distance

def compute_cost_matrix_chunked(dataset_array, subset_array, chunk_size=1000):
num_dataset = dataset_array.shape[0]
num_subset = subset_array.shape[0]
C = np.zeros((num_dataset, num_subset), dtype=np.float32)

# Compute distance in chunks
for i in range(0, num_dataset, chunk_size):
end_i = min(i + chunk_size, num_dataset)
C[i:end_i, :] = distance.cdist(dataset_array[i:end_i], subset_array, metric='euclidean')

return C

# Compute the cost matrix in chunks

def potSinkhorn(subset, fullData):
C = compute_cost_matrix_chunked(fullData, subset, chunk_size=1000)
C = C / np.max(C)

reg = 0.01 # Regularization parameter
a = np.ones(len(fullData)) / len(fullData)
b = np.ones(len(subset)) / len(subset)

transport_plan = ot.bregman.sinkhorn(a, b, C, reg,
method="greenkhorn",
stopThr=1e-3,
verbose=True)
return np.sum(transport_plan * C)
return np.sum(probabilities * np.log(probabilities))
Loading

0 comments on commit 88d0a93

Please sign in to comment.