topologicpy 0.8.98__py3-none-any.whl → 0.8.99__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- topologicpy/ANN.py +1 -1
- topologicpy/Aperture.py +1 -1
- topologicpy/BVH.py +1 -1
- topologicpy/CSG.py +1 -1
- topologicpy/Cell.py +1 -1
- topologicpy/CellComplex.py +1 -1
- topologicpy/Cluster.py +1 -1
- topologicpy/Color.py +1 -1
- topologicpy/Context.py +1 -1
- topologicpy/DGL.py +1 -1
- topologicpy/Dictionary.py +92 -1
- topologicpy/Edge.py +1 -1
- topologicpy/EnergyModel.py +1 -1
- topologicpy/Face.py +1 -1
- topologicpy/Graph.py +887 -4
- topologicpy/Grid.py +1 -1
- topologicpy/Helper.py +1 -1
- topologicpy/Honeybee.py +1 -1
- topologicpy/Matrix.py +1 -1
- topologicpy/Neo4j.py +1 -1
- topologicpy/Plotly.py +1 -1
- topologicpy/Polyskel.py +1 -1
- topologicpy/PyG.py +1287 -2308
- topologicpy/ShapeGrammar.py +1 -1
- topologicpy/Shell.py +1 -1
- topologicpy/Speckle.py +1 -1
- topologicpy/Sun.py +1 -1
- topologicpy/Topology.py +1 -1
- topologicpy/Vector.py +1 -1
- topologicpy/Vertex.py +1 -1
- topologicpy/Wire.py +1 -1
- topologicpy/__init__.py +1 -1
- topologicpy/version.py +1 -1
- {topologicpy-0.8.98.dist-info → topologicpy-0.8.99.dist-info}/METADATA +1 -1
- topologicpy-0.8.99.dist-info/RECORD +39 -0
- topologicpy-0.8.98.dist-info/RECORD +0 -39
- {topologicpy-0.8.98.dist-info → topologicpy-0.8.99.dist-info}/WHEEL +0 -0
- {topologicpy-0.8.98.dist-info → topologicpy-0.8.99.dist-info}/licenses/LICENSE +0 -0
- {topologicpy-0.8.98.dist-info → topologicpy-0.8.99.dist-info}/top_level.txt +0 -0
topologicpy/ANN.py
CHANGED
topologicpy/Aperture.py
CHANGED
topologicpy/BVH.py
CHANGED
topologicpy/CSG.py
CHANGED
topologicpy/Cell.py
CHANGED
topologicpy/CellComplex.py
CHANGED
topologicpy/Cluster.py
CHANGED
topologicpy/Color.py
CHANGED
topologicpy/Context.py
CHANGED
topologicpy/DGL.py
CHANGED
topologicpy/Dictionary.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright (C)
|
|
1
|
+
# Copyright (C) 2026
|
|
2
2
|
# Wassim Jabi <wassim.jabi@gmail.com>
|
|
3
3
|
#
|
|
4
4
|
# This program is free software: you can redistribute it and/or modify it under
|
|
@@ -1250,6 +1250,97 @@ class Dictionary():
|
|
|
1250
1250
|
|
|
1251
1251
|
return Dictionary.ByMergedDictionaries(dictionaryA, dictionaryB)
|
|
1252
1252
|
|
|
1253
|
+
|
|
1254
|
+
@staticmethod
|
|
1255
|
+
def OneHotEncode(d, keys, categoriesByKey, silent=False):
|
|
1256
|
+
"""
|
|
1257
|
+
One-hot encodes multiple categorical dictionary values in one pass. See https://en.wikipedia.org/wiki/One-hot
|
|
1258
|
+
|
|
1259
|
+
Parameters
|
|
1260
|
+
----------
|
|
1261
|
+
d : topologic_core.Dictionary
|
|
1262
|
+
The input dictionary.
|
|
1263
|
+
keys : list
|
|
1264
|
+
List of dictionary keys to one-hot encode.
|
|
1265
|
+
categoriesByKey : dict
|
|
1266
|
+
A dictionary mapping each key (str) to an ordered list of categories (list).
|
|
1267
|
+
Example:
|
|
1268
|
+
{
|
|
1269
|
+
"room_type": ["Kitchen","Bedroom","WC"],
|
|
1270
|
+
"zone": ["Public","Private"]
|
|
1271
|
+
}
|
|
1272
|
+
silent : bool , optional
|
|
1273
|
+
If True, suppress warnings. Default is False.
|
|
1274
|
+
|
|
1275
|
+
Returns
|
|
1276
|
+
-------
|
|
1277
|
+
topologic_core.Dictionary
|
|
1278
|
+
A new dictionary where each original key in `keys` is removed (if present)
|
|
1279
|
+
and replaced with one-hot encoded keys:
|
|
1280
|
+
"<key>_0", "<key>_1", ...
|
|
1281
|
+
"""
|
|
1282
|
+
|
|
1283
|
+
from topologicpy.Dictionary import Dictionary
|
|
1284
|
+
from topologicpy.Topology import Topology
|
|
1285
|
+
|
|
1286
|
+
if not Topology.IsInstance(d, "Dictionary"):
|
|
1287
|
+
if not silent:
|
|
1288
|
+
print("Dictionary.OneHotEncode - Error: Input is not a valid Dictionary.")
|
|
1289
|
+
return None
|
|
1290
|
+
|
|
1291
|
+
if keys is None:
|
|
1292
|
+
if not silent:
|
|
1293
|
+
print("Dictionary.OneHotEncode - Error: keys is None.")
|
|
1294
|
+
return None
|
|
1295
|
+
|
|
1296
|
+
keys = list(keys)
|
|
1297
|
+
if len(keys) == 0:
|
|
1298
|
+
return d
|
|
1299
|
+
|
|
1300
|
+
if not isinstance(categoriesByKey, dict):
|
|
1301
|
+
if not silent:
|
|
1302
|
+
print("Dictionary.OneHotEncode - Error: categoriesByKey must be a dict mapping key -> categories.")
|
|
1303
|
+
return None
|
|
1304
|
+
|
|
1305
|
+
# Read original dictionary once
|
|
1306
|
+
orig_keys = Dictionary.Keys(d)
|
|
1307
|
+
orig_vals = [Dictionary.ValueAtKey(d, k) for k in orig_keys]
|
|
1308
|
+
|
|
1309
|
+
# Build a quick index for deletions/updates
|
|
1310
|
+
orig_index = {k: i for i, k in enumerate(orig_keys)}
|
|
1311
|
+
|
|
1312
|
+
# Determine which keys to remove and capture their values
|
|
1313
|
+
values_by_key = {}
|
|
1314
|
+
for k in keys:
|
|
1315
|
+
if k in orig_index:
|
|
1316
|
+
values_by_key[k] = orig_vals[orig_index[k]]
|
|
1317
|
+
else:
|
|
1318
|
+
values_by_key[k] = None
|
|
1319
|
+
|
|
1320
|
+
# Remove requested keys (preserving order of remaining items)
|
|
1321
|
+
remove_set = set(keys)
|
|
1322
|
+
out_keys = []
|
|
1323
|
+
out_vals = []
|
|
1324
|
+
for k, v in zip(orig_keys, orig_vals):
|
|
1325
|
+
if k not in remove_set:
|
|
1326
|
+
out_keys.append(k)
|
|
1327
|
+
out_vals.append(v)
|
|
1328
|
+
|
|
1329
|
+
# Append one-hot encodings for each key in `keys`
|
|
1330
|
+
for k in keys:
|
|
1331
|
+
cats = categoriesByKey.get(k, None)
|
|
1332
|
+
if not isinstance(cats, (list, tuple)) or len(cats) == 0:
|
|
1333
|
+
if not silent:
|
|
1334
|
+
print(f"Dictionary.OneHotEncodeBatch - Warning: No categories provided for key '{k}'. Skipping.")
|
|
1335
|
+
continue
|
|
1336
|
+
|
|
1337
|
+
value = values_by_key.get(k, None)
|
|
1338
|
+
for i, cat in enumerate(cats):
|
|
1339
|
+
out_keys.append(f"{k}_{i}")
|
|
1340
|
+
out_vals.append(1 if value == cat else 0)
|
|
1341
|
+
|
|
1342
|
+
return Dictionary.ByKeysValues(out_keys, out_vals)
|
|
1343
|
+
|
|
1253
1344
|
@staticmethod
|
|
1254
1345
|
def PythonDictionary(dictionary, silent: bool = False):
|
|
1255
1346
|
"""
|
topologicpy/Edge.py
CHANGED
topologicpy/EnergyModel.py
CHANGED
topologicpy/Face.py
CHANGED