topologicpy 0.8.21__py3-none-any.whl → 0.8.22__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/Dictionary.py CHANGED
@@ -773,7 +773,7 @@ class Dictionary():
773
773
  return None
774
774
 
775
775
  @staticmethod
776
- def ValueAtKey(dictionary, key, silent=False):
776
+ def ValueAtKey(dictionary, key, defaultValue=None, silent=False):
777
777
  """
778
778
  Returns the value of the input key in the input dictionary.
779
779
 
@@ -783,6 +783,8 @@ class Dictionary():
783
783
  The input dictionary.
784
784
  key : string
785
785
  The input key.
786
+ defaultValue : any , optional
787
+ The default value to return if the key or value are not found. The default is None.
786
788
  silent : bool , optional
787
789
  If set to True, no error and warning messages are printed. Otherwise, they are. The default is False.
788
790
 
@@ -804,10 +806,10 @@ class Dictionary():
804
806
  return None
805
807
  if Topology.IsInstance(dictionary, "Dictionary"):
806
808
  dic = Dictionary.PythonDictionary(dictionary)
807
- return dic.get(key, None)
809
+ return dic.get(key, defaultValue)
808
810
  elif isinstance(dictionary, dict):
809
- return dictionary.get(key, None)
810
- return None
811
+ return dictionary.get(key, defaultValue)
812
+ return defaultValue
811
813
 
812
814
  # if isinstance(dictionary, dict):
813
815
  # attr = dictionary[key]
topologicpy/Graph.py CHANGED
@@ -4379,12 +4379,17 @@ class Graph:
4379
4379
 
4380
4380
  @staticmethod
4381
4381
  def Compare(graphA, graphB,
4382
- weightAttributes: float = 1.0,
4383
- weightGeometry: float = 1.0,
4384
- weightMetrics: float = 1.0,
4385
- weightStructure: float = 1.0,
4386
- weightWL: float = 1.0,
4387
- weightJaccard: float = 1.0,
4382
+ weightAttributes: float = 0.0,
4383
+ weightGeometry: float = 0.0,
4384
+ weightBetwennessCentrality: float = 0.0,
4385
+ weightClosenessCentrality: float = 0.0,
4386
+ weightDegreeCentrality: float = 0.0,
4387
+ weightDiameter: float = 0.0,
4388
+ weightGlobalClusteringCoefficient: float = 0.0,
4389
+ weightPageRank: float = 0.0,
4390
+ weightStructure: float = 0.0,
4391
+ weightWeisfeilerLehman: float = 0.0,
4392
+ weightJaccard: float = 0.0,
4388
4393
  vertexIDKey: str = "id",
4389
4394
  edgeWeightKey: str = None,
4390
4395
  iterations: int = 3,
@@ -4402,18 +4407,28 @@ class Graph:
4402
4407
  graphB : topologic Graph
4403
4408
  The second input graph.
4404
4409
  weightAttributes : float , optional
4405
- The desired weight for attribute similarity (dictionary key overlap at vertices). Default is 1.0.
4410
+ The desired weight for attribute similarity (dictionary key overlap at vertices). Default is 0.0.
4411
+ weightBetwennessCentrality : float , optional
4412
+ The desired weight for betweenness centrality similarity (graph-level and node-level). Default is 0.0.
4413
+ weightClosenessCentrality : float , optional
4414
+ The desired weight for closeness centrality similarity (graph-level and node-level). Default is 0.0.
4415
+ weightDegreeCentrality : float , optional
4416
+ The desired weight for degree centrality similarity (graph-level and node-level). Default is 0.0.
4417
+ weightDiameter : float , optional
4418
+ The desired weight for diameter similarity (graph-level and node-level). Default is 0.0.
4406
4419
  weightGeometry : float , optional
4407
- The desired weight for geometric similarity (vertex positions). Default is 1.0.
4408
- weightMetrics : float , optional
4409
- The desired weight for metric similarity (graph-level and node-level). Default is 1.0.
4410
- The compared metrics are: betweenness centrality, closeness centrality, clustering coefficient, degree, diameter, and pagerank.
4411
- weightStructure : float , optional
4412
- The desired weight for structural similarity (number of vertices and edges). Default is 1.0.
4413
- weightWL : float , optional
4414
- The desired weight for Weisfeiler-Lehman kernel similarity (iterative label propagation). Default is 1.0.
4420
+ The desired weight for geometric similarity (vertex positions). Default is 0.0.
4421
+ weightGlobalClusteringCoefficient : float , optional
4422
+ The desired weight for global clustering coefficient similarity (graph-level and node-level). Default is 0.0.
4415
4423
  weightJaccard: float , optional
4416
- The desired weight for the Weighted Jaccard similarity. Default is 1.0.
4424
+ The desired weight for the Weighted Jaccard similarity. Default is 0.0.
4425
+ weightPageRank : float , optional
4426
+ The desired weight for PageRank similarity (graph-level and node-level). Default is 0.0.
4427
+ weightStructure : float , optional
4428
+ The desired weight for structural similarity (number of vertices and edges). Default is 0.0.
4429
+ weightWeisfeilerLehman : float , optional
4430
+ The desired weight for Weisfeiler-Lehman kernel similarity (iterative label propagation). Default is 0.0.
4431
+
4417
4432
  vertexIDKey: str , optional
4418
4433
  The dictionary key under which to find the unique vertex ID. The default is "id".
4419
4434
  edgeWeightKey: str , optional
@@ -4433,12 +4448,16 @@ class Graph:
4433
4448
  A dictionary of similarity scores between 0 (completely dissimilar) and 1 (identical), based on weighted components.
4434
4449
  The keys in the dictionary are:
4435
4450
  "attribute"
4451
+ "betwenness_centrality"
4452
+ "closeness_centrality"
4453
+ "degree_centrality"
4436
4454
  "geometry"
4437
- "metrics"
4455
+ "global_clustering_coefficient"
4456
+ "jaccard"
4457
+ "pagerank"
4438
4458
  "structure"
4439
- "wl"
4459
+ "weisfeiler_lehman"
4440
4460
  "overall"
4441
-
4442
4461
  """
