ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_distNormShell::getNormShellLogUDF Interface Reference

Generate and return the natural logarithm of the NormShell density function value(s) at the specified input point X, for the specified set of parameters of the single or mixture of NormShell distributions.
More...

Detailed Description

Generate and return the natural logarithm of the NormShell density function value(s) at the specified input point X, for the specified set of parameters of the single or mixture of NormShell distributions.

See the documentation of pm_distNormShell for details of the NormShell density function.

Parameters
[in]X: The input vector of size (1:ndim) of,
  1. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
containing the ndim-dimensional point at which the function must be evaluated.
[in]center: The input argument of the same type and kind as X, representing the center (location parameter: \(\mu\)) of the density function(s).
It can be,
  1. a contiguous vector of the same rank and size as the input X: center(1:ndim).
  2. a contiguous matrix whose first dimension is of the same size as the input X, and its second dimension is the number of unique density functions in the mixture: center(1:ndim, 1:nmix).
(optional, default = 0.. It must be present if and only if the input argument invCov is also present.)
[in]invCov: The input argument of the same type and kind as X, representing the inverse covariance matrix(es) ( \(\Sigma^{-1}\)) of the Normal distribution(s) of the density function(s).
It can be,
  1. a contiguous square matrix of the same rank as the size of the input X: invCov(1:ndim, 1:ndim).
  2. a contiguous array of rank 3 whose first and second dimensions are of the same size as the input X, and its third dimension is the number of unique density functions in the mixture: invCov(1:ndim, 1:ndim, 1:nmix).
(optional, default = the identity matrix. It must be present if and only if the input argument center is also present.)
[in]width: The input positive-valued argument of the same type and kind as the input X, representing the width of the shell(s) as specified by the shape parameter ( \(\omega\)) of the density function(s).
It can be,
  1. a scalar representing the width of the single density function.
  2. a contiguous vector of size nmix, representing the widths of individual density function(s) in the mixture.
(optional, default = 1.)
[in]radius: The input positive-valued argument of the same type and kind as the input X, representing the radius of the shell(s) as specified by the shape parameter ( \(\rho\)) of the density function(s).
It can be,
  1. a scalar representing the radius of the single density function.
  2. a contiguous vector of size nmix, representing the radii of individual density function(s) in the mixture.
(optional, default = 1.)
Returns
logUDF : The output of the same type and kind as the input argument X representing the natural logarithm of the value(s) of the density function(s) at the specified location X and parameters sets.
It is,
  1. a scalar if and only if the dimensionality of the input arguments corresponds to a single density function.
  2. a vector of size nmix if and only if the dimensionality of the input arguments corresponds to a mixture of nmix density functions.


Possible calling interfaces

! single density function.
logUDF = getNormShellLogUDF(X(1:ndim), width = width, radius = radius)
logUDF = getNormShellLogUDF(X(1:ndim), center(1:ndim), invCov(1:ndim, 1:ndim), width = width, radius = radius)
! mixture of density functions.
logUDF(1:nmix) = getNormShellLogUDF(X(1:ndim), width = width(1:nmix), radius = radius(1:nmix))
logUDF(1:nmix) = getNormShellLogUDF(X(1:ndim), center(1:ndim, 1:nmix), invCov(1:ndim, 1:ndim, 1:nmix), width = width(1:nmix), radius = radius(1:nmix))
Generate and return the natural logarithm of the NormShell density function value(s) at the specified...
This module contains procedures and generic interfaces for computing the Multivariate Normal Shell de...
Warning
The condition all([0. < width]) must hold for the corresponding input arguments.
The condition all([0. < radius]) must hold for the corresponding input arguments.
The condition size(X, 1) == size(center, 1) must hold for the corresponding input arguments.
The condition all(size(X, 1) == [size(invCov, 1), size(invCov, 2)]) must hold for the corresponding input arguments.
The condition size(invCov, rank(invCov)) == size(center, rank(invCov)) must hold for the corresponding input arguments.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
Remarks
The procedures under discussion are impure.


Example usage

