Пример #1
0
fat_right_leaf_2, _priors = type_mixture_leaf_factory(
    leaf_type='pm',
    leaf_meta_type=MetaType.REAL,
    type_to_param_map=pm_continuous_param_map,
    scope=[1],
    init_weights=lf_2_init_weights)
lf_3_init_weights = {Poisson: 0.9, Categorical: 0.1}
# lf_3_init_weights = np.array([.9, .1])
fat_right_leaf_3, _priors = type_mixture_leaf_factory(
    leaf_type='pm',
    leaf_meta_type=MetaType.DISCRETE,
    type_to_param_map=pm_discrete_param_map,
    scope=[2],
    init_weights=lf_3_init_weights)

r_prod.children = [fat_right_leaf_1, fat_right_leaf_2, fat_right_leaf_3]

#
# left branch one leaf and one sum nodes
rf_3_init_weights = {Categorical: 0.4, Poisson: 0.6}
# rf_3_init_weights = np.array([.6, .4])
fat_left_leaf_3, _priors = type_mixture_leaf_factory(
    leaf_type='pm',
    leaf_meta_type=MetaType.DISCRETE,
    type_to_param_map=pm_discrete_param_map,
    scope=[2],
    init_weights=rf_3_init_weights)

left_sum_node = Sum()
l_prod.children = [left_sum_node, fat_left_leaf_3]
Пример #2
0
    ax.plot(pdf_x, pdf_y, label="exponential")
    print('Exponential Mode:', exponential.mode)
    plt.axvline(x=exponential.mode, color='r')
    if show_plots:
        plt.show()

    #
    #
    # testing for a product node over two leaves
    rand_gen = np.random.RandomState(17)

    l_1 = Gaussian(mean=0.5, stdev=2, scope=[0])
    l_2 = Poisson(mean=5, scope=[1])

    p = Product()
    p.children = [l_1, l_2]
    rebuild_scopes_bottom_up(p)
    assign_ids(p)

    N = 10
    X_1 = rand_gen.normal(loc=0, scale=1, size=(N, 1))
    X_2 = rand_gen.poisson(lam=3, size=(N, 1))
    X = np.concatenate((X_1, X_2), axis=1)
    print('X', X, X.shape)

    X_mpe = np.copy(X)
    X_mpe[np.arange(N) % 2 == 0, 0] = np.nan
    X_mpe[np.arange(N) % 2 == 1, 1] = np.nan
    print('X_mpe', X_mpe, X_mpe.shape)

    lls = likelihood(p, X)