4443
4462
 
4444
4463
  import hashlib
@@ -4551,40 +4570,56 @@ class Graph:
4551
4570
 
4552
4571
  return numerator / denominator if denominator > 0 else 0.0
4553
4572
 
4554
- def metrics_similarity(graphA, graphB, mantissa=6):
4555
- # Example using global metrics + mean of node metrics
4556
- def safe_mean(lst):
4573
+ def safe_mean(lst):
4557
4574
  return sum(lst)/len(lst) if lst else 0
4558
-
4559
- metrics1 = {
4560
- "closeness": safe_mean(Graph.ClosenessCentrality(graphA)),
4561
- "betweenness": safe_mean(Graph.BetweennessCentrality(graphA)),
4562
- "degree": safe_mean(Graph.DegreeCentrality(graphA)),
4563
- "pagerank": safe_mean(Graph.PageRank(graphA)),
4564
- "clustering": Graph.GlobalClusteringCoefficient(graphA),
4565
- "diameter": Graph.Diameter(graphA)
4566
- }
4567
-
4568
- metrics2 = {
4569
- "closeness": safe_mean(Graph.ClosenessCentrality(graphB)),
4570
- "betweenness": safe_mean(Graph.BetweennessCentrality(graphB)),
4571
- "degree": safe_mean(Graph.DegreeCentrality(graphB)),
4572
- "pagerank": safe_mean(Graph.PageRank(graphB)),
4573
- "clustering": Graph.GlobalClusteringCoefficient(graphB),
4574
- "diameter": Graph.Diameter(graphB)
4575
- }
4576
-
4577
- # Compute similarity as 1 - normalized absolute difference
4578
- similarities = []
4579
- for key in metrics1:
4580
- v1, v2 = metrics1[key], metrics2[key]
4581
- if v1 == 0 and v2 == 0:
4582
- similarities.append(1)
4583
- else:
4584
- diff = abs(v1 - v2) / max(abs(v1), abs(v2), 1e-6)
4585
- similarities.append(1 - diff)
4586
-
4587
- return round(sum(similarities) / len(similarities), mantissa)
4575
+
4576
+ def betweenness_centrality_similarity(graphA, graphB, mantissa=6):
4577
+ v1 = safe_mean(Graph.BetweennessCentrality(graphA))
4578
+ v2 = safe_mean(Graph.BetweennessCentrality(graphB))
4579
+ if v1 == 0 and v2 == 0:
4580
+ return 1
4581
+ diff = abs(v1 - v2) / max(abs(v1), abs(v2), 1e-6)
4582
+ return round((1 - diff), mantissa)
4583
+
4584
+ def closeness_centrality_similarity(graphA, graphB, mantissa=6):
4585
+ v1 = safe_mean(Graph.ClosenessCentrality(graphA))
4586
+ v2 = safe_mean(Graph.ClosenessCentrality(graphB))
4587
+ if v1 == 0 and v2 == 0:
4588
+ return 1
4589
+ diff = abs(v1 - v2) / max(abs(v1), abs(v2), 1e-6)
4590
+ return round((1 - diff), mantissa)
4591
+
4592
+ def degree_centrality_similarity(graphA, graphB, mantissa=6):
4593
+ v1 = safe_mean(Graph.DegreeCentrality(graphA))
4594
+ v2 = safe_mean(Graph.DegreeCentrality(graphB))
4595
+ if v1 == 0 and v2 == 0:
4596
+ return 1
4597
+ diff = abs(v1 - v2) / max(abs(v1), abs(v2), 1e-6)
4598
+ return round((1 - diff), mantissa)
4599
+
4600
+ def diameter_similarity(graphA, graphB, mantissa=6):
4601
+ v1 = Graph.Diameter(graphA)
4602
+ v2 = Graph.Diameter(graphB)
4603
+ if v1 == 0 and v2 == 0:
4604
+ return 1
4605
+ diff = abs(v1 - v2) / max(abs(v1), abs(v2), 1e-6)
4606
+ return round((1 - diff), mantissa)
4607
+
4608
+ def global_clustering_coefficient_similarity(graphA, graphB, mantissa=6):
4609
+ v1 = Graph.GlobalClusteringCoefficient(graphA)
4610
+ v2 = Graph.GlobalClusteringCoefficient(graphB)
4611
+ if v1 == 0 and v2 == 0:
4612
+ return 1
4613
+ diff = abs(v1 - v2) / max(abs(v1), abs(v2), 1e-6)
4614
+ return round((1 - diff), mantissa)
4615
+
4616
+ def pagerank_similarity(graphA, graphB, mantissa=6):
4617
+ v1 = safe_mean(Graph.PageRank(graphA))
4618
+ v2 = safe_mean(Graph.PageRank(graphB))
4619
+ if v1 == 0 and v2 == 0:
4620
+ return 1
4621
+ diff = abs(v1 - v2) / max(abs(v1), abs(v2), 1e-6)
4622
+ return round((1 - diff), mantissa)
4588
4623
 
