forlab_stats.f90 Source File


Contents

Source Code


Source Code

module forlab_stats

    use stdlib_kinds, only: sp, dp, qp, int8, int16, int32, int64
    use stdlib_stats, only: mean
    implicit none
    private

    public :: mean, var, std
    public :: rng, randu, randn

    !> Version: Experimental
    !>
    !> Generate a normal distributed data scalar or vector.
    !> ([Specification](../page/specs/forlab_stats.html#randn))
    interface randn
        module function randn_0_sp(mean, std) result(random)
            real(sp), intent(in) :: mean, std
            real(sp) :: random
        end function randn_0_sp
        module function randn_1_sp(mean, std, ndim) result(random)
            real(sp), intent(in) :: mean, std
            integer, intent(in) :: ndim
            real(sp) :: random(ndim)
        end function randn_1_sp
        module function randn_0_dp(mean, std) result(random)
            real(dp), intent(in) :: mean, std
            real(dp) :: random
        end function randn_0_dp
        module function randn_1_dp(mean, std, ndim) result(random)
            real(dp), intent(in) :: mean, std
            integer, intent(in) :: ndim
            real(dp) :: random(ndim)
        end function randn_1_dp
    end interface randn

    !> Version: Experimental
    !>
    !> Generate an uniformly distributed data scalar or vector.
    !> ([Specification](../page/specs/forlab_stats.html#randomrandu))
    interface randu
        module function randu_0_rsp(start, end) result(random)
            real(sp), intent(in) :: start, end
            real(sp) :: random
        end function randu_0_rsp
        module function randu_1_rsp(start, end, ndim) result(random)
            real(sp), intent(in) :: start, end
            integer, intent(in) :: ndim
            real(sp) :: random(ndim)
        end function randu_1_rsp
        module function randu_0_rdp(start, end) result(random)
            real(dp), intent(in) :: start, end
            real(dp) :: random
        end function randu_0_rdp
        module function randu_1_rdp(start, end, ndim) result(random)
            real(dp), intent(in) :: start, end
            integer, intent(in) :: ndim
            real(dp) :: random(ndim)
        end function randu_1_rdp
        module function randu_0_iint8(start, end) result(random)
            integer(int8), intent(in) :: start, end
            integer(int8) :: random
        end function randu_0_iint8
        module function randu_1_iint8(start, end, ndim) result(random)
            integer(int8), intent(in) :: start, end
            integer, intent(in) :: ndim
            integer(int8) :: random(ndim)
        end function randu_1_iint8
        module function randu_0_iint16(start, end) result(random)
            integer(int16), intent(in) :: start, end
            integer(int16) :: random
        end function randu_0_iint16
        module function randu_1_iint16(start, end, ndim) result(random)
            integer(int16), intent(in) :: start, end
            integer, intent(in) :: ndim
            integer(int16) :: random(ndim)
        end function randu_1_iint16
        module function randu_0_iint32(start, end) result(random)
            integer(int32), intent(in) :: start, end
            integer(int32) :: random
        end function randu_0_iint32
        module function randu_1_iint32(start, end, ndim) result(random)
            integer(int32), intent(in) :: start, end
            integer, intent(in) :: ndim
            integer(int32) :: random(ndim)
        end function randu_1_iint32
        module function randu_0_iint64(start, end) result(random)
            integer(int64), intent(in) :: start, end
            integer(int64) :: random
        end function randu_0_iint64
        module function randu_1_iint64(start, end, ndim) result(random)
            integer(int64), intent(in) :: start, end
            integer, intent(in) :: ndim
            integer(int64) :: random(ndim)
        end function randu_1_iint64
    end interface randu

    interface
        module subroutine rng(seed)
            integer, intent(in), optional :: seed
        end subroutine rng
    end interface

    interface var
        !! `std` computes vector and matrix standard deviations.
        !!([Specification](../module/forlab_var.html))
        real(sp) module function var_1_sp(x, w)
            real(sp), dimension(:), intent(in) :: x
            integer, intent(in), optional :: w
        end function var_1_sp
        module function var_2_sp(A, w, dim)
            real(sp), dimension(:), allocatable :: var_2_sp
            real(sp), dimension(:, :), intent(in) :: A
            integer, intent(in), optional :: w, dim
        end function var_2_sp
        real(dp) module function var_1_dp(x, w)
            real(dp), dimension(:), intent(in) :: x
            integer, intent(in), optional :: w
        end function var_1_dp
        module function var_2_dp(A, w, dim)
            real(dp), dimension(:), allocatable :: var_2_dp
            real(dp), dimension(:, :), intent(in) :: A
            integer, intent(in), optional :: w, dim
        end function var_2_dp
    end interface var
    interface std
        !! `std` computes vector and matrix standard deviations.
        !!([Specification](../module/forlab_var.html))
        real(sp) module function std_1_sp(x, w)
            real(sp), dimension(:), intent(in) :: x
            integer, intent(in), optional :: w
        end function std_1_sp
        module function std_2_sp(A, w, dim)
            real(sp), dimension(:), allocatable :: std_2_sp
            real(sp), dimension(:, :), intent(in) :: A
            integer, intent(in), optional :: w, dim
        end function std_2_sp
        real(dp) module function std_1_dp(x, w)
            real(dp), dimension(:), intent(in) :: x
            integer, intent(in), optional :: w
        end function std_1_dp
        module function std_2_dp(A, w, dim)
            real(dp), dimension(:), allocatable :: std_2_dp
            real(dp), dimension(:, :), intent(in) :: A
            integer, intent(in), optional :: w, dim
        end function std_2_dp
    end interface std

end module forlab_stats