Beispiel #1
0
    def makeResponseLikelihood(self, *argv, **kwargs):
        """Make a prediction and predict its probability from a multivariate
        normal distribution
    
        Arguments:
            * argv: an undetermined number of tensors containg the weights
            and biases
            * realVals: the actual values for the predicted quantities
            * sd: standard deviation for output distribution, uses
            current hyper parameter value if nothing is given
            * hyperStates: A list containing all the hyper paramters
            * predict: the function used to make a prediction from the 
            current neural net
            * dtype: the datatype of the network
        Returns:
            * result: the log probabilities of the real vals given the
            predicted values
        """

        if (kwargs["sd"] is None):
            sd = kwargs["hyperStates"][-1]
        else:
            sd = kwargs["sd"]
        current = kwargs["predict"](True, argv[0])
        current = tf.transpose(current)
        sigma = tf.ones_like(current) * sd
        realVals = tf.reshape(kwargs["realVals"], current.shape)
        result = multivariateLogProb(sigma, current, realVals, kwargs["dtype"])

        return (result)
Beispiel #2
0
    def calculateHyperProbs(self, hypers, slopes):
        """Calculates the log probability of a set of weights and biases given
        new distribtuions as well as the probability of the new distribution
        means and SDs given their distribtuions.

        Arguments:
            * hypers: a list containg 4 new possible hyper parameters
            * weightBias: a list with the current weight and bias matrices

        Returns:
            * prob: log probability of weights and biases given the new hypers
            and the probability of the new hyper parameters given their priors
        """

        mean = hypers[0]
        sd = hypers[1]

        slopes = tf.square(slopes[0])

        prob = tf.reduce_sum(
            multivariateLogProb(sd, mean, slopes, dtype=self.dtype))

        # Calculate probability of new hypers
        val = self.meanHyper.log_prob([mean])
        prob += tf.reduce_sum(input_tensor=val)

        # Calculate probability of weights and biases given new hypers
        val = self.sdHyper.log_prob([sd])
        prob += tf.reduce_sum(input_tensor=val)

        return (prob)
Beispiel #3
0
    def calcultateLogProb(self, *argv, **kwargs):
        """Make a prediction and predict its probability from a multivariate
        normal distribution
    
        rguments:
            * argv: an undetermined number of tensors containg the weights
            and biases
            * realVals: the actual values for the predicted quantities
            * hypers: A list containing all the hyper paramters
            * predict: the function used to make a prediction from the 
            current neural net
            * dtype: the datatype of the network
            * n: Use every n networks
        Returns:
            * result: the log probabilities of the real vals given the
            predicted values
        """
        sd = []
        for x in range(len(kwargs["hypers"])):
            sd.append(kwargs["hypers"][x][-1])
        current = kwargs["predict"](argv[0], n=kwargs["n"])
        for x in range(len(current)):
            current[x] = tf.transpose(current[x])

        realVals = tf.reshape(kwargs["realVals"], current[0].shape)
        result = []
        for x in range(len(current)):

            result.append(
                multivariateLogProb(
                    tf.ones_like(current[0]) * sd[x], current[x], realVals,
                    kwargs["dtype"]))

        return (result)
Beispiel #4
0
    def calculateProbs(self, slopes):
        """Calculates the log probability of the slopes given
        their distributions in this layer.

        Arguments:
            * weightsBias: list with new possible weight and bias tensors

        Returns:
            * prob: log prob of weights and biases given their distributions
        """

        prob = tf.reduce_sum(
            multivariateLogProb(self.hypers[1],
                                self.hypers[0],
                                slopes,
                                dtype=self.dtype))

        return (prob)