This file contains hidden or 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 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 |
This file contains hidden or 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
#!/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 \ |
This file contains hidden or 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 | |
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.") |
This file contains hidden or 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 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]) |
This file contains hidden or 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 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) |
This file contains hidden or 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
"""Example low-level socket usage""" | |
import time | |
import sys | |
import socket | |
import libzt | |
import os | |
import threading | |
CALL_TIME_DELAY = 0.05 |
This file contains hidden or 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 | |
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) |
This file contains hidden or 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 | |
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) |
This file contains hidden or 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 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] |
This file contains hidden or 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 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 |
NewerOlder