Skip to content

Commit

Permalink
Added PyTorch Geometric! bumped to v0.7.39
Browse files Browse the repository at this point in the history
Also fixed bug in Wire.Skeleton
  • Loading branch information
wassimj committed Aug 8, 2024
1 parent bbf21be commit bece2ea
Show file tree
Hide file tree
Showing 13 changed files with 5,122 additions and 101 deletions.
3,028 changes: 3,028 additions & 0 deletions notebooks/PyG_BGR_Classification.ipynb

Large diffs are not rendered by default.

20 changes: 2 additions & 18 deletions src/topologicpy/ANN.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,27 +471,11 @@ def DatasetBySampleName(name):
----------
name : str
The name of the dataset. This can be one of ['breast_cancer', 'california_housing', 'digits', 'iris', 'wine']
trainRatio : float , optional
The ratio of the data to use for training and validation vs. the ratio to use for testing. The default is 0.6
which means that 60% of the data will be used for training and validation while 40% of the data will be reserved for testing.
randomState : int , optional
The randomState parameter is used to ensure reproducibility of the results. When you set the randomState parameter to a specific integer value,
it controls the shuffling of the data before splitting it into training and testing sets.
This means that every time you run your code with the same randomState value and the same dataset, you will get the same split of the data.
The default is 42 which is just a randomly picked integer number. Specify None for random sampling.
Returns
-------
dict
Returns the following dictionary:
XTrain, XTest, yTrain, yTest, inputSize, outputSize
XTrain is the list of features used for training
XTest is the list of features used for testing
yTrain is the list of targets used for training
yTest is the list of targets used for testing
inputSize is the size (length) of the input
outputSize is the size (length) of the output
sklearn.utils._bunch.Bunch
The created dataset.
"""
# Load dataset
if name == 'breast_cancer':
Expand Down
12 changes: 4 additions & 8 deletions src/topologicpy/Face.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,8 @@ def ByThickenedWire(wire, offsetA: float = 1.0, offsetB: float = 0.0, tolerance:
Returns
-------
topologic_core.Cell
The created cell.
topologic_core.Face
The created face.
"""
from topologicpy.Vertex import Vertex
Expand Down Expand Up @@ -2170,19 +2170,15 @@ def Squircle(origin = None, radius: float = 0.5, sides: int = 121, a: float = 2.
origin : topologic_core.Vertex , optional
The location of the origin of the squircle. The default is None which results in the squircle being placed at (0, 0, 0).
radius : float , optional
The radius of the squircle. The default is 0.5.
The desired radius of the squircle. The default is 0.5.
sides : int , optional
The number of sides of the squircle. The default is 121.
The desired number of sides of the squircle. The default is 121.
a : float , optional
The "a" factor affects the x position of the points to interpolate between a circle and a square.
A value of 1 will create a circle. Higher values will create a more square-like shape. The default is 2.0.
b : float , optional
The "b" factor affects the y position of the points to interpolate between a circle and a square.
A value of 1 will create a circle. Higher values will create a more square-like shape. The default is 2.0.
radius : float , optional
The desired radius of the squircle. The default is 0.5.
sides : int , optional
The desired number of sides for the squircle. The default is 100.
direction : list , optional
The vector representing the up direction of the circle. The default is [0, 0, 1].
placement : str , optional
Expand Down
8 changes: 5 additions & 3 deletions src/topologicpy/Graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -4686,6 +4686,8 @@ def ExportToAdjacencyMatrixCSV(adjacencyMatrix, path):
Parameters
----------
adjacencyMatrix: list
The input adjacency matrix.
path : str
The desired path to the output folder where the graphs, edges, and nodes CSV files will be saved.
Expand Down Expand Up @@ -4936,7 +4938,6 @@ def ExportToCSV(graph, path, graphLabel, graphFeatures="",
The desired graph label column header. The default is "label".
graphFeaturesHeader : str , optional
The desired graph features column header. The default is "feat".
edgeLabelKey : str , optional
The edge label dictionary key saved in each graph edge. The default is "label".
defaultEdgeLabel : int , optional
Expand Down Expand Up @@ -4971,7 +4972,6 @@ def ExportToCSV(graph, path, graphLabel, graphFeatures="",
This value is ignored if an edgeMaskKey is foud.
bidirectional : bool , optional
If set to True, a reversed edge will also be saved for each edge in the graph. Otherwise, it will not. The default is True.
nodeFeaturesKeys : list , optional
The list of features keys saved in the dicitonaries of nodes. The default is [].
nodeLabelKey : str , optional
Expand Down Expand Up @@ -7444,7 +7444,7 @@ def PyvisGraph(graph, path, overwrite: bool = True, height: int = 900, backgroun
The desired default vertex size. The default is 6.
vertexSizeKey : str , optional
If not set to None, the vertex size will be derived from the dictionary value set at this key. If set to "degree", the size of the vertex will be determined by its degree (number of neighbors). The default is None.
vertexColor : int , optional
vertexColor : str , optional
The desired default vertex color. his can be a named color or a hexadecimal value. The default is 'black'.
vertexColorKey : str , optional
If not set to None, the vertex color will be derived from the dictionary value set at this key. The default is None.
Expand Down Expand Up @@ -7884,6 +7884,8 @@ def Show(graph, vertexColor="black", vertexSize=6, vertexLabelKey=None, vertexGr
The dictionary key to use to display the edge label. The default is None.
edgeGroupKey : str , optional
The dictionary key to use to display the edge group. The default is None.
edgeGroups : list , optional
The list of edge groups against which to index the color of the edge. The default is [].
showEdges : bool , optional
If set to True the edges will be drawn. Otherwise, they will not be drawn. The default is True.
showEdgeLegend : bool , optional
Expand Down
2 changes: 0 additions & 2 deletions src/topologicpy/Grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,6 @@ def VerticesByParameters(face=None, uRange=[0.0,0.25,0.5,0.75,1.0], vRange=[0.0,
----------
face : topologic_core.Face , optional
The input face. If set to None, the grid will be created on the XY plane. The default is None.
origin : topologic_core.Vertex , optional
The origin of the grid vertices. If set to None: if the face is set, the origin will be set to vertex at the face's 0,0 paratmer. If the face is set to None, the origin will be set to (0, 0, 0). The default is None.
uRange : list , optional
A list of *u* parameters for the *u* grid lines from the uOrigin. The default is [0.0,0.25,0.5,0.75,1.0].
vRange : list , optional
Expand Down
34 changes: 0 additions & 34 deletions src/topologicpy/Helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,40 +163,6 @@ def onestep(cur,y,base):
iterated_list.append(y)
return iterated_list

@staticmethod
def K_Means(data, k=4, maxIterations=100):
import random
def euclidean_distance(p, q):
return sum((pi - qi) ** 2 for pi, qi in zip(p, q)) ** 0.5

# Initialize k centroids randomly
centroids = random.sample(data, k)

for _ in range(maxIterations):
# Assign each data point to the nearest centroid
clusters = [[] for _ in range(k)]
for point in data:
distances = [euclidean_distance(point, centroid) for centroid in centroids]
nearest_centroid_index = distances.index(min(distances))
clusters[nearest_centroid_index].append(point)

# Compute the new centroids as the mean of the points in each cluster
new_centroids = []
for cluster in clusters:
if not cluster:
# If a cluster is empty, keep the previous centroid
new_centroids.append(centroids[clusters.index(cluster)])
else:
new_centroids.append([sum(dim) / len(cluster) for dim in zip(*cluster)])

# Check if the centroids have converged
if new_centroids == centroids:
break

centroids = new_centroids

return {'clusters': clusters, 'centroids': centroids}

@staticmethod
def MergeByThreshold(listA, threshold=0.0001):
"""
Expand Down
8 changes: 5 additions & 3 deletions src/topologicpy/Neo4j.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def randomVertex(vertices, minDistance):
return Graph.ByVerticesEdges(vertices,edges)

@staticmethod
def AddGraph(neo4jGraph, graph, labelKey=None, relationshipKey=None, bidirectional=True, deleteAll=True, mantissa: int = 6, tolerance: float = 0.0001):
def AddGraph(neo4jGraph, graph, labelKey=None, relationshipKey=None, mantissa: int = 6, tolerance: float = 0.0001):
"""
Adds the input topologic graph to the input neo4j graph
Expand All @@ -286,8 +286,10 @@ def AddGraph(neo4jGraph, graph, labelKey=None, relationshipKey=None, bidirection
The input neo4j graph.
graph : topologic_core.Graph
The input topologic graph.
categoryKey : str
The category key in the dictionary under which to look for the category value.
labelKey : str , optional
The label key in the dictionary under which to look for the label value.
relationshipKey: str , optional
The relationship key in the dictionary under which to look for the relationship value.
mantissa : int, optional
The desired length of the mantissa. The default is 6.
tolerance : float , optional
Expand Down
6 changes: 5 additions & 1 deletion src/topologicpy/Polyskel.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ def intersect(self, other):
return None # Rays are parallel and do not intersect

# Calculate the intersection point using vector algebra
t = (other.p - self.p).cross(other.v) / self.v.cross(other.v)
denom = self.v.cross(other.v)
if not denom == 0:
t = (other.p - self.p).cross(other.v) / self.v.cross(other.v)
else:
return None
if t >= 0:
return self.p + self.v * t # Intersection point
else:
Expand Down
Loading

0 comments on commit bece2ea

Please sign in to comment.