Skip to content

Instantly share code, notes, and snippets.

View thistleknot's full-sized avatar

Turning out data tricks since 2006! thistleknot

View GitHub Profile
unit = dfhack.gui.getSelectedUnit()
PlusPlus = {700, 1200, 1400, 1500, 1600, 1800, 2500}
Plus = {450, 950, 1150, 1250, 1350, 1550, 2250}
Normal = {200, 700, 900, 1000, 1100, 1300, 2000}
Minus = {150, 600, 800, 900, 1000, 1100, 1500}
PhysicalPlus = {"STRENGTH", "TOUGHNESS", "ANALYTICAL_ABILITY", "FOCUS", "CREATIVITY", "PATIENCE", "MEMORY"}
unit = dfhack.gui.getSelectedUnit()
PlusPlus = {700, 1200, 1400, 1500, 1600, 1800, 2500}
Plus = {450, 950, 1150, 1250, 1350, 1550, 2250}
Normal = {200, 700, 900, 1000, 1100, 1300, 2000}
Minus = {150, 600, 800, 900, 1000, 1100, 1500}
Mental_Attribute_Names = {
Mental_PlusPlus = {"FOCUS", "SPATIAL_SENSE"},
Mental_Plus = {"ANALYTICAL_ABILITY", "FOCUS", "CREATIVITY", "PATIENCE", "MEMORY"},
-- Bugs
--[[
...rk\MasterworkDF v3e\Dwarf Fortress\hack\scripts/test.lua:199: Cannot read fie
ld unit_attribute[].6: index out of bounds.
stack traceback:
[C]: in function '__index'
...rk\MasterworkDF v3e\Dwarf Fortress\hack\scripts/test.lua:199: in func
tion 'boostValue'
...rk\MasterworkDF v3e\Dwarf Fortress\hack\scripts/test.lua:61: in funct
-- Bugs
-- --------------------------------------------------------------------------
-- Functions
function boostAttributes(selectedUnitCaste, unit)
--[[ these were not easy to get, see code...
df.physical_attribute_type
0 STRENGTH
1 AGILITY
-- Bugs
-- --------------------------------------------------------------------------
-- Classes
TraitArrayBins = defclass(TraitArrayBins)
TraitArrayBins.ATTR = {
name = "",
traitMin = 0,
traitMed = 0,
traitMax = 0
TraitArrayBins = {}
TraitArrayBins.__index = TraitArrayBins
function TraitArrayBins.create(name, traitMin, traitMed, traitMax)
local trait = {}
setmetatable(trait,TraitArrayBins)
trait.name = name
trait.traitMin = traitMin
import os
os.environ['R_HOME'] = '/mnt/distvol/R/4.0.5/lib64/R/'
import rpy2.robjects as ro
from rpy2.robjects.packages import importr
from rpy2.robjects import pandas2ri
pandas2ri.activate()
k = 4
grdevices = importr('grDevices')
@thistleknot
thistleknot / linear_shap.py
Created May 2, 2021 17:14
Python shap values
import sklearn
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.model_selection import train_test_split
import numpy as np
import shap
shap.initjs()
# select a set of background examples to take an expectation over
background = np.array(data)
#[np.random.choice(X_train.shape[0],100,replace=False)]
@thistleknot
thistleknot / back_step.py
Last active May 8, 2021 23:39
python backwards step regression with zca whitening
trf = zca.ZCA().fit(transformed.iloc[:,1:])
X = pd.DataFrame(trf.transform(transformed.iloc[:,1:]))
X.columns=pd.DataFrame(transformed.iloc[:,1:]).columns
X.index = all_data.index
#from sklearn.preprocessing import StandardScaler
y = pd.DataFrame((transformed.iloc[:,0]-np.mean(transformed.iloc[:,0]))/np.std(transformed.iloc[:,0]))
y.columns=pd.DataFrame(transformed.iloc[:,0]).columns
y.index = all_data.index
@thistleknot
thistleknot / ecdf.py
Last active August 29, 2021 03:17
ECDF Python
converted = pd.DataFrame()
def ecdf2(values):
co = len(values)
externalArray = pd.DataFrame()
for d in range(0,len(values.columns)):
internalArray = []
for i in range(0,len(values.iloc[:,d])):
a = ( \
sum( ( values.iloc[:,d] <= values.iloc[:,d][i] ) ) + \