View source code
							
							
						
								Display the source code in std/numeric.d from which this
								page was generated on github.
							
						
							Report a bug
							
						
								If you spot a problem with this page, click here to create a
								Bugzilla issue.
							
						
							
								Improve this page
							
							
					
								Quickly fork, edit online, and submit a pull request for this page.
								Requires a signed-in GitHub account. This works well for small changes.
								If you'd like to make larger changes you may want to consider using
								local clone.
							
						Module std.numeric
This module is a port of a growing fragment of the numeric header in Alexander Stepanov's Standard Template Library, with a few additions.
Functions
| Name | Description | 
|---|---|
| 
									cosineSimilarity(a, b)
								 | Computes the cosine similarity of input ranges aandb. The two ranges must have the same length. If both ranges define
length, the check is done once; otherwise, it is done at each
iteration. If either range has all-zero elements, return 0. | 
| 
									decimalToFactorial(decimal, fac)
								 | This function transforms decimalvalue into a value in the factorial number
system stored infac. | 
| 
									dotProduct(a, b)
								 | Computes the dot product of input ranges aandb. The two ranges must have the same length. If both ranges define
length, the check is done once; otherwise, it is done at each
iteration. | 
| 
									entropy(r)
								 | Computes entropy of input range rin bits. This
function assumes (without checking) that the values inrare all
in[0, 1]. For the entropy to be meaningful, oftenrshould
be normalized too (i.e., its values should sum to 1). The
two-parameter version stops evaluating as soon as the intermediate
result is greater than or equal tomax. | 
| 
									euclideanDistance(a, b)
								 | Computes Euclidean distance between input ranges aandb. The two ranges must have the same length. The three-parameter
version stops computation as soon as the distance is greater than or
equal tolimit(this is useful to save computation if a small
distance is sought). | 
| 
									fft(range)
								 | Convenience functions that create an Fftobject, run the FFT or inverse
 FFT and return the result.  Useful for one-off FFTs. | 
| 
									findLocalMin(f, ax, bx, relTolerance, absTolerance)
								 | Find a real minimum of a real function f(x)via bracketing.
Given a functionfand a range(ax .. bx),
returns the value ofxin the range which is closest to a minimum off(x).fis never evaluted at the endpoints ofaxandbx.
Iff(x)has more than one minimum in the range, one will be chosen arbitrarily.
Iff(x)returns NaN or -Infinity,(x, f(x), NaN)will be returned;
otherwise, this algorithm is guaranteed to succeed. | 
| 
									findRoot(f, a, b, tolerance)
								 | Find a real root of a real function f(x) via bracketing. | 
| 
									findRoot(f, ax, bx, fax, fbx, tolerance)
								 | Find root of a real function f(x) by bracketing, allowing the termination condition to be specified. | 
| 
									gapWeightedSimilarity(s, t, lambda)
								 | The so-called "all-lengths gap-weighted string kernel" computes a
similarity measure between sandtbased on all of their
common subsequences of all lengths. Gapped subsequences are also
included. | 
| 
									gapWeightedSimilarityIncremental(r1, r2, penalty)
								 | Similar to gapWeightedSimilarity, just works in an incremental
manner by first revealing the matches of length 1, then gapped matches
of length 2, and so on. The memory requirement is Ο(s). The time complexity is Ο(s) time
for computing each step. Continuing on the previous example: | 
| 
									gapWeightedSimilarityNormalized(s, t, lambda, sSelfSim, tSelfSim)
								 | The similarity per gapWeightedSimilarityhas an issue in that it
grows with the lengths of the two strings, even though the strings are
not actually very similar. For example, the range["Hello",
"world"]is increasingly similar with the range["Hello",
"world", "world", "world",...]as more instances of"world"are
appended. To prevent that,gapWeightedSimilarityNormalizedcomputes a normalized version of the similarity that is computed asgapWeightedSimilarity(s, t, lambda) /
sqrt(gapWeightedSimilarity(s, t, lambda) * gapWeightedSimilarity(s, t,
lambda)). The functiongapWeightedSimilarityNormalized(a
so-called normalized kernel) is bounded in[0, 1], reaches0only for ranges that don't match in any position, and1only for
identical ranges. | 
| 
									gcd(a, b)
								 | Computes the greatest common divisor of aandbby using
