Skip to content

Instantly share code, notes, and snippets.

View Shiina18's full-sized avatar
💭
I may be slow to respond.

shiina Shiina18

💭
I may be slow to respond.
View GitHub Profile
@Shiina18
Shiina18 / MyOLSMultipleLinearRegression.java
Created February 1, 2022 00:49
Calculates the two-tailed p-values for the t-statistics for regression parameters.
import org.apache.commons.math3.distribution.TDistribution;
import org.apache.commons.math3.linear.RealMatrix;
import org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression;
import org.apache.commons.math3.util.FastMath;
import java.util.Arrays;
public class MyOLSMultipleLinearRegression extends OLSMultipleLinearRegression {
/**
* <p>Calculates the two-tailed p-values for the t-statistics for regression parameters.
import collections
import uuid
from typing import Dict
import numpy as np
import tritonclient
import tritonclient.grpc as grpcclient
import tritonclient.utils.shared_memory as shm
ShmHandle = collections.namedtuple(
@Shiina18
Shiina18 / _decorators.py
Last active September 11, 2022 10:16
Python timing decorator
import functools
import logging
import time
logger = logging.getLogger(__name__)
def pretty_time(t):
if t < 1:
return f'{t * 1000:.1f} ms'
from typing import Union, Tuple, List, Dict
import numpy as np
import onnx
import onnxruntime as ort
import torch
import torch.nn as nn
def torch2onnx(
@Shiina18
Shiina18 / representer_point_selection.py
Last active September 1, 2023 01:30
This is probably a more clear implementation of [chihkuanyeh/Representer_Point_Selection](https://github.com/chihkuanyeh/Representer_Point_Selection/blob/master/compute_representer_vals.py) in PyTorch. Some details are different and changeable with comments attached.
import torch
import torch.nn as nn
class Classifier(nn.Module):
def __init__(self, pretrained_linear: nn.Linear):
super().__init__()
assert pretrained_linear.bias is not None # changeable
self.linear = nn.Linear(
in_features=pretrained_linear.in_features,
out_features=pretrained_linear.out_features,
@Shiina18
Shiina18 / find_best_f1_and_threshold.py
Created December 26, 2023 08:59
some simple python utilities copied from other sources
"""
Copied from sentence-transformers / sentence_transformers/evaluation/BinaryClassificationEvaluator.py
"""
def find_best_f1_and_threshold(scores, labels, high_score_more_similar: bool):
assert len(scores) == len(labels)
scores = np.asarray(scores)
labels = np.asarray(labels)
rows = list(zip(scores, labels))
@Shiina18
Shiina18 / merge_csv.sh
Created January 11, 2024 07:20
Merge all csvs with the same columns. Usage `./merge_csv.sh -s source_dir -t target_csv_filepath`. Modification is needed if there may be spaces in filenames.
#!/bin/bash
# Parse command line arguments using getopts
while getopts ":s:t:" opt; do
case $opt in
s)
source_dir="$OPTARG"
;;
t)
target_path="$OPTARG"
@Shiina18
Shiina18 / swiss.py
Last active January 12, 2024 07:52
Swiss system round calculator. Assume no draw, win prob 50%. List all possible results.
import collections
import itertools
Distribution = dict[tuple[int, int], int] # {(#wins, #loss): #players}
State = tuple[float, Distribution] # (prob, dist)
def sum_counter(counters):
s = collections.Counter()
for c in counters:
@Shiina18
Shiina18 / find_top_k.py
Last active March 22, 2024 01:22
Very verbose implementation for finding topk with minimum comparison "described in Knuth's Art of Programming, Volume 3, Page 212". See https://stackoverflow.com/questions/4956593/optimal-algorithm-for-returning-top-k-values-from-an-array-of-length-n
"""
Very verbose implementation for finding topk with minimum comparison
https://stackoverflow.com/questions/4956593/optimal-algorithm-for-returning-top-k-values-from-an-array-of-length-n
"""
from __future__ import annotations
import dataclasses
import enum