This file contains 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 pulp # https://pythonhosted.org/PuLP/ | |
# vvvvvvvvvvvvvvvvvvvvvvvvv convenience methods vvvvvvvvvvvvvvvvvvvvvvvvv | |
def dot(coefficients, variables): | |
return pulp.LpAffineExpression(zip(variables, coefficients)) | |
def print_variables(t, y): | |
print(f't: {t.varValue}') | |
for i in range(len(y)): |
This file contains 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 itertools | |
import pulp # https://pythonhosted.org/PuLP/ | |
def brute_force_best( | |
runners_per_country, | |
qs, | |
max_countries, | |
min_runners): | |
This file contains 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 itertools | |
import pulp # https://pythonhosted.org/PuLP/ | |
def count_to_ind_lookup(counts): | |
lookup = {} | |
ind = 0 | |
for i, c in enumerate(counts): | |
lookup.update(dict(zip(range(ind, ind + c), [i] * c))) | |
ind += c |
This file contains 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 matplotlib.pyplot as plt | |
import numpy as np | |
import pandas as pd | |
from scipy.stats import beta, uniform | |
from sklearn.metrics import ( | |
f1_score, | |
accuracy_score, | |
precision_score, | |
recall_score, | |
average_precision_score |
This file contains 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
def something(n: Long, k: Long): Double = | |
1 - (n - k) / k.toDouble * math.log((n + 0.5) / (n - k + 0.5)) |
This file contains 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
def something(n: Long, k: Long): BigDecimal = { | |
def h(i: Long, total: BigDecimal): BigDecimal = { | |
if (k < i) total | |
else { | |
val p = BigDecimal.exact(i) / (n - k + i) | |
val ap = p / k | |
h(i + 1, total + ap) | |
} | |
} | |
h(1, BigDecimal.exact(0)) |
This file contains 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
def something(n: Long, k: Long): BigDecimal = { | |
// For convenience. | |
type BD = BigDecimal | |
def bd(v: Long) = BigDecimal.exact(v) | |
@scala.annotation.tailrec // OLD VERSION: | |
def h(i: Long, total: BD): BD = { // def h(ni: Long, ki: Long, total: DB) = { | |
if (i <= 0) total // if (ki <= 0) total | |
else { // else { | |
val p = bd(i) / denom(n,k,i) // val p = bd(ki) / ni |
This file contains 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
def something(n: Long, k: Long): BigDecimal = { | |
@scala.annotation.tailrec | |
def h(ni: Long, ki: Long, total: BigDecimal): BigDecimal = { | |
if (ki <= 0) total | |
else { | |
val p = BigDecimal.exact(ki) / ni | |
val ap = p / k | |
h(ni - 1, ki - 1, total + ap) | |
} | |
} |
This file contains 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
# ============================================================================ | |
# R.M. Deak wt_cv_eval_is_diff_unwt_cv.py | |
# | |
# Runs scikit-learn's cross validation with GridSearchCV and shows that | |
# different optimal parameter values may be returned by GridSearchCV than | |
# when using cross validation with sample_weights passed to the scoring | |
# function. | |
# ============================================================================ | |
from typing import NamedTuple |
This file contains 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 scipy.stats import hypergeom | |
# Run the following to see the graph: | |
# for i in range(1, 400): | |
# print(f"{i}\t{exp_test_acc(400, 201, i)}") | |
# | |
def exp_test_acc(pop_size, pos_in_pop, fold1_size): | |
fold2_size = pop_size - fold1_size | |
E_acc = 0.0 |