This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def weekday_server_sched(offset): | |
return [[1 if ((i - offset + 7) % 7) < 5 else 0, i+1] for i in range(7)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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={ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
NewerOlder