示例#1
0
文件: __init__.py 项目: lftl/aoc
def main(session, noun=10, verb=2):
    raw = common.load_input(2, session)
    lines = parse(raw)

    lines[1] = noun
    lines[2] = verb

    return run(lines)
示例#2
0
def main(session):
    raw = common.load_input(1, session)
    lines = list(map(int, raw.splitlines()))

    part1 = sum(map(fuel, lines))
    part2 = sum(map(total_fuel_recursive, lines))

    print(f"Part 1: {part1}")
    print(f"Part 2: {part2}")
示例#3
0
文件: __init__.py 项目: lftl/aoc
def main(session=None):
    raw = common.load_input(3, session)
    lines = raw.splitlines()
    wires = list(map(wire2multiline, [line.split(',') for line in lines]))

    intersections = wires[0].intersection(wires[1])
    distances = list(map(manhattan_distance, intersections))
    distances.sort()

    print (f"Part 1: {distances[1]}")

    distances2 = list(map(wire_length_gen(wires), intersections[1:]))
    distances2.sort()
    print (f"Part 2: {distances2[1]}")
        save_to_value_store(value_name, value)


p = publish_value
t = start_stop_timer

outcome_diagnosis_pattern = ("I") #|| input
use_death_as_outcome = False #|| input

followup_period_years = 5 #|| input


#load_input_run_name = "T2D_timesplit__Stroke__v14"
load_input_run_name = "T2D_timesplit__CKD_N17-N19__v14"
load_input_shared_storage_name = "T2D__to__OUTCOMES_MIX_v14_1__SHARED_DATA"
subpop_lbnrs = load_input(load_input_run_name, "subpop_lbnrs", load_input_shared_storage_name) #|| input

first_subpop_event_df = load_input(load_input_run_name, "first_subpop_event_df", load_input_shared_storage_name) #|| input
subpop_cpr_df = load_input(load_input_run_name, "subpop_cpr_df", load_input_shared_storage_name) #|| input
subpop_birthplace_df = load_input(load_input_run_name, "subpop_birthplace_df", load_input_shared_storage_name) #|| input
subpop_death_causes_df = load_input(load_input_run_name, "subpop_death_causes_df", load_input_shared_storage_name) #|| input

subpop_sks_df = load_input(load_input_run_name, "subpop_sks_df", load_input_shared_storage_name) #|| input
subpop_diag_df = load_input(load_input_run_name, "subpop_diag_df", load_input_shared_storage_name) #|| input
subpop_prescriptions_df = load_input(load_input_run_name, "subpop_prescriptions_df", load_input_shared_storage_name) #|| input
subpop_ssr_df = load_input(load_input_run_name, "subpop_ssr_df", load_input_shared_storage_name) #|| input

current_addresses_df = load_input(load_input_run_name, "current_addresses_df", load_input_shared_storage_name) #|| input
past_addresses_df = load_input(load_input_run_name, "past_addresses_df", load_input_shared_storage_name) #|| input
past_archive_addresses_df = load_input(load_input_run_name, "past_archive_addresses_df", load_input_shared_storage_name) #|| input
示例#5
0
#load_input_run_name = "T2D_timesplit__Stroke__v14"
load_input_shared_storage_name = "T2D__to__OUTCOMES_MIX_v14_1__SHARED_DATA"

#%%
#||
action_name = "Describe Fit Results"
action_description = ""
action_input = {"fit_results", "trainX", "testX", "trainY", "testY", "patient_feature_vector___index__to__feature__list",
                "testX_index__to__patient_feature_vector_indexes", "patient_feature_vector___index__to__lbnr__list", "subpop_basic_df"}
action_output = {"model_type_summary"}
#||

#%%
#fit_results = load_input(load_input_run_name, "ExGradientBoost_count__fit_results", load_input_shared_storage_name) #|| input
#fit_results = load_input(load_input_run_name, "LR_aux__fit_results", load_input_shared_storage_name) #|| input
fit_results = load_input(load_input_run_name, "ExGradientBoost_count__fit_results", load_input_shared_storage_name) #|| input
#trainX = load_input(load_input_run_name, "aux__trainX", load_input_shared_storage_name) #|| input
trainX = load_input(load_input_run_name, "count__trainX", load_input_shared_storage_name) #|| input
trainY = load_input(load_input_run_name, "trainY", load_input_shared_storage_name) #|| input
#testX = load_input(load_input_run_name, "aux__testX", load_input_shared_storage_name) #|| input
testX = load_input(load_input_run_name, "count__testX", load_input_shared_storage_name) #|| input
testY = load_input(load_input_run_name, "testY", load_input_shared_storage_name) #|| input
#valX = load_input(load_input_run_name, "aux__valX", load_input_shared_storage_name) #|| input
valX = load_input(load_input_run_name, "count__valX", load_input_shared_storage_name) #|| input
valY = load_input(load_input_run_name, "valY", load_input_shared_storage_name) #|| input

