示例#1
0
    def exact_moment_equations(self, maxdeg):
        """
        return scipy moment equation expressions
        """
        D = self.d
        ws, pis = self.betas, self.weights
        deg_x, deg_b = maxdeg

        sigma = self.sigma_val
        alphas = list(dominated_elements((deg_x + deg_b for _ in xrange(D))))
        alphas = list(dominated_elements((deg_x for _ in xrange(D))))
        alphabs = [(alpha, b) for alpha in alphas
                   for b in xrange(1, deg_b + 1)]
        alphas_ = list(dominated_elements((deg_x + deg_b for _ in xrange(D))))
        moments_x = expected_gaussian_moments(sigma, alphas_)
        moments_y = exact_moments_y(ws, pis, moments_x, alphabs)

        constrs = []
        con = {}
        for b in xrange(1, deg_b + 1):
            for alpha in dominated_elements((deg_x for _ in xrange(D))):
                eqn = describe_moment_polynomial(self.sym_betas, moments_x,
                                                 moments_y[(alpha, b)], alpha,
                                                 b)
                con[(alpha, b)] = eqn
                constrs.append(eqn)
        return constrs, con
示例#2
0
    def empirical_moment_equations(self, xs, maxdeg):
        """
        return scipy moment equation expressions
        """
        xs, ys = xs

        D = self.d
        ws, pis = self.betas, self.weights
        deg_x, deg_b = maxdeg

        alphas = list(dominated_elements((deg_x + deg_b for _ in xrange(D))))
        alphas = list(dominated_elements((deg_x for _ in xrange(D))))
        alphabs = [(alpha, b) for alpha in alphas
                   for b in xrange(1, deg_b + 1)]
        alphas_ = list(dominated_elements((deg_x + deg_b for _ in xrange(D))))
        moments_x = compute_expected_moments(xs, alphas_)
        moments_y = compute_expected_moments_y(ys, xs, alphabs)

        constrs = []
        for b in xrange(1, deg_b + 1):
            for alpha in dominated_elements((deg_x for _ in xrange(D))):
                constrs.append(
                    describe_moment_polynomial(self.sym_betas, moments_x,
                                               moments_y[(alpha, b)], alpha,
                                               b))
        return constrs
示例#3
0
    def exact_moments(self, terms):
        """
        Get the exact moments corresponding to a particular term
        """
        terms = [
            sympify(term) if isinstance(term, str) else term for term in terms
        ]

        # Get max degree of b and x in terms
        D = self.d
        ws, pis = self.betas, self.weights
        deg_b = max(self._y_power(term) for term in terms)
        deg_x = max(max(self._x_power(term) for term in terms))

        sigma = self.sigma_val
        alphas = list(dominated_elements((deg_x for _ in xrange(D))))
        alphabs = [(alpha, b) for alpha in alphas
                   for b in xrange(1, deg_b + 1)]
        alphas_ = list(dominated_elements((deg_x + deg_b for _ in xrange(D))))
        moments_x = expected_gaussian_moments(sigma, alphas_)
        moments_y = exact_moments_y(ws, pis, moments_x, alphabs)

        moment = {term: 0. for term in terms}
        for term in terms:
            b = self._y_power(term)
            alpha = self._x_power(term)
            moment[term] = moments_y[(alpha, b)]
        return moment
示例#4
0
    def empirical_moments(self, xs, terms):
        """
        Get the exact moments corresponding to a particular term
        """
        terms = [
            sympify(term) if isinstance(term, str) else term for term in terms
        ]

        xs, ys = xs

        D = self.d
        deg_b = max(self._y_power(term) for term in terms)
        deg_x = max(max(self._x_power(term) for term in terms))

        alphas = list(dominated_elements((deg_x + deg_b for _ in xrange(D))))
        alphas = list(dominated_elements((deg_x for _ in xrange(D))))
        alphabs = [(alpha, b) for alpha in alphas
                   for b in xrange(1, deg_b + 1)]
        moments_y = compute_expected_moments_y(ys, xs, alphabs)

        moment = {term: 0. for term in terms}
        for term in terms:
            alpha, b = self._x_power(term), self._y_power(term)
            moment[term] = moments_y[(alpha, b)]
        return moment
示例#5
0
    def exact_moments(self, terms):
        """
        Get the exact moments corresponding to a particular term
        """
        terms = [sympify(term) if isinstance(term, str) else term for term in terms]

        # Get max degree of b and x in terms
        D = self.d
        ws, pis = self.betas, self.weights
        deg_b = max(self._y_power(term) for term in terms)
        deg_x = max(max(self._x_power(term) for term in terms))

        sigma = self.sigma_val
        alphas = list(dominated_elements((deg_x for _ in xrange(D))))
        alphabs = [(alpha, b) for alpha in alphas for b in xrange(1,deg_b+1)]
        alphas_ = list(dominated_elements((deg_x + deg_b for _ in xrange(D))))
        moments_x = expected_gaussian_moments(sigma, alphas_)
        moments_y = exact_moments_y(ws, pis, moments_x, alphabs)

        moment = {term : 0. for term in terms}
        for term in terms:
            b = self._y_power(term)
            alpha = self._x_power(term)
            moment[term] = moments_y[(alpha,b)]
        return moment
示例#6
0
    def observed_monomials(self, maxdeg):
        """
        return scipy moment monomials
        """
        D = self.d
        deg_x, deg_b = maxdeg
        alphas = list(dominated_elements((deg_x for _ in xrange(D))))
        alphabs = [(alpha, b) for alpha in alphas for b in xrange(1,deg_b+1)]
        x = [sympify("x%d"%i) for i in xrange(D)]
        y = sympify("y")
        terms = map(sympify, [monomial(x, alpha) * y**b for (alpha,b) in alphabs])

        return terms
示例#7
0
    def empirical_moment_equations(self, xs, maxdeg):
        """
        return scipy moment equation expressions
        """
        xs, ys = xs

        D = self.d
        ws, pis = self.betas, self.weights
        deg_x, deg_b = maxdeg

        alphas = list(dominated_elements((deg_x + deg_b for _ in xrange(D))))
        alphas = list(dominated_elements((deg_x for _ in xrange(D))))
        alphabs = [(alpha, b) for alpha in alphas for b in xrange(1,deg_b+1)]
        alphas_ = list(dominated_elements((deg_x + deg_b for _ in xrange(D))))
        moments_x = compute_expected_moments(xs, alphas_)
        moments_y = compute_expected_moments_y(ys, xs, alphabs)

        constrs = []
        for b in xrange(1, deg_b+1):
            for alpha in dominated_elements((deg_x for _ in xrange(D))):
                constrs.append(describe_moment_polynomial(self.sym_betas, moments_x, moments_y[(alpha, b)], alpha, b))
        return constrs
示例#8
0
    def empirical_moments(self, xs, terms):
        """
        Get the exact moments corresponding to a particular term
        """
        terms = [sympify(term) if isinstance(term, str) else term for term in terms]

        xs, ys = xs

        D = self.d
        deg_b = max(self._y_power(term) for term in terms)
        deg_x = max(max(self._x_power(term) for term in terms))

        alphas = list(dominated_elements((deg_x + deg_b for _ in xrange(D))))
        alphas = list(dominated_elements((deg_x for _ in xrange(D))))
        alphabs = [(alpha, b) for alpha in alphas for b in xrange(1,deg_b+1)]
        moments_y = compute_expected_moments_y(ys, xs, alphabs)

        moment = {term : 0. for term in terms}
        for term in terms:
            alpha, b = self._x_power(term), self._y_power(term)
            moment[term] = moments_y[(alpha,b)]
        return moment
示例#9
0
    def observed_monomials(self, maxdeg):
        """
        return scipy moment monomials
        """
        D = self.d
        deg_x, deg_b = maxdeg
        alphas = list(dominated_elements((deg_x for _ in xrange(D))))
        alphabs = [(alpha, b) for alpha in alphas
                   for b in xrange(1, deg_b + 1)]
        x = [sympify("x%d" % i) for i in xrange(D)]
        y = sympify("y")
        terms = map(sympify,
                    [monomial(x, alpha) * y**b for (alpha, b) in alphabs])

        return terms
示例#10
0
    def exact_moment_equations(self, maxdeg):
        """
        return scipy moment equation expressions
        """
        D = self.d
        ws, pis = self.betas, self.weights
        deg_x, deg_b = maxdeg

        sigma = self.sigma_val
        alphas = list(dominated_elements((deg_x + deg_b for _ in xrange(D))))
        alphas = list(dominated_elements((deg_x for _ in xrange(D))))
        alphabs = [(alpha, b) for alpha in alphas for b in xrange(1,deg_b+1)]
        alphas_ = list(dominated_elements((deg_x + deg_b for _ in xrange(D))))
        moments_x = expected_gaussian_moments(sigma, alphas_)
        moments_y = exact_moments_y(ws, pis, moments_x, alphabs)

        constrs = []
        con = {}
        for b in xrange(1, deg_b+1):
            for alpha in dominated_elements((deg_x for _ in xrange(D))):
                eqn = describe_moment_polynomial(self.sym_betas, moments_x, moments_y[(alpha, b)], alpha, b)
                con[(alpha,b)] = eqn
                constrs.append(eqn)
        return constrs, con