1program example
2
3 use pm_kind, only: SK, IK
4 use pm_kind, only: RKG => RK ! all real kinds are supported.
9 use pm_io, only: display_type
10
11 implicit none
12
13 integer(IK), parameter :: NP = 5_IK
14
15 type(display_type) :: disp
16 disp = display_type(file = "main.out.F90")
17
18 call disp%skip()
19 call disp%show("getNormShellLogUDF([0._RKG]) ! 1D")
20 call disp%show( getNormShellLogUDF([0._RKG]) )
21 call disp%skip()
22
23 call disp%skip()
24 call disp%show("getNormShellLogUDF([0._RKG], [0._RKG], reshape([1._RKG], [1,1]), 5._RKG, 2._RKG) ! 1D")
25 call disp%show( getNormShellLogUDF([0._RKG], [0._RKG], reshape([1._RKG], [1,1]), 5._RKG, 2._RKG) )
26 call disp%skip()
27
28 call disp%skip()
29 call disp%show("getNormShellLogUDF([real(RKG) :: 0, 1], center = [-1._RKG, 1._RKG], invCov = reshape([1._RKG, .5_RKG, .5_RKG, 1._RKG], [2, 2]), width = 0.5_RKG, radius = 2._RKG) ! 2D")
30 call disp%show( getNormShellLogUDF([real(RKG) :: 0, 1], center = [-1._RKG, 1._RKG], invCov = reshape([1._RKG, .5_RKG, .5_RKG, 1._RKG], [2, 2]), width = 0.5_RKG, radius = 2._RKG) )
31 call disp%skip()
32
33 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34 ! Output an example density array for visualization.
35 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36
37 block
38 integer(IK) :: fileUnit, i, j
39 integer(IK), parameter :: nmix = 4
40 real(RKG) , parameter :: signif = 2
41 real(RKG) :: point(1000), width(nmix), radius(nmix), center(1, nmix), invCov(1, 1, nmix)
42 center = reshape([-1._RKG, +0._RKG, +1._RKG, +2._RKG], shape(center))
43 invCov = 1._RKG / reshape([+1._RKG, +2._RKG, +5._RKG, 0.5_RKG], shape(invCov))
44 radius = [1._RKG, 5._RKG, 2._RKG, 0.5_RKG]
45 width = .5_RKG
46 call setLinSpace( point &
47 , x1 = -10._RKG &
48 , x2 = +10._RKG &
49 )
50 open(newunit = fileUnit, file = "getNormShellLogUDF.D1.RK.txt")
51 do i = 1, size(point)
52 write(fileUnit,"(*(f0.8,:,','))") point(i), exp(getNormShellLogUDF(point(i:i), center, invCov, width, radius))
53 end do
54 close(fileUnit)
55 end block
56
57 block
58 use pm_mathSubAdd, only: operator(.subadd.)
59 use pm_arrayMembership, only: operator(.inrange.)
60 use pm_matrixInit, only: uppLowDia, getMatInit
62 integer(IK) :: fileUnit, i, j
63 real(RKG) , parameter :: signif = 2_IK
64 integer(IK) , parameter :: ndim = 2_IK, nmix = 2_IK, npnt = 700_IK
65 real(RKG) :: grid(ndim, npnt, npnt), center(ndim, nmix), invCov(ndim, ndim, nmix), width(nmix), radius(nmix)
66 center = 2 * reshape([-1._RKG, -1._RKG, 1._RKG, 1._RKG], shape(center))
67 invCov = spread(getMatInit([ndim, ndim], uppLowDia, 0._RKG, 0._RKG, 1._RKG), 3, nmix)
68 invCov(1,2,1) = 0.5
69 invCov(2,1,1) = 0.5
70 radius = [2._RKG, 2._RKG]
71 width = .5_RKG * [1._RKG, 1._RKG]
72 do i = 1, ndim
73 grid(i, :, :) = spread(getLinSpace(x1 = -6._RKG, x2 = +6._RKG, count = npnt) , 3 - i, npnt)
74 end do
75 open(newunit = fileUnit, file = "getNormShellLogUDF.D2.RK.txt")
76 do i = 1, size(grid, 2)
77 do j = 1, size(grid, 3)
78 write(fileUnit,"(*(f0.8,:,','))") grid(:, i, j), exp(getLogSumExp(getNormShellLogUDF(grid(:, i, j), center, invCov, width, radius)))
79 end do
80 end do
81 close(fileUnit)
82 end block
83
84end program example
Generate count evenly spaced points over the interval [x1, x2] if x1 < x2, or [x2,...
Return the linSpace output argument with size(linSpace) elements of evenly-spaced values over the int...
Return the logSpace output argument with size(logSpace) elements of logarithmically-evenly-spaced val...
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
Generate and return the natural logarithm of the sum of the exponential of the input array robustly (...
Generate and return a matrix of shape (shape(1), shape(2)) with the upper/lower triangle and the diag...
This module contains procedures and generic interfaces for assessing whether particular value(s) or a...
This module contains procedures and generic interfaces for generating arrays with linear or logarithm...
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter RK
The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
Definition: pm_kind.F90:543
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
This module contains the procedures and interfaces for computing the natural logarithm of the sum of ...
This module contains procedures and generic interfaces for evaluating the mathematical operator acti...
This module contains procedures and generic interfaces relevant to generating and initializing matric...
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2getNormShellLogUDF([0._RKG]) ! 1D
3-0.50000000000000000
4
5
6getNormShellLogUDF([0._RKG], [0._RKG], reshape([1._RKG], [1,1]), 5._RKG, 2._RKG) ! 1D
7-0.80000000000000016E-1
8
9
10getNormShellLogUDF([real(RKG) :: 0, 1], center = [-1._RKG, 1._RKG], invCov = reshape([1._RKG, .5_RKG, .5_RKG, 1._RKG], [2, 2]), width = 0.5_RKG, radius = 2._RKG) ! 2D
11-2.0000000000000000
12
13

Postprocessing of the example output
1#!/usr/bin/env python
2
3import matplotlib.pyplot as plt
4import pandas as pd
5import numpy as np
6import math
7import glob
8import sys
9
10linewidth = 2
11fontsize = 17
12
13marker ={ "CK" : "-"
14 , "IK" : "."
15 , "RK" : "-"
16 }
17xlab = { "CK" : "X ( real/imaginary components )"
18 , "IK" : "X ( integer-valued )"
19 , "RK" : "X ( real-valued )"
20 }
21legends = [ r"$\mu = -1.,~\Sigma = 1., \omega = .5, \rho = 1.$"
22 , r"$\mu = +0.,~\Sigma = 2., \omega = .5, \rho = 5.$"
23 , r"$\mu = +1.,~\Sigma = 5., \omega = .5, \rho = 2.$"
24 , r"$\mu = +2.,~\Sigma = .5, \omega = .5, \rho = .5$"
25 ]
26
27for kind in ["IK", "CK", "RK"]:
28
29 # Make 1d plot.
30
31 pattern = "*.D1."+kind+".txt"
32 fileList = glob.glob(pattern)
33 if len(fileList) == 1:
34
35 df = pd.read_csv(fileList[0], delimiter = ",")
36
37 fig = plt.figure(figsize = 1.25 * np.array([6.4, 4.8]), dpi = 300)
38 ax = plt.subplot()
39
40 if kind == "CK":
41 plt.plot( df.values[:, 0]
42 , df.values[:,1:5]
43 , marker[kind]
44 , linewidth = linewidth
45 #, color = "r"
46 )
47 plt.plot( df.values[:, 1]
48 , df.values[:,1:5]
49 , marker[kind]
50 , linewidth = linewidth
51 #, color = "blue"
52 )
53 else:
54 plt.plot( df.values[:, 0]
55 , df.values[:,1:5]
56 , marker[kind]
57 , linewidth = linewidth
58 #, color = "r"
59 )
60 ax.legend ( legends
61 , fontsize = fontsize
62 )
63
64 plt.xticks(fontsize = fontsize - 2)
65 plt.yticks(fontsize = fontsize - 2)
66 ax.set_xlabel(xlab[kind], fontsize = 17)
67 ax.set_ylabel("Probability Density Function (PDF)", fontsize = 17)
68
69 plt.grid(visible = True, which = "both", axis = "both", color = "0.85", linestyle = "-")
70 ax.tick_params(axis = "y", which = "minor")
71 ax.tick_params(axis = "x", which = "minor")
72
73 plt.tight_layout()
74 plt.savefig(fileList[0].replace(".txt",".png"))
75
76 elif len(fileList) > 1:
77
78 sys.exit("Ambiguous file list exists.")
79 # Make 2d plot.
80
81 pattern = "*.D2."+kind+".txt"
82 fileList = glob.glob(pattern)
83 if len(fileList) == 1:
84
85 df = pd.read_csv(fileList[0], delimiter = ",", header = None)
86 df = df.values
87
88 npnt = math.isqrt(len(df[:, 0]))
89 gridx = np.reshape(df[:, 0], newshape = (npnt, npnt), order = 'F')
90 gridy = np.reshape(df[:,1], newshape = (npnt, npnt), order = 'F')
91 gridz = np.reshape(df[:,2], newshape = (npnt, npnt), order = 'C')
92
93 fig, ax = plt.subplots(subplot_kw = {"projection": "3d"})
94 fig = plt.figure(figsize = 1.25 * np.array([6.4, 4.8]), dpi = 300)
95 ax = fig.add_subplot(1, 1, 1, projection = '3d')
96
97 ax.plot_surface(gridx, gridy, gridz, cmap = 'viridis', linewidth = 0)
98 ax.set_xlabel('X axis')
99 ax.set_ylabel('Y axis')
100 ax.set_zlabel("Log ( Density )", fontsize = 17)
101
102 plt.xticks(fontsize = fontsize - 2)
103 plt.yticks(fontsize = fontsize - 2)
104
105 plt.grid(visible = True, which = "both", axis = "both", color = "0.85", linestyle = "-")
106 ax.tick_params(axis = "y", which = "minor")
107 ax.tick_params(axis = "x", which = "minor")
108
109 plt.tight_layout()
110 plt.savefig(fileList[0].replace(".txt",".png"))
111
112 elif len(fileList) > 1:
113
114 sys.exit("Ambiguous file list exists.")

Visualization of the example output
Test:
test_pm_distNormShell


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Amir Shahmoradi, Oct 16, 2009, 11:14 AM, Michigan

Definition at line 161 of file pm_distNormShell.F90.


The documentation for this interface was generated from the following file: