-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4db7ef
commit 4eaaa9a
Showing
8 changed files
with
456 additions
and
1,090 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,62 @@ | ||
from torch.utils.data import Dataset | ||
from typing import Dict, List | ||
|
||
import torch | ||
from torch.utils.data import Dataset | ||
|
||
|
||
class ZoningDataset(Dataset): | ||
def __init__(self, categorical, continuous, standardization_dictionary=None, index_dictionary=None): | ||
def __init__( | ||
self, | ||
categorical, | ||
continuous, | ||
standardization_dictionary=None, | ||
index_dictionary=None, | ||
): | ||
self.categorical = categorical | ||
self.continuous = continuous | ||
|
||
if index_dictionary is None: | ||
self.index_dictionary = { | ||
"zoning_ordering" : ['downtown', 'blue_zone', 'yellow_zone', 'other_non_university'], | ||
"limit_ordering" : ['eliminated', 'reduced', 'full'] | ||
"zoning_ordering": [ | ||
"downtown", | ||
"blue_zone", | ||
"yellow_zone", | ||
"other_non_university", | ||
], | ||
"limit_ordering": ["eliminated", "reduced", "full"], | ||
} | ||
|
||
self.standardization_dictionary = standardization_dictionary | ||
|
||
categorical_levels = dict() | ||
if self.categorical: | ||
self.categorical_levels = dict() | ||
for name in self.categorical.keys(): | ||
self.categorical_levels[name] = torch.unique(categorical[name]) | ||
|
||
def __len__(self): | ||
return len(self.categorical['parcel_id']) | ||
return len(self.categorical["parcel_id"]) | ||
|
||
def __getitem__(self, idx): | ||
cat_data = {key: val[idx] for key, val in self.categorical.items()} | ||
cont_data = {key: val[idx] for key, val in self.continuous.items()} | ||
return {'categorical': cat_data, 'continuous': cont_data,} | ||
|
||
return { | ||
"categorical": cat_data, | ||
"continuous": cont_data, | ||
} | ||
|
||
|
||
def select_from_data(data, kwarg_names: Dict["str", List["str"]]): | ||
_data = {} | ||
_data["outcome"] = data["continuous"][kwarg_names["outcome"]] | ||
_data["categorical"] = { | ||
key: val | ||
for key, val in data["categorical"].items() | ||
if key in kwarg_names["categorical"] | ||
} | ||
_data["continuous"] = { | ||
key: val | ||
for key, val in data["continuous"].items() | ||
if key in kwarg_names["continuous"] | ||
} | ||
|
||
return _data |
Oops, something went wrong.