Generate a sample of shape (nsam)
, or (ndim, nsam)
or (nsam, ndim)
that is scaled by the specified input amount
along the specified axis dim
.
Here, ndim
stands for the number of dimensions (data attributes) of the input sample
and nsam
represents the number of data points in the sample
.
If the input amount
is the square-root of the inverse of the variance of the (zero-mean) sample, then the returned sample will have a variance of one.
- Parameters
-
[in] | sample | : The input contiguous array of shape (nsam) , (ndim, nsam) , or (nsam, ndim) of,
-
type
complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128),
-
type
real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
containing the sample to be scaled.
|
[in] | dim | : The input scalar of type integer of default kind IK, whose value represents the dimension of the input sample containing different nsam observations:
-
If
dim = 1 , the input sample is assumed to have the shape (nsam, ndim) .
-
If
dim = 2 , the input sample is assumed to have the shape (ndim, nsam) .
(optional. It must be present if and only if the input arguments the condition rank(sample) > 1 holds.) |
[in] | amount | : The input scalar or the contiguous vector of,
-
the same type and kind as
sample ,
-
type
real of the same kind as that of sample if sample is of type complex ,
representing the amount by which the input sample must be scaled.
-
If the input
rank(sample) = 1 , then amount must be a scalar.
-
If the input
rank(sample) = 2 , then amount must be a vector of size ndim .
If the sample is to be scaled to have a unit variance, then the input amount corresponds to the square-root of the inverse of the variance of the sample that is returned by procedures collectively represented by the generic interface getVar.
Note that the size of the input amount must be consistent with the size of the input sample :
-
If the input argument
dim = 1 then, size(amount) == size(sample, 2) == ndim must hold.
-
If the input argument
dim = 2 then, size(amount) == size(sample, 1) == ndim must hold.
|
[in] | operation | : The input scalar constant that can be any of the following:
-
The constant transHerm implying that a Hermitian transpose of the input sample must be returned.
In other words, the actions getScaled(sample, dim, transHerm) and transpose(conjg(getScaled(sample, dim))) are equivalent.
Specifying transHerm for source of type other than complex is identical to specifying transSymm for source of type other than complex .
(optional, default = .false. . It can be present only if the condition rank(sample) == 2 holds.) |
- Returns
sampleScaled
: The output object of the same type and kind and rank as sample
, containing the scaled sample.
-
If the input
sample
is a vector, then sampleScaled
has the same shape and size as that of sample
.
-
If the input
sample
is a matrix of shape (nrow, ncol)
, then
-
sampleScaled
has the shape (nrow, ncol)
if operation
is missing.
-
sampleScaled
has the shape (ncol, nrow)
if operation = transHerm
.
Possible calling interfaces ⛓
sampleScaled(:)
= getScaled(sample(:), amount)
sampleScaled(:,:)
= getScaled(sample(:,:), dim, amount(:))
sampleScaled(:,:)
= getScaled(sample(:,:), dim, amount(:), operation)
Generate a sample of shape (nsam), or (ndim, nsam) or (nsam, ndim) that is scaled by the specified in...
This module contains classes and procedures for scaling (i.e., multiplying) univariate or multivariat...
- Warning
- The condition
1 <= dim .and. dim <= rank(sample)
must hold for the corresponding input arguments.
The condition size(amount) == size(sample, 3 - dim) .or. rank(sample) /= 2
must hold for the corresponding input arguments.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1
.
-
The
pure
procedure(s) documented herein become impure
when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1
.
By default, these procedures are pure
in release
build and impure
in debug
and testing
builds.
- See also
- getVar
setVar
getScaled
setScaled
Example usage ⛓
15 type(display_type) :: disp
19 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
20 call disp%show(
"!Scale a 1D zero-mean sample to have a unit variance.")
21 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
26 real(TKG),
allocatable :: sample(:)
27 call disp%show(
"sample = getLinSpace(x1 = 0., x2 = 10., count = 11_IK)")
28 sample
= getLinSpace(x1
= 0., x2
= 10., count
= 11_IK)
29 call disp%show(
"call setShifted(sample, -getMean(sample))")
35 call disp%show(
"sample = getScaled(sample, 1._TKG / sqrt(getVar(sample)))")
46 complex(TKG),
allocatable :: sample(:)
47 call disp%show(
"sample = cmplx(getLinSpace(x1 = 0., x2 = 10., count = 11_IK), -getLinSpace(x1 = 0., x2 = 10., count = 11_IK), TKG)")
48 sample
= cmplx(
getLinSpace(x1
= 0., x2
= 10., count
= 11_IK),
-getLinSpace(x1
= 0., x2
= 10., count
= 11_IK), TKG)
49 call disp%show(
"call setShifted(sample, -getMean(sample))")
55 call disp%show(
"sample = getScaled(sample, 1._TKG / sqrt(getVar(sample)))")
65 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
66 call disp%show(
"!Scale a 2D zero-mean sample to have a unit variance.")
67 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
72 real(TKG),
allocatable :: sample(:,:)
73 call disp%show(
"sample = reshape(getLinSpace(x1 = 1._TKG, x2 = 10._TKG, count = 10_IK), [2,5])")
74 sample
= reshape(
getLinSpace(x1
= 1._TKG, x2
= 10._TKG, count
= 10_IK), [
2,
5])
77 call disp%show(
"call setShifted(sample, dim, -getMean(sample, dim))")
81 call disp%show(
"getVar(sample, dim)")
83 call disp%show(
"sample = getScaled(sample, dim, 1._TKG / sqrt(getVar(sample, dim)))")
87 call disp%show(
"getVar(sample, dim)")
94 complex(TKG),
allocatable :: sample(:,:)
95 call disp%show(
"sample = cmplx(reshape(getLinSpace(x1 = 1._TKG, x2 = 10._TKG, count = 10_IK), [2,5]), -reshape(getLinSpace(x1 = 1._TKG, x2 = 10._TKG, count = 10_IK), [2,5]))")
96 sample
= cmplx(
reshape(
getLinSpace(x1
= 1._TKG, x2
= 10._TKG, count
= 10_IK), [
2,
5]),
-reshape(
getLinSpace(x1
= 1._TKG, x2
= 10._TKG, count
= 10_IK), [
2,
5]))
99 call disp%show(
"call setShifted(sample, dim, -getMean(sample, dim))")
103 call disp%show(
"getVar(sample, dim)")
105 call disp%show(
"sample = getScaled(sample, dim, 1._TKG / sqrt(getVar(sample, dim)))")
109 call disp%show(
"getVar(sample, dim)")
115 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
116 call disp%show(
"!Scale a 2D zero-mean sample to have a unit variance and transpose the result upon return.")
117 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
122 real(TKG),
allocatable :: sample(:,:)
123 call disp%show(
"sample = reshape(getLinSpace(x1 = 1._TKG, x2 = 10._TKG, count = 10_IK), [2,5])")
124 sample
= reshape(
getLinSpace(x1
= 1._TKG, x2
= 10._TKG, count
= 10_IK), [
2,
5])
127 call disp%show(
"call setShifted(sample, dim, -getMean(sample, dim))")
131 call disp%show(
"getVar(sample, dim)")
133 call disp%show(
"sample = getScaled(sample, dim, 1._TKG / sqrt(getVar(sample, dim)), transHerm)")
134 sample
= getScaled(sample, dim,
1._TKG / sqrt(
getVar(sample, dim)), transHerm)
137 call disp%show(
"getVar(sample, 3_IK - dim)")
144 complex(TKG),
allocatable :: sample(:,:)
145 call disp%show(
"sample = cmplx(reshape(getLinSpace(x1 = 1._TKG, x2 = 10._TKG, count = 10_IK), [2,5]), -reshape(getLinSpace(x1 = 1._TKG, x2 = 10._TKG, count = 10_IK), [2,5]))")
146 sample
= cmplx(
reshape(
getLinSpace(x1
= 1._TKG, x2
= 10._TKG, count
= 10_IK), [
2,
5]),
-reshape(
getLinSpace(x1
= 1._TKG, x2
= 10._TKG, count
= 10_IK), [
2,
5]))
149 call disp%show(
"call setShifted(sample, dim, -getMean(sample, dim))")
153 call disp%show(
"getVar(sample, dim)")
155 call disp%show(
"sample = getScaled(sample, dim, 1._TKG / sqrt(getVar(sample, dim)), transHerm)")
156 sample
= getScaled(sample, dim,
1._TKG / sqrt(
getVar(sample, dim)), transHerm)
159 call disp%show(
"getVar(sample, 3_IK - dim)")
Generate count evenly spaced points over the interval [x1, x2] if x1 < x2, or [x2,...
This is a generic method of the derived type display_type with pass attribute.
This is a generic method of the derived type display_type with pass attribute.
Generate and return the (weighted) mean of an input sample of nsam observations with ndim = 1 or 2 at...
Return a sample of shape (nsam), or (ndim, nsam) or (nsam, ndim) that is shifted by the specified inp...
Generate and return the variance of the input sample of type complex or real of shape (nsam) or (ndim...
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...
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
This module contains classes and procedures for computing the first moment (i.e., the statistical mea...
This module contains classes and procedures for shifting univariate or multivariate samples by arbitr...
This module contains classes and procedures for computing the properties related to the covariance ma...
Generate and return an object of type display_type.
Example Unix compile command via Intel ifort
compiler ⛓
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example Windows Batch compile command via Intel ifort
compiler ⛓
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
Example Unix / MinGW compile command via GNU gfortran
compiler ⛓
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example output ⛓
6sample
= getLinSpace(x1
= 0., x2
= 10., count
= 11_IK)
9-5.00000000,
-4.00000000,
-3.00000000,
-2.00000000,
-1.00000000,
+0.00000000,
+1.00000000,
+2.00000000,
+3.00000000,
+4.00000000,
+5.00000000
14-1.58113885,
-1.26491106,
-0.948683262,
-0.632455528,
-0.316227764,
+0.00000000,
+0.316227764,
+0.632455528,
+0.948683262,
+1.26491106,
+1.58113885
18sample
= cmplx(
getLinSpace(x1
= 0., x2
= 10., count
= 11_IK),
-getLinSpace(x1
= 0., x2
= 10., count
= 11_IK), TKG)
21(
-5.00000000,
+5.00000000), (
-4.00000000,
+4.00000000), (
-3.00000000,
+3.00000000), (
-2.00000000,
+2.00000000), (
-1.00000000,
+1.00000000), (
+0.00000000,
+0.00000000), (
+1.00000000,
-1.00000000), (
+2.00000000,
-2.00000000), (
+3.00000000,
-3.00000000), (
+4.00000000,
-4.00000000), (
+5.00000000,
-5.00000000)
26(
-1.11803401,
+1.11803401), (
-0.894427180,
+0.894427180), (
-0.670820355,
+0.670820355), (
-0.447213590,
+0.447213590), (
-0.223606795,
+0.223606795), (
+0.00000000,
+0.00000000), (
+0.223606795,
-0.223606795), (
+0.447213590,
-0.447213590), (
+0.670820355,
-0.670820355), (
+0.894427180,
-0.894427180), (
+1.11803401,
-1.11803401)
35sample
= reshape(
getLinSpace(x1
= 1._TKG, x2
= 10._TKG, count
= 10_IK), [
2,
5])
39-4.00000000,
-2.00000000,
+0.00000000,
+2.00000000,
+4.00000000
40-4.00000000,
-2.00000000,
+0.00000000,
+2.00000000,
+4.00000000
42+8.00000000,
+8.00000000
45-1.41421354,
-0.707106769,
+0.00000000,
+0.707106769,
+1.41421354
46-1.41421354,
-0.707106769,
+0.00000000,
+0.707106769,
+1.41421354
48+0.999999940,
+0.999999940
50sample
= cmplx(
reshape(
getLinSpace(x1
= 1._TKG, x2
= 10._TKG, count
= 10_IK), [
2,
5]),
-reshape(
getLinSpace(x1
= 1._TKG, x2
= 10._TKG, count
= 10_IK), [
2,
5]))
54(
-4.00000000,
+4.00000000), (
-2.00000000,
+2.00000000), (
+0.00000000,
+0.00000000), (
+2.00000000,
-2.00000000), (
+4.00000000,
-4.00000000)
55(
-4.00000000,
+4.00000000), (
-2.00000000,
+2.00000000), (
+0.00000000,
+0.00000000), (
+2.00000000,
-2.00000000), (
+4.00000000,
-4.00000000)
57+16.0000000,
+16.0000000
60(
-1.00000000,
+1.00000000), (
-0.500000000,
+0.500000000), (
+0.00000000,
+0.00000000), (
+0.500000000,
-0.500000000), (
+1.00000000,
-1.00000000)
61(
-1.00000000,
+1.00000000), (
-0.500000000,
+0.500000000), (
+0.00000000,
+0.00000000), (
+0.500000000,
-0.500000000), (
+1.00000000,
-1.00000000)
63+1.00000000,
+1.00000000
70sample
= reshape(
getLinSpace(x1
= 1._TKG, x2
= 10._TKG, count
= 10_IK), [
2,
5])
74-4.00000000,
-2.00000000,
+0.00000000,
+2.00000000,
+4.00000000
75-4.00000000,
-2.00000000,
+0.00000000,
+2.00000000,
+4.00000000
77+8.00000000,
+8.00000000
78sample
= getScaled(sample, dim,
1._TKG / sqrt(
getVar(sample, dim)), transHerm)
80-1.41421354,
-1.41421354
81-0.707106769,
-0.707106769
82+0.00000000,
+0.00000000
83+0.707106769,
+0.707106769
84+1.41421354,
+1.41421354
86+0.999999940,
+0.999999940
88sample
= cmplx(
reshape(
getLinSpace(x1
= 1._TKG, x2
= 10._TKG, count
= 10_IK), [
2,
5]),
-reshape(
getLinSpace(x1
= 1._TKG, x2
= 10._TKG, count
= 10_IK), [
2,
5]))
92(
-4.00000000,
+4.00000000), (
-2.00000000,
+2.00000000), (
+0.00000000,
+0.00000000), (
+2.00000000,
-2.00000000), (
+4.00000000,
-4.00000000)
93(
-4.00000000,
+4.00000000), (
-2.00000000,
+2.00000000), (
+0.00000000,
+0.00000000), (
+2.00000000,
-2.00000000), (
+4.00000000,
-4.00000000)
95+16.0000000,
+16.0000000
96sample
= getScaled(sample, dim,
1._TKG / sqrt(
getVar(sample, dim)), transHerm)
98(
-1.00000000,
-1.00000000), (
-1.00000000,
-1.00000000)
99(
-0.500000000,
-0.500000000), (
-0.500000000,
-0.500000000)
100(
+0.00000000,
-0.00000000), (
+0.00000000,
-0.00000000)
101(
+0.500000000,
+0.500000000), (
+0.500000000,
+0.500000000)
102(
+1.00000000,
+1.00000000), (
+1.00000000,
+1.00000000)
104+1.00000000,
+1.00000000
- Test:
- test_pm_sampleScale
- Todo:
- Very Low Priority: The functionality of this interface can be expanded to include scaling of higher dimensional input
sample
and whole sample
input arrays of arbitrary shape, although the latter is trivial using the Fortran array syntax.
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.
-
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.
-
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.
- Copyright
- Computational Data Science Lab
- Author:
- Amir Shahmoradi, Saturday 2:48 AM, August 22, 2021, Dallas, TX
Definition at line 198 of file pm_sampleScale.F90.