4589
4624
  def structure_similarity(graphA, graphB, mantissa=6):
4590
4625
  v1 = Graph.Vertices(graphA)
@@ -4640,22 +4675,42 @@ class Graph:
4640
4675
  print("Graph.Compare - Error: The graphB input parameter is not a valid topologic graph. Returning None.")
4641
4676
  return
4642
4677
 
4643
- total_weight = weightAttributes + weightGeometry + weightMetrics + weightStructure + weightWL + weightJaccard
4678
+ total_weight = sum([weightAttributes,
4679
+ weightGeometry,
4680
+ weightBetwennessCentrality,
4681
+ weightClosenessCentrality,
4682
+ weightDegreeCentrality,
4683
+ weightDiameter,
4684
+ weightGlobalClusteringCoefficient,
4685
+ weightPageRank,
4686
+ weightStructure,
4687
+ weightWeisfeilerLehman,
4688
+ weightJaccard])
4644
4689
 
4645
4690
  attribute_score = attribute_similarity(graphA, graphB, mantissa=mantissa) if weightAttributes else 0
4691
+ betweenness_centrality_score = betweenness_centrality_similarity(graphA, graphB, mantissa=mantissa) if weightBetwennessCentrality else 0
4692
+ closeness_centrality_score = closeness_centrality_similarity(graphA, graphB, mantissa=mantissa) if weightClosenessCentrality else 0
4693
+ degree_centrality_score = degree_centrality_similarity(graphA, graphB, mantissa=mantissa) if weightDegreeCentrality else 0
4694
+ diameter_score = diameter_similarity(graphA, graphB, mantissa=mantissa) if weightDiameter else 0
4695
+ global_clustering_coefficient_score = global_clustering_coefficient_similarity(graphA, graphB, mantissa=mantissa) if weightGlobalClusteringCoefficient else 0
4646
4696
  geometry_score = geometry_similarity(graphA, graphB, mantissa=mantissa) if weightGeometry else 0
4647
4697
  jaccard_score = weighted_jaccard_similarity(graphA, graphB, vertexIDKey=vertexIDKey, edgeWeightKey=edgeWeightKey, mantissa=mantissa) if weightJaccard else 0
4648
- metrics_score = metrics_similarity(graphA, graphB, mantissa=mantissa) if weightMetrics else 0
4698
+ pagerank_score = pagerank_similarity(graphA, graphB, mantissa=mantissa) if weightPageRank else 0
4649
4699
  structure_score = structure_similarity(graphA, graphB, mantissa=mantissa) if weightStructure else 0
4650
- wl_score = weisfeiler_lehman_similarity(graphA, graphB, iterations, mantissa=mantissa) if weightWL else 0
4700
+ weisfeiler_lehman_score = weisfeiler_lehman_similarity(graphA, graphB, iterations, mantissa=mantissa) if weightWeisfeilerLehman else 0
4651
4701
 
4652
4702
  weighted_sum = (
4653
4703
  attribute_score * weightAttributes +
4704
+ betweenness_centrality_score * weightBetwennessCentrality +
4705
+ closeness_centrality_score * weightClosenessCentrality +
4706
+ degree_centrality_score * weightDegreeCentrality +
4707
+ diameter_score * weightDiameter +
4654
4708
  geometry_score * weightGeometry +
4709
+ global_clustering_coefficient_score * weightGlobalClusteringCoefficient +
4655
4710
  jaccard_score * weightJaccard +
4656
- metrics_score * weightMetrics +
4711
+ pagerank_score * weightPageRank +
4657
4712
  structure_score * weightStructure +
4658
- wl_score * weightWL
4713
+ weisfeiler_lehman_score * weightWeisfeilerLehman
4659
4714
  )
4660
4715
 
4661
4716
  if total_weight <= 0:
@@ -4665,11 +4720,15 @@ class Graph:
4665
4720
 
4666
4721
  return {
4667
4722
  "attribute": round(attribute_score, mantissa),
4723
+ "betwenness_centrality": round(betweenness_centrality_score, mantissa),
4724
+ "closeness_centrality": round(closeness_centrality_score, mantissa),
4725
+ "degree_centrality": round(degree_centrality_score, mantissa),
4668
4726
  "geometry": round(geometry_score, mantissa),
4727
+ "global_clustering_coefficient": round(global_clustering_coefficient_score, mantissa),
4669
4728
  "jaccard": round(jaccard_score, mantissa),
4670
- "metrics": round(metrics_score, mantissa),
4729
+ "pagerank": round(pagerank_score, mantissa),
4671
4730
  "structure": round(structure_score, mantissa),
4672
- "wl": round(wl_score, mantissa),
4731
+ "weisfeiler_lehman": round(weisfeiler_lehman_score, mantissa),
4673
4732
  "overall": round(overall_score, mantissa)
4674
4733
  }
4675
4734
 
topologicpy/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = '0.8.21'
1
+ __version__ = '0.8.22'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: topologicpy
3
- Version: 0.8.21
3
+ Version: 0.8.22
4
4
  Summary: An AI-Powered Spatial Modelling and Analysis Software Library for Architecture, Engineering, and Construction.
5
5
  Author-email: Wassim Jabi <wassim.jabi@gmail.com>
6
6
  License: AGPL v3 License
@@ -7,11 +7,11 @@ topologicpy/Cluster.py,sha256=o5jdMRpcGfSGGiXQdFg-e9XcnBF5AqTj3xb1nSpwJWE,58606
7
7
  topologicpy/Color.py,sha256=q9xsGmxFMz7sQKmygwSVS12GaTRB-OT0-_i6t3-cthE,20307
8
8
  topologicpy/Context.py,sha256=ppApYKngZZCQBFWaxIMi2z2dokY23c935IDCBosxDAE,3055
9
9
  topologicpy/DGL.py,sha256=M_znFtyPBJJz-iXLYZs2wwBj24fhevIo739dGha0chM,139041
