Skip to content

Instantly share code, notes, and snippets.

View Corwinpro's full-sized avatar

Petr Kungurtsev Corwinpro

View GitHub Profile
@Corwinpro
Corwinpro / meshtagging_mvc.py
Created October 3, 2021 00:21 — forked from michalhabera/meshtagging_mvc.py
Terribly hacky MVC workaround for pygmsh-meshio-dolfin boundary tagging
from pygmsh.built_in.geometry import Geometry
from pygmsh import generate_mesh
import meshio
import dolfin
geom = Geometry()
lc = .1
p0 = geom.add_point([0, 0, 0], lcar=lc)
p1 = geom.add_point([1, 0, 0], lcar=lc)
@Corwinpro
Corwinpro / actors.py
Created August 12, 2021 19:21 — forked from jvkersch/actors.py
Implementation of the actor model in Python
import abc
import asyncio
class MessageBox:
""" A class that can
- send messages of a certain type with some context (== put a message into
an internal queue),
- receive messages from the internal queue
"""
@Corwinpro
Corwinpro / async_post.py
Created January 10, 2021 12:08
A simple asyncio code that emulates a Post Office
import asyncio
import time
import random
from collections import defaultdict
NOF_AGENTS = 20
NOF_RECIPIENTS = 3
class Message:
import dolfin as dolf
import numpy as np
LOG_LEVEL = 30
dolf.set_log_level(LOG_LEVEL)
mesh = dolf.UnitIntervalMesh(100)
n = dolf.FacetNormal(mesh)
wall_left = "near(x[0], 0)"
wall_right = "near(x[0], 1.)"
from sklearn.base import BaseEstimator
from sklearn.model_selection import cross_val_score
from sklearn.metrics import roc_auc_score
class RandomForestClassifierCustom(BaseEstimator):
def __init__(self, n_estimators=10, max_depth=10, max_features=10,
random_state=SEED):
self.n_estimators = n_estimators
self.max_depth = max_depth
self.max_features = max_features
train_df['year_month'] = train_df['time1'].apply(lambda t: 100 * t.year + t.month).values.reshape(-1, 1)
test_df['year_month'] = test_df['time1'].apply(lambda t: 100 * t.year + t.month).values.reshape(-1, 1)
print(train_df['year_month'].loc[y_train == 1].describe())
train_df = train_df[(train_df['year_month'] >= 201401)]#201309
print(train_df['year_month'].loc[y_train == 1].describe())
### Output
train_times, test_times = train_df[times], test_df[times]
train_session_start_hour = train_times['time1'].apply(lambda ts: ts.hour).values
test_session_start_hour = test_times['time1'].apply(lambda ts: ts.hour).values
def add_day_features(df):
session_start_hour = df['time1'].apply(lambda ts: ts.hour)
morning = ((session_start_hour >= 7) & (session_start_hour <= 11)).astype('int').values.reshape(-1, 1)
day = ((session_start_hour >= 12) & (session_start_hour <= 18)).astype('int').values.reshape(-1, 1)
evening = ((session_start_hour >= 19) & (session_start_hour <= 23)).astype('int').values.reshape(-1, 1)
df['morning'] = morning
petrkungurtsev@:~$ sudo pip install ROL
Password:
The directory '/Users/petrkungurtsev/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/petrkungurtsev/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting ROL
Downloading ROL-0.0.9.tar.gz (7.9MB)
100% |████████████████████████████████| 7.9MB 167kB/s
Installing collected packages: ROL
Running setup.py install for ROL ... error
import numpy as np
import matplotlib.pyplot as plt
import math
def add_subplot_axes(ax,rect,axisbg='w'):
fig = plt.gcf()
box = ax.get_position()
width = box.width
height = box.height
inax_position = ax.transAxes.transform(rect[0:2])
from dolfin import *
import numpy as np
import math
from petsc4py import PETSc
#BCSType = 'Dirichlet'
#BCSType = 'Neumann'
BCSType = 'Mixed'
print BCSType