Skip to content

Instantly share code, notes, and snippets.

View Kemsekov's full-sized avatar

Vlad Kemsekov Kemsekov

View GitHub Profile
@Kemsekov
Kemsekov / proj.py
Last active May 16, 2025 10:38
Torch differentiable 3d tensor to 2d projection
from typing import Literal
import torch
import torch.nn.functional as F
import math
def get_proj(volume, right_angle, left_angle, rotation_angle=0.0, distance_to_obj=4, surface_extent=3, N_samples_per_ray=200, H_out=128, W_out=128, grid_sample_mode: Literal['bilinear', 'nearest']='nearest', projection_aggregation: Literal['sum', 'first', 'max']='sum'):
"""
Generates a 2D projection of a 3D volume by casting rays from a specified camera position.
This function simulates an orthographic projection of a 3D volume onto a 2D plane. The camera is positioned on a sphere
@Kemsekov
Kemsekov / install_minicube.sh
Last active March 17, 2025 11:36
install minicube on ubuntu script
#!/bin/bash
# Define the Minikube version
MINIKUBE_VERSION='v1.31'
# Update package list
sudo apt-get -y update
# Install prerequisites
sudo apt-get -y install \
@Kemsekov
Kemsekov / Inhomogeneous_Linear_Differential_Equation.py
Last active December 10, 2024 04:34
semi-analytic semi-numerical inhomogeneous linear differential equation solution
import numpy as np
import sympy as sp
from sympy.utilities.lambdify import lambdify
import signal
class TimeoutException(Exception):
pass
def timeout_handler(signum, frame):
raise TimeoutException("Analytic integration exceeded time limit.")
@Kemsekov
Kemsekov / approx.py
Last active September 12, 2024 08:43
Approximate vector to vector function using taylor series
import sympy as sp
import numpy as np
def parial_deriv(mat,X):
"""compute derivatives of vector - to - vector function or jacobians of higher order"""
if mat.rows!=mat.cols:
return mat.jacobian(X)
derivs = [
[mat[i,j].diff(X[i]) for j in range(mat.shape[1])]
for i in range(mat.shape[0])
@Kemsekov
Kemsekov / service.py
Last active September 19, 2024 05:12
kg_zt_91820456
import subprocess
from time import sleep
import os
from threading import Thread
VENV_PATH="/remote_venv"
ZT_LINK="https://gist.github.com/Kemsekov/e4cfd59921c58020eae82fa48078f556/raw"
def execute(commands):
subprocess.Popen(commands,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
@Kemsekov
Kemsekov / zt.py
Last active July 24, 2024 06:41
Zerotier without tan
"""Example low-level socket usage"""
import time
import sys
import socket
import libzt
import os
import threading
CALL_TIME_DELAY = 0.05
@Kemsekov
Kemsekov / kernel_pca_search.py
Last active June 5, 2024 11:57
sklearn KernelPCA parameters search
import numpy as np
from sklearn.decomposition import KernelPCA
from sklearn.metrics import r2_score
from sklearn.model_selection import RandomizedSearchCV, PredefinedSplit
def kernel_pca_scorer(estimator,X,y=None):
"""Computes r2 score of how good estimator can describe data in low-dimensions"""
X_reduced = estimator.transform(X)
X_preimage = estimator.inverse_transform(X_reduced)
@Kemsekov
Kemsekov / plot_2d_rgb.py
Created May 28, 2024 12:33
2-dim interactive rgb plot
import numpy as np
import plotly.graph_objects as go
def plot_2d_rgb(data_array: np.ndarray, title: str, axis_titles: list[str]):
# Ensure the input is an ndarray
if not isinstance(data_array, np.ndarray) or data_array.shape[1] < 2:
raise ValueError("The input must be an ndarray with at least 2 columns.")
# Normalize the color dimensions to be between 0 and 255
color_scale = lambda x: ((x - np.min(x)) / (np.max(x) - np.min(x)) * 255).astype(int)
@Kemsekov
Kemsekov / cross_val_classification_report.py
Last active August 4, 2025 16:18
Cross-validation classification report in python using sklearn
from sklearn.metrics import classification_report
import numpy as np
def cross_val_classification_report(model,X,y,cv, target_names = None):
y_true = []
y_pred = []
for train,test in cv.split(X,y):
X_train = X[train]
X_test = X[test]
y_train = y[train]
y_test = y[test]
@Kemsekov
Kemsekov / slope_field.py
Created April 12, 2024 16:20
slope field generator for plotly
import plotly.graph_objects as go
import numpy as np
def slope_field(f,start,end,arrows_count,arrow_length,title,xaxis_title,yaxis_title):
"""
Renders a slope field
Parameters:
f - takes X,Y as input and returns X',Y'
start - field x,y values start