Skip to content

Instantly share code, notes, and snippets.

View merylldindin's full-sized avatar

Meryll Dindin merylldindin

View GitHub Profile
@merylldindin
merylldindin / fit_predict.py
Last active November 25, 2019 05:17
ToMaTo Clustering
def define_clusters(lst, fil, neighbors):
# lst -> ordered list of indexes
# fil -> mapped dictionnary of filtration values with indexes
# neighbors -> number of closest elements to consider per query
unf = UnionFind()
for idx in lst:
grp, srt = [], np.where(lst == idx)[0][0]
from sklearn.metrics import confusion_matrix
def kappa_score(y_true, y_pred):
cfm = confusion_matrix(y_true, y_pred)
n_c = len(np.unique(y_true))
s_0 = np.sum(cfm, axis=0)
s_1 = np.sum(cfm, axis=1)
exp = np.outer(s_0, s_1).astype(np.double) / np.sum(s_0)
mat = np.ones([n_c, n_c], dtype=np.int)
# Load the dataset
x,y = load_iris(return_X_y=True)
# Split it in training and validation
x_t, x_v, y_t, y_v = train_test_split(x, y, test_size=0.2, shuffle=True, random_state=42)
# Build a representation of the problem
arg = {'threads': cpu_count(), 'weights': False}
prb = Prototype(x_t, x_v, y_t, y_v, 'ETS', 'classification', 'acc', **arg)
# Instantiate and run a one-shot learning based on the given configuration
exp = Experiment()
exp.single(prb, random_state=42)
{
'computeFFT': True, 'mainFrequency': True,
'computePeriodogram': True, 'computeSpectrogram': True,
'frequencyBands': True,
'coefficientsAR': True,
'crossingOver': True, 'computePolarity': True,
'computeWavelet': True,
'computeChaos': True, 'computeFractals': True,
'signalDecomposition': True,
'computeStatistics': True,
# Initialize San Francisco mapping
map_center_coordinates = (37.7749, -122.4194)
m = folium.Map(location=map_center_coordinates, tiles="Stamen Terrain", zoom_start=12)
# Load the processed graph of San Francisco
trj = Trajectory('../datasets/sanfrancisco.jb')
obj = np.random.choice(list(trj.G.keys()), 6)
# Build five random objectives given one starting point
for i in range(5):
pth = trj.shortest_path(obj[0], obj[i+1])
pts = np.asarray([np.asarray(e.split(':')).astype('float')[::-1] for e in pth])
files:
"/etc/httpd/conf.d/wsgi_custom.conf":
mode: "000644"
owner: root
group: root
content: |
WSGIApplicationGroup %{GLOBAL}
"/etc/httpd/conf.d/proxy-pass.conf":
mode: "000644"
# Initialize the Flask application
application = Flask(__name__)
app_sockets = Sockets(application)
# Websocket usage example
@app_sockets.route('/stream')
def stream(websocket):
while not websocket.closed:
msg = websocket.receive()
if msg is None: continue
import json, base64, websocket
class Base64Encoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, bytes): return base64.b64encode(o).decode()
return json.JSONEncoder.default(self, o)
class Emitter:
from application import wss
if __name__ == '__main__':
from gevent import pywsgi
from geventwebsocket.handler import WebSocketHandler
# Development server to run locally on port 5000
app = pywsgi.WSGIServer(('', 5000), wss, handler_class=WebSocketHandler)
app.serve_forever()
FROM python:3.7-slim
RUN mkdir -p /app/storage
VOLUME /app
WORKDIR /app
COPY ./requirements.txt /app/requirements.txt
RUN pip install gunicorn
RUN pip install -r requirements.txt
COPY . /app