Ejemplo n.º 1
0
def inverse_stoc_hyper_priors_test9():
    """
	real nn arch with 16 nn params, two hyperparams, layer granularity, 
	independent params
	"""
    num_inputs = 1
    layer_sizes = [3, 2]
    num_outputs = 1
    print "num weights"
    n_dims = tools.calc_num_weights(num_inputs, layer_sizes, num_outputs)
    print tools.calc_num_weights(num_inputs, layer_sizes, num_outputs)
    weight_shapes = tools.get_weight_shapes(num_inputs, layer_sizes,
                                            num_outputs)
    print "weight shapes"
    print tools.get_weight_shapes(num_inputs, layer_sizes, num_outputs)
    granularity = 'layer'
    hyper_dependence_lengths = tools.get_hyper_dependence_lengths(
        weight_shapes, granularity)
    n_stoc = len(hyper_dependence_lengths)
    print "number of weights per layer"
    print tools.calc_num_weights_layers(weight_shapes)
    dependence_lengths = tools.get_degen_dependence_lengths(weight_shapes,
                                                            independent=True)
    print "degen dependence lengths"
    print tools.get_degen_dependence_lengths(weight_shapes, independent=True)
    hyperprior_types = [9, 7]
    prior_types = [4]
    hyperprior_params = [[1., 2.], [2., 0.]]
    prior_hyperparams = [0.]
    param_hyperprior_types = [1, 0, 1]
    param_prior_types = [0]
    prior = isp.inverse_stoc_hyper_prior(hyperprior_types, prior_types,
                                         hyperprior_params, prior_hyperparams,
                                         hyper_dependence_lengths,
                                         dependence_lengths,
                                         param_hyperprior_types,
                                         param_prior_types, n_stoc, n_dims)
    p = np.array([
        0.1, 0.5, 0.6, 0.7, 0.8, 0.9, 0.4, 0.2, 0.1, 0.5, 0.7, 0.8, 0.9, 0.4,
        0.2, 0.1, 0.5, 0.9, 0.2, 0.7
    ])
    prior(p)
    u = [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]
    v = [
        2., 2., 2., 2., 2., 2., 1.6986436, 1.6986436, 1.6986436, 1.6986436,
        1.6986436, 1.6986436, 1.6986436, 1.6986436, 2., 2., 2.
    ]
    print isp.gaussian_prior()(p[3], u[0], v[0])
    print isp.gaussian_prior()(p[4], u[1], v[1])
    print isp.gaussian_prior()(p[5], u[2], v[2])
    print isp.gaussian_prior()(p[6], u[3], v[3])
    print isp.gaussian_prior()(p[7], u[4], v[4])
    print isp.gaussian_prior()(p[8], u[5], v[5])
    print isp.gaussian_prior()(p[9], u[6], v[6])
    print isp.gaussian_prior()(p[10], u[7], v[7])
    print isp.gaussian_prior()(p[11], u[8], v[8])
    print isp.gaussian_prior()(p[12], u[9], v[9])
    print isp.gaussian_prior()(p[13], u[10], v[10])
    print isp.gaussian_prior()(p[14], u[11], v[11])
    print isp.gaussian_prior()(p[15], u[12], v[12])
    print isp.gaussian_prior()(p[16], u[13], v[13])
    print isp.gaussian_prior()(p[17], u[14], v[14])
    print isp.gaussian_prior()(p[18], u[15], v[15])
    print isp.gaussian_prior()(p[19], u[16], v[16])
Ejemplo n.º 2
0
def inverse_stoc_hyper_priors_test14():
    """
	real nn arch with 16 nn params, two hyperparams, input_size granularity, 
	degen dependent params
	"""
    num_inputs = 1
    layer_sizes = [3, 2]
    num_outputs = 1
    print "num weights"
    n_dims = tools.calc_num_weights(num_inputs, layer_sizes, num_outputs)
    print tools.calc_num_weights(num_inputs, layer_sizes, num_outputs)
    weight_shapes = tools.get_weight_shapes(num_inputs, layer_sizes,
                                            num_outputs)
    print "weight shapes"
    print tools.get_weight_shapes(num_inputs, layer_sizes, num_outputs)
    granularity = 'input_size'
    hyper_dependence_lengths = tools.get_hyper_dependence_lengths(
        weight_shapes, granularity)
    n_stoc = len(hyper_dependence_lengths)
    print "n_stoc"
    print n_stoc
    print "granularity"
    print tools.get_hyper_dependence_lengths(weight_shapes, granularity)
    print "number of weights per layer"
    print tools.calc_num_weights_layers(weight_shapes)
    dependence_lengths = tools.get_degen_dependence_lengths(weight_shapes)
    print "degen dependence lengths"
    print tools.get_degen_dependence_lengths(weight_shapes)
    hyperprior_types = [9, 7]
    prior_types = [4, 5]
    hyperprior_params = [[1., 2.], [2., 0.]]
    prior_hyperparams = [0., 1.]
    param_hyperprior_types = [0, 1, 0, 0, 1, 1, 1, 0, 0]
    param_prior_types = [0, 1, 0, 1, 0, 0, 1, 1, 0]
    prior = isp.inverse_stoc_hyper_prior(hyperprior_types, prior_types,
                                         hyperprior_params, prior_hyperparams,
                                         hyper_dependence_lengths,
                                         dependence_lengths,
                                         param_hyperprior_types,
                                         param_prior_types, n_stoc, n_dims)
    p = np.array([
        0.1, 0.5, 0.6, 0.7, 0.8, 0.9, 0.4, 0.2, 0.1, 0.5, 0.7, 0.8, 0.9, 0.4,
        0.2, 0.1, 0.5, 0.9, 0.2, 0.7, 0.4, 0.9, 0.3, 0.5, 0.6, 0.8
    ])
    prior(p)
    u = [0., 0., 0., 1., 1., 1., 0., 0., 1., 1., 0., 0., 0., 0., 1., 1., 0.]
    v = [
        4.35688457, 4.35688457, 4.35688457, 2., 2., 2., 1.47740087, 1.47740087,
        1.28886271, 1.28886271, 2., 2., 2., 2., 2., 2.9938003, 4.35688457
    ]
    print isp.gaussian_prior()(p[9], u[0], v[0])
    print isp.gaussian_prior()(p[10], u[1], v[1])
    print isp.gaussian_prior()(p[11], u[2], v[2])
    print isp.laplace_prior()(p[12], u[3], v[3])
    print isp.laplace_prior()(p[13], u[4], v[4])
    print isp.laplace_prior()(p[14], u[5], v[5])
    print isp.gaussian_prior()(p[15], u[6], v[6])
    print isp.gaussian_prior()(p[16], u[7], v[7])
    print isp.laplace_prior()(p[17], u[8], v[8])
    print isp.laplace_prior()(p[18], u[9], v[9])
    print isp.gaussian_prior()(p[19], u[10], v[10])
    print isp.gaussian_prior()(p[20], u[11], v[11])
    print isp.gaussian_prior()(p[21], u[12], v[12])
    print isp.gaussian_prior()(p[22], u[13], v[13])
    print isp.laplace_prior()(p[23], u[14], v[14])
    print isp.laplace_prior()(p[24], u[15], v[15])
    print isp.gaussian_prior()(p[25], u[16], v[16])
