Skip to content

Instantly share code, notes, and snippets.

View galenseilis's full-sized avatar
📈
f(data | model, expertise) = insight

Galen Seilis galenseilis

📈
f(data | model, expertise) = insight
View GitHub Profile
@galenseilis
galenseilis / dictionary_to_object.py
Created January 12, 2024 20:14
dictionary_to_object.py
import types
class DictToObject:
def __init__(self, dictionary):
for key, value in dictionary.items():
if callable(value):
# If the value is callable (a function/method), bind it to the instance
setattr(self, key, types.MethodType(value, self))
else:
# Otherwise, set it as an attribute
@galenseilis
galenseilis / mm1_simkit_example.py
Last active January 3, 2024 16:03
Example of a MM1 being simulated using SimKit
"""Demo model of SimpleKit usage."""
from simplekit import SimpleKit
from collections import deque
from numpy.random import default_rng
import sys
class MMk(SimpleKit):
"""Implementation of an M/M/k queueing model using SimpleKit."""
def __init__(self, arrivalRate, serviceRate, maxServers, numCustomers, seed = 1234567):
@galenseilis
galenseilis / WeekDayConstrainedDist.py
Created December 23, 2023 05:40
WeekDayConstrainedDist for HCiw
class WeekDayConstrainedDist(ciw.dists.Distribution):
def __init__(self, dist, offset=0, *args, **kwargs):
super().__init__(*args, **kwargs)
self.dist = dist
self.offset = offset
def sample(self, t=None, ind=None):
tau = (np.floor(t) - self.offset + 7) % 7
if tau < 5:
@galenseilis
galenseilis / gist:e3c587b0977df8d70d896f05086d44d3
Created December 23, 2023 05:17
Function to make a weekday server schedule for ciw
def weekday_server_sched(offset):
return [[1 if ((i - offset + 7) % 7) < 5 else 0, i+1] for i in range(7)]
# Ugly one-liner from an interactive session... sorry!
import numpy as np;
from scipy.stats import ttest_1samp as t;
import matplotlib.pyplot as plt;
[
plt.scatter(
np.arange(1,101),
[t(np.random.normal(size=n+1), 1).pvalue for n in range(100)],
alpha=1/np.sqrt(100),
color='g')
@galenseilis
galenseilis / qt_get_sim_data.py
Created December 16, 2023 17:05
queueing_tool example; just dumping it here. This gist shows obtaining data data from a simulation.
import matplotlib.pyplot as plt
import networkx as nx
import queueing_tool as qt
g = qt.generate_random_graph(100, seed=3)
q = qt.QueueNetwork(g, seed=3)
q.max_agents = 20000
q.initialize(100)
q.start_collecting_data()
@galenseilis
galenseilis / old_ciw_example.py
Created December 16, 2023 17:03
This was just on my hard drive. Don't think I'll use it, but putting it here is fine.
import ciw
import pandas as pd
N = ciw.create_network(
arrival_distributions={
"Baby": [ciw.dists.Exponential(rate=1.0), None, None],
"Child": [ciw.dists.Exponential(rate=2.0), None, None],
},
service_distributions={
@galenseilis
galenseilis / quickprophet_example.py
Last active December 15, 2023 10:56
quickprophet example
import numpy as np
ds = pd.date_range('2023-01-01', '2027-03-02')
df = pd.DataFrame(dict(ds=ds, y=np.random.poisson(np.arange(ds.size) / 10 + 1)))
df = features.add_day_of_year_features(df, 'ds')
df['GROUP'] = ['ALL'] * ds.size
param_grid = {
'changepoint_prior_scale': [0.001],
'seasonality_prior_scale': [0.01],
'holidays_prior_scale': [0.01]
@galenseilis
galenseilis / script1.py
Created December 11, 2023 17:11
socket_example.py
import socket
import pickle
data_structure = {'key': 'value', 'numbers': [1, 2, 3]}
# Serialize the data structure
serialized_data = pickle.dumps(data_structure)
# Send the serialized data to script2.py
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
@galenseilis
galenseilis / 2023-12-07.py
Last active December 8, 2023 15:23
Ciw Single Thread Performance
from dataclasses import dataclass
import random
import ciw
from hciw.waitlist import create_existing_customers_from_list
from hciw.service_disciplines import lex_priority_benchmark_with_threshold_switch
import numpy as np
import pandas as pd