예제 #1
0
    /**
     * \return Gaussian second centered moment
     *
     * Computes the covariance from other representation of not available
     *
     * \throws GaussianUninitializedException if the Gaussian is of dynamic-size
     *         and has not been initialized using SetStandard(dimension).
     * \throws InvalidGaussianRepresentationException if non-of theember function)
     *         representation can be used as a source
     */
    virtual const SecondMoment& covariance() const
    {
        if (dimension() == 0)
        {
            fl_throw(GaussianUninitializedException());
        }

        if (is_dirty(CovarianceMatrix) && is_dirty(DiagonalCovarianceMatrix))
        {
            switch (select_first_representation<4>({{DiagonalSquareRootMatrix,
                                                    DiagonalPrecisionMatrix,
                                                    SquareRootMatrix,
                                                    PrecisionMatrix}}))
            {
            case SquareRootMatrix:
                covariance_ = square_root_ * square_root_.transpose();
                break;

            case PrecisionMatrix:
                covariance_ = precision_.inverse();
                break;

            case DiagonalSquareRootMatrix:
                covariance_.setZero(dimension(), dimension());
                for (int i = 0; i < square_root_.diagonalSize(); ++i)
                {
                    covariance_(i, i) = square_root_(i, i) * square_root_(i, i);
                }
                break;

            case DiagonalPrecisionMatrix:
                covariance_.setZero(dimension(), dimension());
                for (int i = 0; i < precision_.diagonalSize(); ++i)
                {
                    covariance_(i, i) = 1./precision_(i, i);
                }
                break;

            default:
                fl_throw(InvalidGaussianRepresentationException());
                break;
            }

            updated_internally(CovarianceMatrix);
        }

        return covariance_;
    }
예제 #2
0
파일: point_set.hpp 프로젝트: SimonEbner/fl
    /**
     * Resizes a dynamic-size PointSet
     *
     * \param Points_   Number of points
     *
     * \throws ResizingFixedSizeEntityException
     */
    void resize(int points_count)
    {
        if (int(weights_.size()) == points_count &&
            int(points_.cols()) == points_count) return;

        if (IsFixed<Points_>())
        {
            fl_throw(
                fl::ResizingFixedSizeEntityException(weights_.size(),
                                                     points_count,
                                                     "poit set Gaussian"));
        }

        points_.setZero(points_.rows(), points_count);

        weights_.resize(points_count, 1);
        const double weight = (points_count > 0)? 1. / double(points_count) : 0;
        for (int i = 0; i < points_count; ++i)
        {
            weights_(i).w_mean = weight;
            weights_(i).w_cov = weight;
        }

        // std::fill(weights_.begin(), weights_.end(), Weight{weight, weight});
    }
예제 #3
0
    /**
     * Sets the mean
     *
     * \param mean New Gaussian mean
     *
     * \throws WrongSizeException
     */
    virtual void mean(const Variate& mean) noexcept
    {
        if (mean_.size() != mean.size())
        {
            fl_throw(fl::WrongSizeException(mean.size(), mean_.size()));
        }

        mean_ = mean;
    }
예제 #4
0
    /**
     * Sets the covariance matrix in the precision form (inverse of covariance)
     *
     * \param precision New precision matrix
     *
     * \throws WrongSizeException
     */
    virtual void precision(const SecondMoment& precision) noexcept
    {
        if (precision_.size() != precision.size())
        {
            fl_throw(fl::WrongSizeException(
                         precision.size(), precision_.size()));
        }

        precision_ = precision;
        updated_externally(PrecisionMatrix);
    }
예제 #5
0
    /**
     * Sets the covariance matrix in the form of its square root (Cholesky f
     * actor)
     *
     * \param square_root New covariance square root
     *
     * \throws WrongSizeException
     */
    virtual void square_root(const SecondMoment& square_root)
    {
        if (square_root_.size() != square_root.size())
        {
            fl_throw(fl::WrongSizeException(
                         square_root.size(), square_root_.size()));
        }

        square_root_ = square_root;
        updated_externally(SquareRootMatrix);
    }
예제 #6
0
    virtual void covariance(const SecondMoment& covariance)
    {
        if (covariance_.size() != covariance.size())
        {
            fl_throw(fl::WrongSizeException(
                         covariance.size(), covariance_.size()));
        }

        covariance_ = covariance;
        updated_externally(CovarianceMatrix);
    }
예제 #7
0
    /**
     * Sets the covariance matrix in its diagonal precision form
     *
     * \param diag_precision New diagonal precision matrix
     *
     * \throws WrongSizeException
     */
    virtual void diagonal_precision(const SecondMoment& diag_precision)
    {
        if (diag_precision.size() != precision_.size())
        {
            fl_throw(
                fl::WrongSizeException(
                    diag_precision.size(), precision_.size()));
        }

        precision_ = diag_precision.diagonal().asDiagonal();
        updated_externally(DiagonalPrecisionMatrix);
    }