10
- topologicpy/Dictionary.py,sha256=7h-Gszgnt2OEOvOSADJ4pa-mTNlhQ9cuIiB5WHEW6aY,33949
10
+ topologicpy/Dictionary.py,sha256=TO5Ar9j_xUSV325MYbUHdNrKfgo9VcehcZCeZWAn6b0,34126
11
11
  topologicpy/Edge.py,sha256=yxkCVDYBflJNEYxnjMmlyvbkpg8TNy7y5bSH3yQ4jzs,71418
12
12
  topologicpy/EnergyModel.py,sha256=UoQ9Jm-hYsN383CbcLKw-y6BKitRHj0uyh84yQ-8ACg,53856
13
13
  topologicpy/Face.py,sha256=SlhB8L7BpDjd4a9YZE4UJ3zoGuF1oq9MSpuesEWro_Q,184847
14
- topologicpy/Graph.py,sha256=Iq2UI-CdW3usxpgxRi-caxQeUmkFfGhD37c6mPT2Gd8,523908
14
+ topologicpy/Graph.py,sha256=c2VvEvEM3hGgFR6xP-A58HXcgEVnPyA_heFOoNZ4p_Y,527640
15
15
  topologicpy/Grid.py,sha256=2s9cSlWldivn1i9EUz4OOokJyANveqmRe_vR93CAndI,18245
16
16
  topologicpy/Helper.py,sha256=4H5KPiv_eiEs489UOOyGLe9RaeoZIfmMh3mk_YCHmXg,29100
17
17
  topologicpy/Honeybee.py,sha256=uDVtDbloydNoaBFcSNukKL_2PLyD6XKkCp1VHz1jtaU,21751
@@ -28,9 +28,9 @@ topologicpy/Vector.py,sha256=GkGt-aJ591IJ2IPffMAudvITLDPi2qZibZc4UAav6m8,42407
28
28
  topologicpy/Vertex.py,sha256=q99IrWwdNlvVfUXz6iP8icmP8NzP2nsiqtgnF9Jnpx8,80913
29
29
  topologicpy/Wire.py,sha256=IVPzBKsckuxC-rHvwxmvtVF7PpApz2lhPHomtQMo_kg,228499
30
30
  topologicpy/__init__.py,sha256=vlPCanUbxe5NifC4pHcnhSzkmmYcs_UrZrTlVMsxcFs,928
31
- topologicpy/version.py,sha256=zZ7tNz8qiJpD43ZZY6gDLsQEo04V3AXFbZKZwwi4Pww,23
32
- topologicpy-0.8.21.dist-info/licenses/LICENSE,sha256=FK0vJ73LuE8PYJAn7LutsReWR47-Ooovw2dnRe5yV6Q,681
33
- topologicpy-0.8.21.dist-info/METADATA,sha256=uin9-ogEkyhyjro0BGZPrFB4abynjZPuv7G3lTk6XzA,10535
34
- topologicpy-0.8.21.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
35
- topologicpy-0.8.21.dist-info/top_level.txt,sha256=J30bDzW92Ob7hw3zA8V34Jlp-vvsfIkGzkr8sqvb4Uw,12
36
- topologicpy-0.8.21.dist-info/RECORD,,
31
+ topologicpy/version.py,sha256=SuLneBfTbTDP--cc9ZcmXl_eRJruqxfxMHpHGiHHHZA,23
32
+ topologicpy-0.8.22.dist-info/licenses/LICENSE,sha256=FK0vJ73LuE8PYJAn7LutsReWR47-Ooovw2dnRe5yV6Q,681
33
+ topologicpy-0.8.22.dist-info/METADATA,sha256=9_VzttjULYoYaVn35tAzKn6Q7cf2l4mfnGKYkOE_tFo,10535
34
+ topologicpy-0.8.22.dist-info/WHEEL,sha256=ooBFpIzZCPdw3uqIQsOo4qqbA4ZRPxHnOH7peeONza0,91
35
+ topologicpy-0.8.22.dist-info/top_level.txt,sha256=J30bDzW92Ob7hw3zA8V34Jlp-vvsfIkGzkr8sqvb4Uw,12
36
+ topologicpy-0.8.22.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.0)
2
+ Generator: setuptools (80.0.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5