an efficient algorithm such as Euclid's
or Stein's algorithm. | 
| 
									inverseFft(range)
								 | Convenience functions that create an Fftobject, run the FFT or inverse
 FFT and return the result.  Useful for one-off FFTs. | 
| 
									jensenShannonDivergence(a, b)
								 | Computes the Jensen-Shannon divergence between aandb, which is the sum(ai * log(2 * ai / (ai + bi)) + bi * log(2 *
bi / (ai + bi))) / 2. The base of logarithm is 2. The ranges are
assumed to contain elements in[0, 1]. Usually the ranges are
normalized probability distributions, but this is not required or
checked byjensenShannonDivergence. If the inputs are normalized,
the result is bounded within[0, 1]. The three-parameter version
stops evaluations as soon as the intermediate result is greater than
or equal tolimit. | 
| 
									kullbackLeiblerDivergence(a, b)
								 | Computes the Kullback-Leibler divergence between input ranges aandb, which is the sumai * log(ai / bi). The base
of logarithm is 2. The ranges are assumed to contain elements in[0, 1]. Usually the ranges are normalized probability distributions,
but this is not required or checked bykullbackLeiblerDivergence. If any elementbiis zero and the
corresponding elementainonzero, returns infinity. (Otherwise,
ifai == 0 && bi == 0, the termai * log(ai / bi)is
considered zero.) If the inputs are normalized, the result is
positive. | 
| 
									normalize(range, sum)
								 | Normalizes values in rangeby multiplying each element with a
number chosen such that values sum up tosum. If elements inrangesum to zero, assignssum / rangeto
all. Normalization makes sense only if all elements inrangeare
positive.normalizeassumes that is the case without checking it. | 
| 
									sumOfLog2s(r)
								 | Compute the sum of binary logarithms of the input range r.
The error of this method is much smaller than with a naive sum of log2. | 
Classes
| Name | Description | 
|---|---|
| 
									Fft
								 | A class for performing fast Fourier transforms of power of two sizes. This class encapsulates a large amount of state that is reusable when performing multiple FFTs of sizes smaller than or equal to that specified in the constructor. This results in substantial speedups when performing multiple FFTs with a known maximum size. However, a free function API is provided for convenience if you need to perform a one-off FFT. | 
Structs
| Name | Description | 
|---|---|
| 
									CustomFloat
								 | Allows user code to define custom floating-point formats. These formats are
 for storage only; all operations on them are performed by first implicitly
 extracting them to realfirst. After the operation is completed the
 result can be stored in a custom floating-point value via assignment. | 
| 
									GapWeightedSimilarityIncremental
								 | Similar to gapWeightedSimilarity, just works in an incremental
manner by first revealing the matches of length 1, then gapped matches
of length 2, and so on. The memory requirement is Ο(s). The time complexity is Ο(s) time
for computing each step. Continuing on the previous example: | 
Enums
| Name | Description | 
|---|---|
| 
									CustomFloatFlags
								 | Format flags for CustomFloat. | 
Templates
| Name | Description | 
|---|---|
| 
									secantMethod
								 | Implements the secant method for finding a
root of the function funstarting from points[xn_1, x_n](ideally close to the root).Nummay befloat,double,
orreal. | 
Aliases
| Name | Type | Description | 
|---|---|---|
| CustomFloat | CustomFloat!(CustomFloatParams!bits) | Allows user code to define custom floating-point formats. These formats are
 for storage only; all operations on them are performed by first implicitly
 extracting them to realfirst. After the operation is completed the
 result can be stored in a custom floating-point value via assignment. | 
| FPTemporary | real | Defines the fastest type to use when storing temporaries of a
calculation intended to ultimately yield a result of type F(whereFmust be one offloat,double, orreal). When doing a multi-step computation, you may want to store
intermediate results asFPTemporary!F. | 
Authors
Andrei Alexandrescu, Don Clugston, Robert Jacques, Ilya Yaroshenko
License
					Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.