예제 #8
0
    /**
     * Sets the covariance matrix in its diagonal square root form
     *
     * \param diag_square_root New diagonal square root of the covariance
     *
     * \throws WrongSizeException
     */
    virtual void diagonal_square_root(const SecondMoment& diag_square_root)
    {
        if (diag_square_root.size() != square_root_.size())
        {
            fl_throw(
                fl::WrongSizeException(
                    diag_square_root.size(), square_root_.size()));
        }

        square_root_ = diag_square_root.diagonal().asDiagonal();
        updated_externally(DiagonalSquareRootMatrix);
    }
예제 #9
0
    /**
     * Sets the covariance matrix as a diagonal matrix
     *
     * \param diag_covariance New diagonal covariance matrix
     *
     * \throws WrongSizeException
     */
    virtual void diagonal_covariance(const SecondMoment& diag_covariance)
    {
        if (diag_covariance.size() != covariance_.size())
        {
            fl_throw(
                fl::WrongSizeException(
                    diag_covariance.size(), covariance_.size()));
        }

        covariance_ = diag_covariance.diagonal().asDiagonal();
        updated_externally(DiagonalCovarianceMatrix);
    }
예제 #10
0
    /**
     * \return Gaussian second centered moment in the square root form (
     * Cholesky decomposition)
     *
     * Computes the square root from other representation of not available
     *
     * \throws GaussianUninitializedException if the Gaussian is of dynamic-size
     *         and has not been initialized using SetStandard(dimension).
     * \throws InvalidGaussianRepresentationException if non-of the
     *         representation can be used as a source
     */
    virtual const SecondMoment& square_root() const
    {
        if (dimension() == 0)
        {
            fl_throw(GaussianUninitializedException());
        }

        if (is_dirty(SquareRootMatrix) && is_dirty(DiagonalSquareRootMatrix))
        {
            const SecondMoment& cov = covariance();

            switch (select_first_representation<4>({{DiagonalCovarianceMatrix,
                                                    DiagonalPrecisionMatrix,
                                                    CovarianceMatrix,
                                                    PrecisionMatrix}}))
            {
            case CovarianceMatrix:
            case PrecisionMatrix:
                fl::square_root(cov, square_root_);
                break;

            case DiagonalCovarianceMatrix:
            case DiagonalPrecisionMatrix:
                square_root_.setZero(dimension(), dimension());
                for (int i = 0; i < square_root_.rows(); ++i)
                {
                    square_root_(i, i) = std::sqrt(cov(i, i));
                }
                break;

            default:
                fl_throw(InvalidGaussianRepresentationException());
                break;
            }

            updated_internally(SquareRootMatrix);
        }

        return square_root_;
    }
예제 #11
0
    /**
     * \return Gaussian second centered moment in the precision form (inverse
     * of the covariance)
     *
     * Computes the precision from other representation of not available
     *
     * \throws GaussianUninitializedException if the Gaussian is of dynamic-size
     *         and has not been initialized using SetStandard(dimension).
     * \throws InvalidGaussianRepresentationException if non-of the
     *         representation can be used as a source
     */
    virtual const SecondMoment& precision() const
    {
        if (dimension() == 0)
        {
            fl_throw(GaussianUninitializedException());
        }

        if (is_dirty(PrecisionMatrix) && is_dirty(DiagonalPrecisionMatrix))
        {
            const SecondMoment& cov = covariance();

            switch (select_first_representation<4>({{DiagonalCovarianceMatrix,
                                                    DiagonalSquareRootMatrix,
                                                    CovarianceMatrix,
                                                    SquareRootMatrix}}))
            {
            case CovarianceMatrix:
            case SquareRootMatrix:
                precision_ = covariance().inverse();
                break;

            case DiagonalCovarianceMatrix:
            case DiagonalSquareRootMatrix:
                precision_.setZero(dimension(), dimension());
                for (int i = 0; i < cov.rows(); ++i)
                {
                    precision_(i, i) = 1./cov(i, i);
                }
                break;

            default:
                fl_throw(InvalidGaussianRepresentationException());
                break;
            }

            updated_internally(PrecisionMatrix);
        }

        return precision_;
    }
예제 #12
0
void Fl_Query::checkDatabaseState() {
    if (!m_database)
        fl_throw("Query is not connected to a database");
    if (!m_database->active())
        m_database->open();
}
예제 #13
0
unsigned Fl_Query::record_count() const {
    fl_throw("Record count is not supported for this database");
}