Ejemplo n.º 1
0
def calc_prob(elem_events, total_items):

    coin_conditional = Conditional(elem_events)
    arrangements = coin_conditional.arrange_items(total_items)

    # First 5 the same sides
    same_sides = [arr for arr in arrangements if len(set(arr[:5])) == 1]

    print(f"{len(same_sides)}/{len(arrangements)}")
    return len(same_sides) / len(arrangements)
Ejemplo n.º 2
0
def calc_prob(elem_events, total_items):

    coin_conditional = Conditional(elem_events)
    arrangements = coin_conditional.arrange_items(total_items)

    # Different faces turning up
    diff_faces = [arr for arr in arrangements if len(set(arr)) != 1]

    print(f"{len(diff_faces)}/{len(arrangements)}")
    return len(diff_faces) / len(arrangements)
Ejemplo n.º 3
0
def calc_prob(elem_events, total_items):

    coin_conditional = Conditional(elem_events)
    arrangements = coin_conditional.arrange_items(total_items)

    # Two faces being the same
    same_2_faces = [arr for arr in arrangements if len(set(arr)) == 3]

    print(f"{len(same_2_faces)}/{len(arrangements)}")
    return len(same_2_faces) / len(arrangements)
Ejemplo n.º 4
0
def calc_prob(elem_events, total_items):

    die_conditional = Conditional(elem_events)
    arrangements = die_conditional.arrange_items(total_items)
    
    # Sum greater than 10
    more_than_10 = [arr for arr in arrangements if sum([int(i) for i in arr]) > 10]

    # Sum is 12
    sum_12 = [arr for arr in more_than_10 if sum([int(i) for i in arr]) == 12]

    print(f"{len(sum_12)}/{len(more_than_10)}")
    return len(sum_12) / len(more_than_10)
Ejemplo n.º 5
0
def calc_prob(elem_events, total_items):
    die_conditional = Conditional(elem_events)
    die_init_arrangements = die_conditional.arrange_items(total_items)

    # Excludes the case where both dice are odd
    arrangements = [
        arr for arr in die_init_arrangements
        if not (is_odd(arr[0]) and is_odd(arr[1]))
    ]

    # Cases where total of 2 dice is 8
    total_8 = [arr for arr in arrangements if int(arr[0]) + int(arr[1]) == 8]

    print(f"{len(total_8)}/{len(arrangements)}")
    return len(total_8) / len(arrangements)
Ejemplo n.º 6
0
def calc_prob(elem_events, total_items):

    coin_conditional = Conditional(elem_events)

    # Possible permutations of H/T in the toss of 10 coins
    arrangements = coin_conditional.arrange_items(total_items)

    # Excludes the case of all tails (given that we know that there is at least one head)
    no_all_tails = [
        arr for arr in arrangements if not all([i == 'T' for i in arr])
    ]

    # Excludes the case where there is a single head
    no_one_heads = [arr for arr in no_all_tails if list(arr).count('H') != 1]

    print(f"{len(no_one_heads)}/{len(no_all_tails)}")
    return len(no_one_heads) / len(no_all_tails)
Ejemplo n.º 7
0
def main():
    playTournament(
        numOfGames=200,
        players=[NN(),
                 Rotate(),
                 BeatPrevious(),
                 Probability(),
                 Conditional()])
Ejemplo n.º 8
0
def calc_prob(elem_events, total_items):

    coin_conditional = Conditional(elem_events)
    arrangements = coin_conditional.arrange_items(total_items)

    # Excludes the case of all tails (given that we know that there is at
    # least one head)
    no_all_tails = [arr for arr in arrangements if not all(
        [i == 'T' for i in arr])]

    # At least 2 heads
    atleast_2H = [arr for arr in no_all_tails if list(arr).count('H') >= 2]

    # Exactly 3 heads
    exactly_3H = [arr for arr in atleast_2H if list(arr).count('H') == 3]

    print(f"{len(exactly_3H)}/{len(atleast_2H)}")
    return len(exactly_3H) / len(atleast_2H)
Ejemplo n.º 9
0
def calc_prob(elem_events, total_items):

    card_conditional = Conditional(elem_events, False)
    arrangements = card_conditional.arrange_items(total_items)

    # At least one ace
    atleast_1A = {
        tuple(arr)
        for arr in arrangements if [card[0] for card in arr].count('A') >= 1
    }

    # Exactly two aces
    exatly_2A = {
        tuple(arr)
        for arr in arrangements if [card[0] for card in arr].count('A') == 2
    }

    print(f"{len(exatly_2A)}/{len(atleast_1A)}")
    return len(exatly_2A) / len(atleast_1A)
Ejemplo n.º 10
0
 .load(train_path)

# Datetime

dt_trans = DateColumns(inputCol="click_time")
dt_ass = VectorAssembler(inputCols=dt_trans.getOutputColumns(),
                         outputCol="dt_cols",
                         handleInvalid="skip")
dt_minmax = MinMaxScaler(inputCol="dt_cols", outputCol="dt_scaled")

dt_pipeline = Pipeline(stages=[dt_trans, dt_ass, dt_minmax])

cond_cols = ["cond_app", "cond_device", "cond_os", "cond_channel"]

cond_app = Conditional(inputCol=TARGET,
                       groupByCol=["app"],
                       outputCol="cond_app")
cond_device = Conditional(inputCol=TARGET,
                          groupByCol=["device"],
                          outputCol="cond_device")
cond_os = Conditional(inputCol=TARGET, groupByCol=["os"], outputCol="cond_os")
cond_channel = Conditional(inputCol=TARGET,
                           groupByCol=["channel"],
                           outputCol="cond_channel")

cond_ass = VectorAssembler(inputCols=cond_cols,
                           outputCol="cond_cols",
                           handleInvalid="skip")

cond_pipeline = Pipeline(
    stages=[cond_app, cond_device, cond_os, cond_channel, cond_ass])