Skip to content

Instantly share code, notes, and snippets.

View petrosDemetrakopoulos's full-sized avatar

Petros Demetrakopoulos petrosDemetrakopoulos

View GitHub Profile
@petrosDemetrakopoulos
petrosDemetrakopoulos / preciptiation_prediction_model.py
Last active December 17, 2022 15:41
Precipitation prediction model
def create_model():
model = Sequential()
model.add(ConvLSTM2D(filters=64, kernel_size=(7, 7),
input_shape=(18,344,315,1),
padding='same',activation=LeakyReLU(alpha=0.01), return_sequences=True))
model.add(BatchNormalization())
model.add(ConvLSTM2D(filters=64, kernel_size=(5, 5),
padding='same',activation=LeakyReLU(alpha=0.01), return_sequences=True))
model.add(BatchNormalization())
model.add(ConvLSTM2D(filters=64, kernel_size=(3, 3),
@petrosDemetrakopoulos
petrosDemetrakopoulos / radar_data_preprocessing.py
Created December 17, 2022 15:11
Radar data preprocessing
def create_dataset_from_raw(directory_path, resize_to):
resize_width = resize_to[0]
resize_height = resize_to[1]
batch_names = [directory_path + name for name in os.listdir(directory_path) if os.path.isdir(os.path.join(directory_path, name))]
dataset = np.zeros(shape=(len(batch_names),36,resize_height,resize_width)) # (samples, filters, rows = height, cols = width)
for batch_idx,batch in enumerate(batch_names):
files = [x for x in os.listdir(batch) if x != '.DS_Store']
files.sort()
crn_batch = np.zeros(shape=(36, resize_height, resize_width))
@petrosDemetrakopoulos
petrosDemetrakopoulos / dataclass_combine.py
Created November 18, 2022 17:51
Dataclass combining other dataclass
from dataclasses import dataclass
from typing import List
import datetime
@dataclass
class Order:
date: datetime.datetime
price: float = 0.0
@dataclass
from dataclasses import dataclass
@dataclass
class User:
email: str
name: str = "First name"
surname: str = "Last name"
def fullName(self):
return self.name + " " + self.surname
@petrosDemetrakopoulos
petrosDemetrakopoulos / dataclass_default_values.py
Last active November 18, 2022 17:06
A dataclass with default values
from dataclasses import dataclass
@dataclass
class User:
email: str
name: str = "First name"
surname: str = "Last name"
from dataclasses import dataclass
@dataclass
class User:
name: str
surname: str
email: str
user_instance = User('Petros', 'Demetrakopoulos', '[email protected]')
print(user_instance)
@petrosDemetrakopoulos
petrosDemetrakopoulos / texasholdem_monte_carlo_call.py
Created September 24, 2022 16:13
Texas Holdem Monte Carlo function call
print(monte_carlo(['Ah','Ad'], ['Ac','2d','9s']))
@petrosDemetrakopoulos
petrosDemetrakopoulos / texasholdem_monte_carlo.py
Created September 24, 2022 11:01
Texas Holdem Monte Carlo
def monte_carlo(hand, table, players=2, samples=10000):
dist = [0,0,0]
for i in range(samples):
outcome = simulate(hand, table, players)
dist[outcome] += 1
return list(map(lambda x: x/samples, dist))
@petrosDemetrakopoulos
petrosDemetrakopoulos / texasholdem_simulate.py
Last active September 24, 2022 09:06
Texas Holdem Simulation function
def simulate(hand, table, players):
hands = []
deck = random.sample(cards,len(cards)) #shuffle the deck
hand = hand[:]
table = table[:]
full = table + hand
deck = list(filter(lambda x: x not in full, deck))
#deal cards to players
@petrosDemetrakopoulos
petrosDemetrakopoulos / imports_and_cards.py
Created September 24, 2022 08:51
TexasHoldem Monte Carlo simulation Imports and Cards Initialization
from phevaluator import evaluate_cards
import random
suits = ['d','s','c','h']
ranks = ['A','2','3','4','5','6','7','8','9','T','J','Q','K']
cards = []
for r in ranks:
for s in suits:
cards.append(r+s)