Ejemplo n.º 3
0
def inverse_stoc_hyper_priors_test7():
    """
	real nn arch with 16 nn params, one hyperparam, single granularity, 
	degen dependent params (2 priors)
	"""
    num_inputs = 1
    layer_sizes = [3, 2]
    num_outputs = 1
    print "num weights"
    n_dims = tools.calc_num_weights(num_inputs, layer_sizes, num_outputs)
    print tools.calc_num_weights(num_inputs, layer_sizes, num_outputs)
    weight_shapes = tools.get_weight_shapes(num_inputs, layer_sizes,
                                            num_outputs)
    print "weight shapes"
    print tools.get_weight_shapes(num_inputs, layer_sizes, num_outputs)
    granularity = 'single'
    hyper_dependence_lengths = tools.get_hyper_dependence_lengths(
        weight_shapes, granularity)
    n_stoc = len(hyper_dependence_lengths)
    print "number of weights per layer"
    print tools.calc_num_weights_layers(weight_shapes)
    dependence_lengths = tools.get_degen_dependence_lengths(weight_shapes)
    print "degen dependence lengths"
    print tools.get_degen_dependence_lengths(weight_shapes)
    hyperprior_types = [9]
    prior_types = [4, 5]
    hyperprior_params = [[1., 2.]]
    prior_hyperparams = [0., 1.]
    param_hyperprior_types = [0]
    param_prior_types = [0, 1, 0, 1, 0, 0, 1, 1, 0]
    prior = isp.inverse_stoc_hyper_prior(hyperprior_types, prior_types,
                                         hyperprior_params, prior_hyperparams,
                                         hyper_dependence_lengths,
                                         dependence_lengths,
                                         param_hyperprior_types,
                                         param_prior_types, n_stoc, n_dims)
    p = np.array([
        0.1, 0.5, 0.6, 0.7, 0.8, 0.9, 0.4, 0.2, 0.1, 0.5, 0.7, 0.8, 0.9, 0.4,
        0.2, 0.1, 0.5, 0.9
    ])
    prior(p)
    u = [0., 0., 0., 1., 1., 1., 0., 0., 1., 1., 0., 0., 0., 0., 1., 1., 0.]
    v = [
        4.35688457, 4.35688457, 4.35688457, 4.35688457, 4.35688457, 4.35688457,
        4.35688457, 4.35688457, 4.35688457, 4.35688457, 4.35688457, 4.35688457,
        4.35688457, 4.35688457, 4.35688457, 4.35688457, 4.35688457
    ]
    print isp.gaussian_prior()(p[1], u[0], v[0])
    print isp.gaussian_prior()(p[2], u[1], v[1])
    print isp.gaussian_prior()(p[3], u[2], v[2])
    print isp.laplace_prior()(p[4], u[3], v[3])
    print isp.laplace_prior()(p[5], u[4], v[4])
    print isp.laplace_prior()(p[6], u[5], v[5])
    print isp.gaussian_prior()(p[7], u[6], v[6])
    print isp.gaussian_prior()(p[8], u[7], v[7])
    print isp.laplace_prior()(p[9], u[8], v[8])
    print isp.laplace_prior()(p[10], u[9], v[9])
    print isp.gaussian_prior()(p[11], u[10], v[10])
    print isp.gaussian_prior()(p[12], u[11], v[11])
    print isp.gaussian_prior()(p[13], u[12], v[12])
    print isp.gaussian_prior()(p[14], u[13], v[13])
    print isp.laplace_prior()(p[15], u[14], v[14])
    print isp.laplace_prior()(p[16], u[15], v[15])
    print isp.gaussian_prior()(p[17], u[16], v[16])