trainX_index__to__patient_feature_vector_indexes =  load_input(load_input_run_name, "trainX_index__to__patient_feature_vector_indexes", load_input_shared_storage_name) #|| input
testX_index__to__patient_feature_vector_indexes =  load_input(load_input_run_name, "testX_index__to__patient_feature_vector_indexes", load_input_shared_storage_name) #|| input
valX_index__to__patient_feature_vector_indexes =  load_input(load_input_run_name, "valX_index__to__patient_feature_vector_indexes", load_input_shared_storage_name) #|| input
patient_feature_vector___index__to__lbnr__list =  load_input(load_input_run_name, "patient_feature_vector___index__to__lbnr__list", load_input_shared_storage_name) #|| input
patient_feature_vector___index__to__feature__list =  load_input(load_input_run_name, "patient_feature_vector___index__to__feature__list", load_input_shared_storage_name) #|| input
示例#6
0
pd.options.display.max_rows = 30

#%%

#Additional data that i had to recalculate for publication purposes

#Print poulation sizes including followup filtering
from datetime import datetime, timedelta

last_calendar_day_of_data = datetime(2016, 1, 1)
last_day_of_data = last_calendar_day_of_data - timedelta(days=365 * 5)
for i in range(5):
    load_input_run_name = f"T2D_{i}_timesplit__MI__v14" if i != 0 else "T2D__timesplit__MI__v14"
    load_input_shared_storage_name = f"T2D_{i}__to__OUTCOMES_MIX_v14_1__SHARED_DATA" if i != 0 else "T2D__to__OUTCOMES_MIX_v14_1__SHARED_DATA"

    subpop_cpr_df = load_input(load_input_run_name, "subpop_cpr_df",
                               load_input_shared_storage_name)  #|| input
    first_subpop_event_df = load_input(
        load_input_run_name, "first_subpop_event_df",
        load_input_shared_storage_name)  #|| input

    filtered_first_subpop_event_df = first_subpop_event_df[
        first_subpop_event_df["first_subpop_event"] < last_day_of_data]
    filtered_cpr_df = pd.merge(subpop_cpr_df,
                               filtered_first_subpop_event_df,
                               left_index=True,
                               right_index=True,
                               how="right")

    print("{}: # {}\t%W {:.3f}\tage {:.3f}".format(
        i, filtered_cpr_df.shape[0], 100 *
        float(filtered_cpr_df[filtered_cpr_df["C_KON"] == "K"].shape[0]) /
示例#7
0
#!/usr/bin/env python3

import numpy as np

from common import load_input
from common import sigmoid

inputs, labels, labels_1hot, (K, m, n) = load_input('predict.csv')

weights_file = 'weights.csv'
thetas = np.loadtxt(weights_file, delimiter=',')
print(f'loaded weights from {weights_file}')

for i in range(len(inputs)):
    image = inputs[i, :]
    image = image.reshape(image.shape[0], 1)
    label = labels[i]
    print(f'\nimage {i} has label {label}')
    ps = sigmoid(thetas.dot(image))
    top_i = np.argmax(ps)
    top = np.squeeze(ps[top_i])
    print(f'prediction: {top_i} with {top * 100:.3f}%')
    for k in range(len(ps)):
        p = np.squeeze(ps[k])
        print(f'\tP({k}) = {p * 100:7.3f}%')
示例#8
0
#!/usr/bin/env python3

import numpy as np

from common import load_input
from common import sigmoid


inputs, labels, labels_1hot, (K, m, n) = load_input('train.csv')

thetas = np.random.rand(K, n)
alpha = 1e-3
iters = int(20_000)

X = inputs
for k in range(K):
    print(f'train classifier {k} with {m} examples for {iters} iterations')
    theta = thetas[k].reshape(n, 1)
    Y = labels_1hot[k].reshape(m, 1)
    for i in range(iters):

        z = X.dot(theta)
        a = sigmoid(z)

        diff = a - Y
        grad = X.T.dot(diff)
        theta -= (alpha / m) * grad

        if i == iters - 1:
            pass
            # TODO: calculate cost