Skip to content

Commit

Permalink
Plotting and typing bugfixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbbcbail committed Aug 1, 2024
1 parent 8c3f9dd commit 771a1ce
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 117 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python.analysis.typeCheckingMode": "basic",
"python.analysis.autoImportCompletions": false
}
8 changes: 5 additions & 3 deletions flexibleSubsetSelection/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# --- Utility ------------------------------------------------------------------

def randomSample(datasetSize: tuple, subsetSize: int,
seed: int | np.random.Generator = None):
seed: (int | np.random.Generator | None) = None):
"""
Randomly sample from dataset by generating random indices to create subset
Expand Down Expand Up @@ -46,7 +46,8 @@ def createEnvironment(outputFlag: int = 0):

return environment

def optimize(objective, constraints, environment, solver, log_file='gurobi_log.txt', verbose=False):
def optimize(objective, constraints, environment, solver,
log_file='gurobi_log.txt', verbose=False):
"""
Sets up a cvxpy problem with given objective and constraints and solves it
using the specified solver.
Expand Down Expand Up @@ -99,7 +100,8 @@ def bestOfRandom(dataset, lossFunction, subsetSize, minLoss=0,


def averageOfRandom(dataset, lossFunction, subsetSize, minLoss=0,
maxIterations=None, seed=None, verbose=False, selectBy="row"):
maxIterations=None, seed=None, verbose=False,
selectBy="row"):

if maxIterations is None:
maxIterations = dataset.size[0]
Expand Down
23 changes: 12 additions & 11 deletions flexibleSubsetSelection/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

# --- Random Dataset Generation ------------------------------------------------

def randomData(randType: str | list, size: tuple, interval: tuple,
seed: int | np.random.Generator = None) -> pd.DataFrame:
def randomData(randType: str, size: tuple, interval: tuple,
seed: (int | np.random.Generator | None) = None) -> pd.DataFrame:
"""
Generate random data based on the specified random generation method.
Expand All @@ -31,7 +31,7 @@ def randomData(randType: str | list, size: tuple, interval: tuple,
generators = {
"uniform": uniform,
"binary": binary,
"categorical": categorical,
"categories": categories,
"normal": normal,
"multimodal": multimodal,
"skew": skew,
Expand All @@ -48,7 +48,7 @@ def randomData(randType: str | list, size: tuple, interval: tuple,
raise ValueError(f"unknown random generation method: {randType}")

def uniform(size: tuple, interval: tuple,
seed: int | np.random.Generator = None) -> pd.DataFrame:
seed: (int | np.random.Generator| None) = None) -> pd.DataFrame:
"""
Generate random data from a uniform distribution using numpy.
Expand All @@ -63,7 +63,8 @@ def uniform(size: tuple, interval: tuple,
data = rng.uniform(interval[0], interval[1], size=size)
return pd.DataFrame(data)

def binary(size: tuple, seed: int | np.random.Generator = None) -> pd.DataFrame:
def binary(size: tuple,
seed: (int | np.random.Generator | None) = None) -> pd.DataFrame:
"""
Generate random binary data points of bernoulli trials using numpy where
each feature has a random probability p.
Expand All @@ -79,8 +80,8 @@ def binary(size: tuple, seed: int | np.random.Generator = None) -> pd.DataFrame:
data = rng.binomial(1, probabilities, size=size)
return pd.DataFrame(data)

def categorical(size: tuple, interval: tuple,
seed: int | np.random.Generator = None) -> pd.DataFrame:
def categories(size: tuple, interval: tuple,
seed: (int | np.random.Generator | None) = None) -> pd.DataFrame:
"""
Generate random categorical data points using numpy with a random number of
categories and a random probability p in interval.
Expand All @@ -101,7 +102,7 @@ def categorical(size: tuple, interval: tuple,
return pd.DataFrame(data)

def normal(size: tuple, interval: tuple,
seed: int | np.random.Generator = None) -> pd.DataFrame:
seed: (int | np.random.Generator | None) = None) -> pd.DataFrame:
"""
Generate random data from a normal distribution using numpy centered on
random mean and with random standard deviation.
Expand All @@ -121,7 +122,7 @@ def normal(size: tuple, interval: tuple,
return pd.DataFrame(data)

def multimodal(size: tuple, interval: tuple, sigmaInterval: tuple = (0.1, 3),
seed: int | np.random.Generator = None) -> pd.DataFrame:
seed: (int | np.random.Generator | None) = None) -> pd.DataFrame:
"""
Generate random data from multimodal distributions using numpy with a random
number of normal distributions centered on random means and standard
Expand Down Expand Up @@ -157,7 +158,7 @@ def multimodal(size: tuple, interval: tuple, sigmaInterval: tuple = (0.1, 3),
return pd.DataFrame(data)

def skew(size: tuple, interval: tuple = (-5, 5),
seed: int | np.random.Generator = None) -> pd.DataFrame:
seed: (int | np.random.Generator | None) = None) -> pd.DataFrame:
"""
Generate random data from skewed distributions using scipy with random
skewness parameter.
Expand All @@ -182,7 +183,7 @@ def skew(size: tuple, interval: tuple = (-5, 5),

def blobs(size: tuple, interval: tuple, numClusters: int = 6,
sigmaInterval: tuple = (0.1, 3),
seed: int | np.random.Generator = None) -> pd.DataFrame:
seed: (int | np.random.Generator | None) = None) -> pd.DataFrame:
"""
Generate random data points using sklearn with numClusters blobs and with
random means and standard deviations.
Expand Down
2 changes: 1 addition & 1 deletion flexibleSubsetSelection/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MultiCriterion():

def __init__(self, objectives: List[Callable],
parameters: List[Dict[str, Any]],
weights: ArrayLike = None) -> None:
weights: (np.ndarray | None) = None) -> None:
"""
Define a multi-criterion loss function with a set of objectives,
weights, and parameters
Expand Down
Loading

0 comments on commit 771a1ce

Please sign in to comment.