Skip to content

Instantly share code, notes, and snippets.

View joaofig's full-sized avatar

João Paulo Figueira joaofig

View GitHub Profile
@joaofig
joaofig / create_geodataframe.py
Created August 19, 2018 14:51
Create GeoDataFrame
# Create the GeoDataFrame from the cluster numbers and blobs
data = { 'cluster': clusters, 'polygon': blobs, 'count': counts }
cluster_gdf = gpd.GeoDataFrame(pd.DataFrame(data), geometry='polygon')
cluster_gdf.crs = {'init': 'epsg:4326'}
ax = cluster_gdf.geometry.plot(linewidth=2.0, color='red', edgecolor='red')
@joaofig
joaofig / show_mplleaflet_map.py
Created August 19, 2018 14:53
Show leaflet map
import mplleaflet
mplleaflet.show(fig=ax.figure, tiles='cartodb_positron')
@joaofig
joaofig / RiddleTorch_fit1.py
Created October 13, 2018 17:52
Start of the torched fit function
def fit(self, s_k):
if not torch.is_tensor(s_k):
raise ValueError('s_k must be a torch tensor.')
item_count = s_k.size()[0]
k_k = torch.arange(0, item_count, dtype=torch.float32)
r_k = torch.ones_like(s_k)
r_k[1:] = 1.0 / s_k[1:]
d_k = (r_k[2:] - r_k[1:-1]) / torch.log(k_k[2:])
@joaofig
joaofig / RiddleTorch_calculate_determination.py
Created October 13, 2018 17:56
Calculate the factor of determination
def calculate_determination(self, y, y_hat):
y_np = y.numpy() if torch.is_tensor(y) else y
y_bar = np.sum(y_np) / len(y_np)
ssreg = np.sum((y_hat - y_bar) ** 2)
sstot = np.sum((y_np - y_bar) ** 2)
r2 = ssreg / sstot
return r2
@joaofig
joaofig / RiddleTorch_calculate_y_hat.py
Created October 13, 2018 18:02
Calculates the estimated y values for a quadratic function
def calculate_y_hat(self, x, y):
xx, yy = x, y
if torch.is_tensor(x):
xx = x.numpy()
if torch.is_tensor(y):
yy = y.numpy()
coefficients = np.polyfit(xx, yy, 2)
polynomial = np.poly1d(coefficients)
y_hat = polynomial(xx)
return y_hat
def calculate_r2(self, x, y):
y_hat = self.calculate_y_hat(x, y)
r2 = self.calculate_determination(y, y_hat)
return r2
def fit(self, s_k):
if not torch.is_tensor(s_k):
raise ValueError('s_k must be a torch tensor.')
item_count = s_k.size()[0]
k_k = torch.arange(0, item_count, dtype=torch.float32)
r_k = torch.ones_like(s_k)
r_k[1:] = 1.0 / s_k[1:]
d_k = (r_k[2:] - r_k[1:-1]) / torch.log(k_k[2:])
@joaofig
joaofig / ShowHotSpots.py
Created October 26, 2018 09:20
Create a concave hull from a set of points
# Create the concave hull object
concave_hull = ConcaveHull(points)
# Calculate the concave hull array
hull_array = concave_hull.calculate()
@joaofig
joaofig / ShowHotSpots.py
Created October 26, 2018 09:22
Create a concave hull
# Create the concave hull object
concave_hull = ConcaveHull(points)
# Calculate the concave hull array
hull_array = concave_hull.calculate()
@joaofig
joaofig / ShowHotSpots_1.py
Created October 26, 2018 09:23
Create a concave hull from a set of points
# Create the concave hull object
concave_hull = ConcaveHull(points)
# Calculate the concave hull array
hull_array = concave_hull.calculate()