### Get List of Clustering Methods Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.clustering.html Example showing how to call `clustering-methods-list` to retrieve the names of all supported clustering algorithms. ```Clojure clustering-methods-list ;;=> (:spectral :dbscan ;;=> :k-means :mec ;;=> :clarans :g-means ;;=> :lloyd :x-means ;;=> :deterministic-annealing :denclue) ``` -------------------------------- ### Power Distribution Parameter Configuration Examples Source: https://github.com/generateme/fastmath/blob/master/docs/clay/random.html Examples of parameter maps for configuring the Power distribution with different values. ```Clojure {:a 0, :b 1, :c 2} ``` ```Clojure {:a 1, :b 2, :c 1.25} ``` -------------------------------- ### Pareto Parameter Configuration Examples Source: https://github.com/generateme/fastmath/blob/master/docs/clay/random.html Examples of parameter maps for configuring the Pareto distribution with different values. ```Clojure {:scale 1, :shape 1} ``` ```Clojure {:scale 2, :shape 2} ``` -------------------------------- ### Normal-Inverse Gaussian Parameter Configuration Examples Source: https://github.com/generateme/fastmath/blob/master/docs/clay/random.html Examples of parameter maps for configuring the Normal-Inverse Gaussian distribution with different values. ```Clojure {:alpha 1, :beta 0, :mu 0, :delta 1} ``` ```Clojure {:alpha 2, :beta 1, :mu 0, :delta 0.5} ``` -------------------------------- ### Reciprocal Sqrt Parameter Configuration Examples Source: https://github.com/generateme/fastmath/blob/master/docs/clay/random.html Examples of parameter maps for configuring the Reciprocal Sqrt distribution with different values. ```Clojure {:a 0.5} ``` ```Clojure {:a 2} ``` -------------------------------- ### K-Means++ Clustering Examples in Clojure Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.clustering.html Provides multiple examples for the `k-means` function. The first demonstrates basic clustering of a numeric vector. The second shows how to `regroup` the clustering results into separate maps for each cluster. The third example illustrates using the clustering result as a predictor function to classify new data points. ```Clojure (k-means [1 2 3 -1 -1 2 -1 11 111] 4) ;;=> #fastmath.clustering.ClusteringResult ;;=> {:clustering (3 3 3 0 0 3 0 2 1), ;;=> :clusters 4, ;;=> :data [1 2 3 -1 -1 2 -1 11 111], ;;=> :info {:distortion 2.0000000000000004}, ;;=> :obj ;;=> #object[smile.clustering.KMeans 0x53cea40f "Cluster distortion: 2.00000\nCluster size of 9 data points:\nCluster 1 3 (33.3%)\nCluster 2 1 (11.1%)\nCluster 3 1 (11.1%)\nCluster 4 4 (44.4%)\n"], ;;=> :predict #, ;;=> :representatives ((-1.0) (111.0) (11.0) (2.0)), ;;=> :sizes (3 1 1 4 0), ;;=> :type :k-means} ``` ```Clojure (regroup (k-means [1 2 3 -1 -1 2 -1 11 111] 4)) ;;=> ({:data (1 2 3 2), :key 3, :representative (2.0), :size 4} ;;=> {:data (-1 -1 -1), :key 0, :representative (-1.0), :size 3} ;;=> {:data (11), :key 2, :representative (11.0), :size 1} ;;=> {:data (111), :key 1, :representative (111.0), :size 1}) ``` ```Clojure (let [cl (k-means [1 2 3 -1 -1 2 -1 11 111] 4)] [(cl -1) (cl 10) (cl 100) (cl 1) (cl -1000) (cl 1000)]) ;;=> [3 2 1 0 3 1] ``` -------------------------------- ### Clojure: Linear Optimization Example Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.optimization.html An example demonstrating the use of `linear-optimization` to solve a simple linear programming problem with a target function and multiple constraints. Shows the resulting optimal point and the function's value at that point. ```Clojure (linear-optimization [-1 4 0] [[-3 1] :<= 6 [-1 -2] :>= -4 [0 1] :>= -3]) ;; => [(9.999999999999995 -3.0) -21.999999999999993] ``` -------------------------------- ### Watson U Distribution API and Parameter Examples Source: https://github.com/generateme/fastmath/blob/master/docs/clay/random.html Documents the `:watson-u` distribution, including its default parameters and examples of parameter maps for configuration. ```APIDOC Watson U Distribution: Name: :watson-u Default parameters: :n: 2 ``` ```Clojure {:n 2} ``` ```Clojure {:n 10} ``` -------------------------------- ### Watson G Distribution API and Parameter Examples Source: https://github.com/generateme/fastmath/blob/master/docs/clay/random.html Documents the `:watson-g` distribution, including its default parameters and examples of parameter maps for configuration. ```APIDOC Watson G Distribution: Name: :watson-g Default parameters: :n: 2 ``` ```Clojure {:n 2} ``` ```Clojure {:n 10} ``` -------------------------------- ### Rayleigh Distribution Parameter Configuration Examples Source: https://github.com/generateme/fastmath/blob/master/docs/clay/random.html Examples of parameter maps for configuring the Rayleigh distribution with different values. Note: The examples use `:b` and `:c` parameters which are not listed in the default parameters for Rayleigh. ```Clojure {:a 0, :b 1, :c 2} ``` ```Clojure {:a 1, :b 2, :c 1.25} ``` -------------------------------- ### Pearson VI Parameter Configuration Examples Source: https://github.com/generateme/fastmath/blob/master/docs/clay/random.html Examples of parameter maps for configuring the Pearson VI distribution with different values. Note: One example uses `:scale` and `:shape` parameters, which are typically associated with Pareto distribution. ```Clojure {:alpha1 1, :alpha2 1, :beta 1} ``` ```Clojure {:scale 2, :shape 2} ``` -------------------------------- ### Clojure: Vector Creation with as-vec Examples Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.vector.html Examples demonstrating the `as-vec` function to create vectors. It shows how to initialize vectors with default zeros, fill them with repeated values, and convert existing vector types while applying new values. ```Clojure (as-vec [1 2 3]) ;;=> [0.0 0.0 0.0] (as-vec [3 2 3] (repeat -10)) ;;=> [-10 -10 -10] (as-vec (vec3 1 2 3) (repeat -10)) ;;=> [-10.0 -10.0 -10.0] (type (as-vec (array-vec [1 1 11 2 3]) (repeat -10))) ;;=> class fastmath.vector.ArrayVec ``` -------------------------------- ### Beta Binomial (BB) Distribution API and Parameter Examples Source: https://github.com/generateme/fastmath/blob/master/docs/clay/random.html Documents the `:bb` distribution, including its default parameters and examples of parameter maps for configuration. It also explains the relationship between its parameters and the Wikipedia definition of alpha and beta. ```APIDOC Beta Binomial (BB) Distribution: Name: :bb Default parameters: :mu (probability): 0.5 :sigma (dispersion): 1.0 :bd (binomial denominator): 10 Parameters mu, sigma in terms of alpha, beta (Wikipedia definition): probability: mu = alpha / (alpha + beta) dispersion: sigma = 1 / (alpha + beta) ``` ```Clojure {:mu 0.5, :sigma 1, :bd 10} ``` ```Clojure {:mu 0.65, :sigma 0.3, :bd 20} ``` -------------------------------- ### mean Usage Example in FastMath Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.random.html Example demonstrating how to retrieve the mean of a gamma distribution. ```Clojure (mean (distribution :gamma)) ;;=> 4.0 ``` -------------------------------- ### Triangular Distribution Parameter Configuration Examples Source: https://github.com/generateme/fastmath/blob/master/docs/clay/random.html Examples of parameter maps for configuring the Triangular distribution with different values for its limits and mode. ```Clojure {:a -1, :b 1, :c 0} ``` ```Clojure {:a -0.5, :b 1, :c 0.5} ``` -------------------------------- ### Clojure: ArrayVec Creation and Usage Examples Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.vector.html Examples demonstrating the creation of `ArrayVec` instances from various inputs like lists, ranges, and single numbers. It also shows basic operations like accessing elements by index, counting elements, and converting to a sequence. ```Clojure (array-vec [1 2 3 4 5 6 7]) ;;=> [1.0 2.0 3.0 4.0 5.0 6.0 7.0] (array-vec (range 0.0 1.0 0.25)) ;;=> [0.0 0.25 0.5 0.75] (array-vec 11) ;;=> [0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0] ``` ```Clojure (nth (array-vec [9 8 7 6]) 2) ;;=> 7.0 (count (array-vec (range 0.1 1.0 0.05))) ;;=> 18 (seq (array-vec [1 2])) ;;=> (1.0 2.0) ``` -------------------------------- ### Install fastmath Stable Version Source: https://github.com/generateme/fastmath/blob/master/README.md This snippet shows the Leiningen/Clojure CLI dependency declaration for installing the stable 2.4.0 version of the fastmath library. Add this to your `project.clj` or `deps.edn` file to include fastmath in your project. ```Clojure [generateme/fastmath "2.4.0"] ``` -------------------------------- ### QDA Classifier Validation Example Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.classification.html Demonstrates how to train a QDA classifier and validate its performance using test data and labels. The example extracts and displays statistics on invalid predictions and overall accuracy. ```Clojure (let [cl (qda train-data train-labels)] (select-keys (validate cl test-data test-labels) [:invalid :stats])) ;;=> {:invalid {:count 0, :data (), :prediction (), :truth ()}, ;;=> :stats {:accuracy 1.0}} ``` -------------------------------- ### Bernoulli Distribution API and Parameter Examples Source: https://github.com/generateme/fastmath/blob/master/docs/clay/random.html Documents the `:bernoulli` distribution, including its default parameters and examples of parameter maps for configuration. It is equivalent to a Binomial distribution with trials=1. ```APIDOC Bernoulli Distribution: Name: :bernoulli Default parameters: :p (probability): 0.5 ``` ```Clojure {:p 0.5} ``` ```Clojure {:p 0.25} ``` -------------------------------- ### Clojure Akima Spline Usage Example Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.interpolation.html Example demonstrating how to use the `akima-spline` function within the generic `interpolate` framework, showing an expected output value. ```Clojure (interpolate akima-spline ...) ;;=> 0.6825735245080953 ``` -------------------------------- ### Clojure B-Spline Usage Example Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.interpolation.html Example demonstrating how to use the `b-spline` function within the generic `interpolate` framework, showing an expected output value. ```Clojure (interpolate b-spline ...) ;;=> 0.5600852765013091 ``` -------------------------------- ### Student's t-Distribution Parameter Configuration Examples Source: https://github.com/generateme/fastmath/blob/master/docs/clay/random.html Examples of parameter maps for configuring the Student's t-distribution with different values for degrees of freedom. ```Clojure {:degrees-of-freedom 1} ``` ```Clojure {:degrees-of-freedom 50} ``` -------------------------------- ### means Usage Examples in FastMath Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.random.html Examples demonstrating how to retrieve the means for multivariate distributions like multi-normal and Dirichlet. ```Clojure (means (distribution :multi-normal)) ;;=> [0.0 0.0] ``` ```Clojure (means (distribution :dirichlet {:alpha [2 2]})) ;;=> (0.5 0.5) ``` -------------------------------- ### X-Means Clustering Example with Gaussian Data Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.clustering.html Demonstrates the application of the X-Means algorithm to a synthetically generated dataset with a Gaussian distribution, aiming to identify the optimal number of clusters. The example showcases how X-Means automatically determines the cluster count and provides details on cluster sizes and representatives. ```Clojure ((juxt :clusters :sizes :representatives) (x-means (repeatedly 10000 (fn* [] (r/randval (r/grand) (r/grand 5 1.0)))) 4)) ;;=> [2 (4906 5094) ((-6.044219999840173E-4) (4.972183058432598))] ``` -------------------------------- ### Initialize Mersenne Twister PRNG for Examples Source: https://github.com/generateme/fastmath/blob/master/docs/clay/random.html Defines a `my-prng` variable initialized with a Mersenne Twister PRNG, which will be used in the following random number generation examples. ```Clojure (def my-prng (r/rng :mersenne)) ``` -------------------------------- ### Clojure Example: Creating a Gaussian Process Object Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.gp.html Demonstrates how to create a `gaussian-process` object in Clojure, showing both a basic instantiation and one with custom parameters for normalization, kernel, scaling, and noise. ```Clojure (gaussian-process [1 2 3] [-1 2 1]) ;;=> fastmath.gp.GaussianProcess@7860dc0e (gaussian-process [1 2 3] [-1 2 1] {:normalize? true, :kernel (k/kernel :gaussian 0.5), :kscale 2.0, :noise 0.1}) ;;=> fastmath.gp.GaussianProcess@4cee1580 ``` -------------------------------- ### API & Examples: Normalize Value to Range (`norm`) Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.core.html API documentation and examples for the `norm` function, which normalizes a value `v` from a `[start, stop]` range to `[0,1]` or maps it to a `[start2, stop2]` range. This function is related to `make-norm`. ```APIDOC (norm v start stop) (norm v start1 stop1 start2 stop2) ``` ```Clojure (norm 0.234 -1.0 1.0) ;;=> 0.617 ``` ```Clojure (norm 0.234 1.0 -1.0) ;;=> 0.383 ``` ```Clojure (norm (cos HALF_PI) -1.0 1.0 0.0 255.0) ;;=> 127.5 ``` ```Clojure (norm (cos HALF_PI) -1.0 1.0 255.0 0.0) ;;=> 127.5 ``` -------------------------------- ### Deterministic Annealing Clustering Example in Clojure Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.clustering.html Illustrates the application of the `deterministic-annealing` function to cluster a dataset of 1000 samples into 4 clusters with a specified alpha value. The example then uses `regroup` to structure the results, showing cluster keys, representatives, and sizes. ```Clojure (map (fn [m] (dissoc m :data)) (-> (repeatedly 1000 (fn* [] (vector (r/randval (r/grand) (r/grand 5 1.0)) (r/randval (r/grand) (r/grand 5 1.0))))) (deterministic-annealing 4 0.5) (regroup))) ;;=> ({:key 0, ;;=> :representative (0.02571403464849379 -0.041487546808452326), ;;=> :size 225} ;;=> {:key 3, ;;=> :representative (4.958779088412497 4.935661039001764), ;;=> :size 269} ;;=> {:key 2, ;;=> :representative (0.005632263753536093 5.024473916660704), ;;=> :size 265} ;;=> {:key 1, ;;=> :representative (5.132011425016014 -0.04658062914962453), ;;=> :size 241}) ``` -------------------------------- ### API & Examples: Macro Normalization (`mnorm`) Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.core.html API documentation and examples for the `mnorm` macro, a macro version of the `norm` function. It normalizes a value `v` from a `[start, stop]` range to `[0,1]` or maps it to a `[start2, stop2]` range. ```APIDOC (mnorm v start stop) (mnorm v start1 stop1 start2 stop2) ``` ```Clojure (mnorm 0.234 -1.0 1.0) ;;=> 0.617 ``` ```Clojure (mnorm 0.234 1.0 -1.0) ;;=> 0.383 ``` ```Clojure (mnorm (cos HALF_PI) -1.0 1.0 0.0 255.0) ;;=> 127.5 ``` ```Clojure (mnorm (cos HALF_PI) -1.0 1.0 255.0 0.0) ;;=> 127.5 ``` -------------------------------- ### Clojure Example: Using fastmath.kernel/approx for Kernel Value Rounding Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.kernel.html Demonstrates how to use the `approx` function from `fastmath.kernel` to round the output of a kernel function. Examples show usage with and without specifying precision. ```Clojure (let [ak (approx (kernel :gaussian))] (ak [1 2] [3 4])) ;;=> 0.02 (let [ak (approx (kernel :gaussian) 6)] (ak [1 2] [3 4])) ;;=> 0.018316 ``` -------------------------------- ### Initialize FastMath Statistical Distributions Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.random.html Demonstrates how to initialize various statistical distributions using the `distribution` function in FastMath. It shows examples for creating a default Beta distribution and one with specified alpha and beta parameters. ```Clojure (distribution :beta) ;;=> org.apache.commons.math3.distribution.BetaDistribution@2c257485 (distribution :beta {:alpha 1.0, :beta 1.0}) ;;=> org.apache.commons.math3.distribution.BetaDistribution@8891aa8 ``` -------------------------------- ### API & Examples: Get Next Double Value (`next-double`) Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.core.html API documentation and examples for the `next-double` function, which returns the next representable floating-point number after a given value. An optional `delta` parameter allows setting the step amount. ```APIDOC (next-double v) (next-double v delta) ``` ```Clojure (next-double 1234.56789) ;;=> 1234.5678900000003 ``` ```Clojure (next-double 1234.56789 1000) ;;=> 1234.5678900002274 ``` -------------------------------- ### API & Examples: Macro Linear Interpolation (`mlerp`) Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.core.html API documentation and examples for the `mlerp` macro, an inline version of linear interpolation (`lerp`). It calculates a value between `start` and `stop` based on a `t` factor, and also demonstrates interpolation outside the given range. ```APIDOC (mlerp start stop t) ``` ```Clojure (mlerp 0.0 1.0 0.123) ;;=> 0.123 (mlerp 0.0 100.0 0.123) ;;=> 12.3 (mlerp 100 200 0.5) ;;=> 150.0 ``` ```Clojure (mlerp -1.0 1.0 1.5) ;;=> 2.0 ``` -------------------------------- ### Clojure: Hyperbolic Arcsine Vector Elements Example Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.vector.html Example demonstrating the `asinh` function, applying the hyperbolic arcsine to each element of a `vec4` and showing the resulting vector with calculated values. ```Clojure (asinh (fastmath.vector/vec4 0.5 -1.5 2.1 0.0)) ;;=> [0.48121182505960347 -1.1947632172871094 1.4874828366412711 0.0] ``` -------------------------------- ### X-Means Clustering Example with Gaussian Distribution in Clojure Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.clustering.html This Clojure example demonstrates the `x-means` function, expecting two clusters from a dataset of 10,000 samples generated with a Gaussian distribution. It uses `juxt` to extract and display the resulting cluster count, sizes, and representatives. ```Clojure ((juxt :clusters :sizes :representatives) (x-means (repeatedly 10000 (fn* [] (r/randval (r/grand) (r/grand 5 1.0)))) 4)) ;;=> [2 (4969 5031 0) ((4.998015855439847) (-0.0011218297060218083))] ``` -------------------------------- ### Regrouping K-Means Clustering Results Example (Clojure) Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.clustering.html Illustrates how to use the `regroup` function with a `k-means` clustering result to obtain a structured list of individual clusters. The example shows the raw `k-means` output, the transformed regrouped output, and a count of the resulting clusters. ```Clojure (k-means [1 2 3 -1 -1 2 -1 11 111] 7) ;;=> #fastmath.clustering.ClusteringResult ;;=> {:clustering (2 5 4 3 3 5 3 0 1), ;;=> :clusters 7, ;;=> :data [1 2 3 -1 -1 2 -1 11 111], ;;=> :info {:distortion 0.0}, ;;=> :obj ;;=> #object[smile.clustering.KMeans 0xada293 "Cluster distortion: 0.00000\nCluster size of 9 data points:\nCluster 1 1 (11.1%)\nCluster 2 1 (11.1%)\nCluster 3 1 (11.1%)\nCluster 4 3 (33.3%)\nCluster 5 1 (11.1%)\nCluster 6 2 (22.2%)\nCluster 7 0 ( 0.0%)\n"], ;;=> :predict #, ;;=> :representatives ((11.0) (111.0) (1.0) (-1.0) (3.0) (2.0) (##NaN)), ;;=> :sizes (1 1 1 3 1 2 0 0), ;;=> :type :k-means} (regroup (k-means [1 2 3 -1 -1 2 -1 11 111] 7)) ;;=> ({:data (1), :key 0, :representative (1.0), :size 1} ;;=> {:data (2 2), :key 5, :representative (2.0), :size 2} ;;=> {:data (3), :key 4, :representative (3.0), :size 1} ;;=> {:data (-1 -1 -1), :key 3, :representative (-1.0), :size 3} ;;=> {:data (11), :key 2, :representative (11.0), :size 1} ;;=> {:data (111), :key 1, :representative (111.0), :size 1}) (count (regroup (k-means [1 2 3 -1 -1 2 -1 11 111] 7))) ;;=> 6 ``` -------------------------------- ### Create Basic Effects in Clojure Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.signal.html Shows how to create an effect using the `effect` multimethod, both with and without initial parameters. This initializes an effect instance ready for use. ```Clojure (effect :fm) ;;=> fm (0.0) (effect :fm {:quant 5}) ;;=> fm (0.0) ``` -------------------------------- ### Get Distribution Dimensionality with `dimensions` in Clojure Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.random.html Illustrates the `dimensions` function for retrieving the dimensionality of a distribution. Examples show how it applies to both single-dimensional (gamma) and multi-dimensional (dirichlet) distributions. ```Clojure (dimensions (distribution :gamma)) ;;=> 1 (dimensions (distribution :dirichlet {:alpha (repeat 30 2.0)})) ;;=> 30 ``` -------------------------------- ### Get Maximum Vector Element with mx Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.vector.html The `mx` function returns the maximum value among all elements in a vector. This example demonstrates its use with a `vec4`. ```Clojure (mx (vec4 -1 -2 3 4)) ;;=> 4.0 ``` -------------------------------- ### Fastmath Optimization API Reference Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.optimization.html Detailed API documentation for the `fastmath.optimization` namespace, including available functions, their parameters, and common configuration options for various optimization algorithms. ```APIDOC Namespace: fastmath.optimization Description: Optimization. Provides various optimization methods. Methods Supported: - Brent (1d functions) - Bobyqa (2d+ functions) - Powell - Nelder-Mead - Multidirectional simplex - CMAES - Gradient - Bayesian Optimization Note: All optimizers require bounds. Functions: minimize(method: keyword, func: function, params: map) -> result Description: Performs actual optimization to find the minimum of a function. Parameters: method: One of the optimization methods (e.g., :brent, :bobyqa, :nelder-mead, :multidirectional-simplex, :cmaes, :gradient). func: The function to optimize. params: A map of parameters. See "Common Parameters" below. maximize(method: keyword, func: function, params: map) -> result Description: Performs actual optimization to find the maximum of a function. Parameters: method: One of the optimization methods (e.g., :brent, :bobyqa, :nelder-mead, :multidirectional-simplex, :cmaes, :gradient). func: The function to optimize. params: A map of parameters. See "Common Parameters" below. scan-and-minimize(method: keyword, func: function, params: map) -> result Description: Finds an initial point using brute force and then performs parallel optimization for best initialization points to minimize a function. Brute force scan uses jitter low discrepancy sequence generator. Parameters: method: One of the optimization methods. func: The function to optimize. params: A map of parameters. See "Common Parameters" and "Scan-and- Functions Parameters" below. scan-and-maximize(method: keyword, func: function, params: map) -> result Description: Finds an initial point using brute force and then performs parallel optimization for best initialization points to maximize a function. Brute force scan uses jitter low discrepancy sequence generator. Parameters: method: One of the optimization methods. func: The function to optimize. params: A map of parameters. See "Common Parameters" and "Scan-and- Functions Parameters" below. minimizer(method: keyword, params: map) -> function (initial_point: vector) -> result Description: Creates an optimizer function that performs minimization. The returned function accepts an initial point. Parameters: method: One of the optimization methods. params: A map of parameters. See "Common Parameters" below. maximizer(method: keyword, params: map) -> function (initial_point: vector) -> result Description: Creates an optimizer function that performs maximization. The returned function accepts an initial point. Parameters: method: One of the optimization methods. params: A map of parameters. See "Common Parameters" below. Common Parameters (for minimize, maximize, scan-and-minimize, scan-and-maximize, minimizer, maximizer): :bounds (obligatory): sequence of [low high] pairs - Search ranges for each dimension. :initial: vector - Initial point other than the mid of the bounds. :max-evals: number - Maximum number of function evaluations. :max-iters: number - Maximum number of algorithm iterations. :bounded?: boolean - Should optimizer force to keep search within bounds (some algorithms go outside desired ranges). :stats?: boolean - Return number of iterations and evaluations along with result. :rel: number - Relative accepted error. :abs: number - Absolute accepted error. Scan-and- Functions Parameters (additional for scan-and-minimize, scan-and-maximize): :N: number - Number of brute force iterations. :n: number - Fraction of N which are used as initial points to parallel optimization. :jitter: number - Jitter factor for sequence generator (for scanning domain). ``` -------------------------------- ### Get Minimum Vector Element with mn Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.vector.html The `mn` function returns the minimum value among all elements in a vector. This example demonstrates its use with a `vec4`. ```Clojure (mn (vec4 -1 -2 3 4)) ;;=> -2.0 ``` -------------------------------- ### Get Covariance Matrix with `covariance` (Clojure) Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.random.html Examples illustrating the use of `covariance` to retrieve the covariance matrix for multivariate distributions like `:multi-normal` and `:dirichlet`. This is useful for understanding the relationships between variables in a distribution. ```Clojure (covariance (distribution :multi-normal)) ;;=> ((1.0 0.0) (0.0 1.0)) (covariance (distribution :dirichlet {:alpha [2 2]})) ;;=> [[0.05 -0.05] [-0.05 0.05]] ``` -------------------------------- ### Clojure: Calculate Probability Density Function (PDF) Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.random.html Illustrates how to use the `pdf` function to get the probability density for a given value from a specified continuous or discrete distribution. It shows examples for both gamma and pascal distributions. ```Clojure (pdf (distribution :gamma) 1) ;;=> 0.15163266492815838 (pdf (distribution :pascal) 1) ;;=> 0.078125 ``` -------------------------------- ### FastMath Function: smooth-interpolation Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.core.html Performs smoothstep-based interpolation between a start and stop value at a given time `t`. This function provides a smooth transition, and the example demonstrates its usage with specific float values. ```Clojure (smooth-interpolation 0.0 1.0 0.123) ;;=> 0.041665266 ``` -------------------------------- ### Install Fastmath Dependency Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/index.html Add the Fastmath library as a dependency to your Clojure project's build file (e.g., project.clj or deps.edn) to include it in your project. ```Clojure [generateme/fastmath "1.5.3-SNAPSHOT"] ``` -------------------------------- ### Get Distribution Dimensionality with `dimensions` (Clojure) Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.random.html Examples showing how to use the `dimensions` function to retrieve the dimensionality of various distributions. It demonstrates that a `:gamma` distribution has 1 dimension, while a `:dirichlet` distribution can have multiple dimensions based on its parameters. ```Clojure (dimensions (distribution :gamma)) ;;=> 1 (dimensions (distribution :dirichlet {:alpha (repeat 30 2.0)})) ;;=> 30 ``` -------------------------------- ### Get Vector Angle from Field with heading Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.fields.html The `heading` function determines the angle of vectors derived from a given field. It takes a field `f` as input. The example shows how to use it with a sinusoidal field and convert the resulting angle to degrees. ```APIDOC heading f ``` ```Clojure (let [f (heading (field :sinusoidal))] (m/degrees (f (v/vec2 m/HALF_PI m/HALF_PI)))) ;;=> 45.0 ``` -------------------------------- ### CubicOut Easing Function Usage Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.easings.html Illustrates how to use the `cubic-out` easing function, showing an example of its application and the resulting approximated value. This function provides a cubic easing effect that starts fast and decelerates towards the end. ```Clojure (m/approx (cubic-out 0.2) 6) ;;=> 0.488 ;; Test: ok. ``` -------------------------------- ### G-Means Clustering Example in Clojure Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.clustering.html Demonstrates the use of the `g-means` function for clustering, expecting 2 clusters from a uniform distribution. The example uses `juxt` to extract the number of clusters found, their sizes, and representatives from the clustering result. ```Clojure ((juxt :clusters :sizes :representatives) (g-means (repeatedly 100 (fn* [] (r/randval (r/drand) (r/drand 5 6)))) 4)) ;;=> [2 (48 52 0) ((5.529580900980793) (0.46507987463900274))] ``` -------------------------------- ### Generate Random Booleans with `brand` in Clojure Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.random.html Illustrates the `brand` function for generating random boolean values. It shows how to get a simple true/false and how to specify a probability for `true`. An example of counting `true` values over many trials is also provided. ```Clojure (brand) ;;=> true (brand 0.1) ;;=> false ``` ```Clojure (count (filter true? (repeatedly 100000 (fn* [] (brand 0.15))))) ;;=> 15085 ``` -------------------------------- ### Get Vector Magnitude from Field with magnitude Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.fields.html The `magnitude` function calculates the magnitude (length) of vectors generated by a field. It takes a field `f` as input. The example illustrates its use with a sinusoidal field, returning the vector's length at a specific point. ```APIDOC magnitude f ``` ```Clojure (let [f (magnitude (field :sinusoidal))] (f (v/vec2 m/HALF_PI m/HALF_PI))) ;;=> 1.4142135623730951 ``` -------------------------------- ### Create and Use a Minimizer Function (Clojure) Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.optimization.html Demonstrates how to create a minimizer function using the `:brent` method and then apply it to a 1D function with different initial points to find the minimum. ```Clojure (let [bounds [[-5.0 5.0]] f (fn [x] (+ (* 0.2 (m/sin (* 10.0 x))) (/ (+ 6.0 (- (* x x) (* 5.0 x))) (inc (* x x))))) optimizer (minimizer :brent f {:bounds bounds})] {:optimizer optimizer, :run-1 (optimizer), :run-2 (optimizer [4.5]), :run-3 (optimizer [-4.5])}) ;;=> {:optimizer #, ;;=> :run-1 [(-3.947569586073323) 2.2959519482739297], ;;=> :run-2 [(2.357114991599655) -0.2350104692683484], ;;=> :run-3 [(-4.570514545168775) 2.074718566761628]} ``` -------------------------------- ### Generate Ridged Multi Noise Values in Clojure Source: https://github.com/generateme/fastmath/blob/master/docs/clay/random.html These examples illustrate how to get noise values from the `ridgedmulti-noise` function for one, two, and three dimensions. The output displays the numerical results of the Ridged Multi noise at the specified coordinates. ```Clojure (ridgedmulti-noise 0.2) ;; => 0.33387061650044203 (ridgedmulti-noise 0.2 0.3) ;; => 0.6479155481384621 (ridgedmulti-noise 0.2 0.3 0.4) ;; => 0.786227445531883 ``` -------------------------------- ### Lloyd Clustering with 2D Vectors in Clojure Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.clustering.html This Clojure example illustrates the application of the Lloyd clustering algorithm to 500 randomly generated 2D vectors. Similar to the spectral example, it uses `dissoc` to simplify the output, displaying cluster details, representatives, and sizes. ```Clojure (dissoc (lloyd (repeatedly 500 (fn* [] (vector (r/randval 0.1 (r/irand -10 10) (r/irand 100 150)) (r/randval (r/irand -10 10) (r/irand 100 150))))) 4 1) :data :clustering :obj :predict) ;;=> {:clusters 4, ;;=> :info {:distortion 316885.16459203116}, ;;=> :representatives ((114.44117647058823 122.84558823529412) ;;=> (125.50230414746544 -0.29493087557603687) ;;=> (-0.6888888888888889 76.68888888888888) ;;=> (137.15686274509804 127.91176470588235)), ;;=> :sizes (136 217 45 102 0), ;;=> :type :lloyd} ``` -------------------------------- ### Instantiate Statistical Distributions in FastMath Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.random.html Demonstrates how to create instances of statistical distributions using the `distribution` function in FastMath, showing both default instantiation and instantiation with specific parameters. ```Clojure (distribution :beta) ;;=> org.apache.commons.math3.distribution.BetaDistribution@5e2a0361 (distribution :beta {:alpha 1.0, :beta 1.0}) ;;=> org.apache.commons.math3.distribution.BetaDistribution@10fa8f92 ``` -------------------------------- ### Get Cell Vertices for 2D Coordinates in Clojure Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.grid.html Illustrates the `corners` function, which returns a list of cell vertices for given 2D space coordinates. Examples show usage with flat-hex and triangle grid types, demonstrating the output structure of vertices. ```Clojure (corners (grid :flat-hex 20) [100 100]) ;;=> ([115.0 95.26279441628824] ;;=> [110.0 103.92304845413263] ;;=> [100.0 103.92304845413264] ;;=> [95.0 95.26279441628824] ;;=> [100.0 86.60254037844386] ;;=> [110.0 86.60254037844386]) (corners (grid :triangle 10 10 10) [100 100]) ;;=> [[95.0 100.0] [105.0 100.0] [100.0 110.0]] ``` -------------------------------- ### Integrate PDF to get CDF/iCDF for Normal-Inverse Gaussian Source: https://github.com/generateme/fastmath/blob/master/docs/clay/random.html Demonstrates how to use `r/integrate-pdf` to obtain CDF (Cumulative Distribution Function) and iCDF (Inverse Cumulative Distribution Function) pairs from the PDF of a Normal-Inverse Gaussian distribution. It specifies integration bounds and steps, and shows an example output. ```Clojure (let [[cdf icdf] (r/integrate-pdf (partial r/pdf (r/distribution :normal-inverse-gaussian)) {:mn -800.0 :mx 800.0 :steps 5000 :interpolator :monotone})] [(cdf 0.0) (icdf 0.5)]) ``` ```Result [0.5000000000001334 -2.5040386431030015E-13] ``` -------------------------------- ### quot macro Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.core.html Wraps the `fastmath.java.PrimitiveMath/quotient` function. Provides examples comparing its behavior with `clojure.core/quot` for various positive and negative inputs. ```APIDOC (quot x y) ``` ```Clojure (quot 3.123 0.333) ;;=> 9.0 (quot -3.123 0.333) ;;=> -9.0 (quot -3.123 -0.333) ;;=> 9.0 (quot 3.123 -0.333) ;;=> -9.0 (clojure.core/quot 3.123 0.333) ;;=> 9.0 (clojure.core/quot -3.123 0.333) ;;=> -9.0 (clojure.core/quot -3.123 -0.333) ;;=> 9.0 (clojure.core/quot 3.123 -0.333) ;;=> -9.0 ``` -------------------------------- ### Neural Gas Basic Clustering Example Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.clustering.html Demonstrates the basic application of the Neural Gas algorithm to a sample dataset, clustering it into a specified number of clusters. The output shows the detailed ClusteringResult map, including clustering assignments, cluster sizes, and representatives. ```Clojure (neural-gas [1 2 3 -1 -1 2 -1 11 111] 4) ;;=> #fastmath.clustering.ClusteringResult ;;=> {:clustering (0 0 0 0 0 0 0 3 1), ;;=> :clusters 4, ;;=> :data [1 2 3 -1 -1 2 -1 11 111], ;;=> :info {:distortion 100.21135606663056}, ;;=> :obj ;;=> #object[smile.vq.NeuralGas 0xd814247 "Neural Gas distortion: 100.21136\nClusters of 9 data points of dimension 1:\n 0\t 7 (77.8%)\n 1\t 1 (11.1%)\n 2\t 0 ( 0.0%)\n 3\t 1 (11.1%)\n"], ;;=> :predict #, ;;=> :representatives ((0.6767057694246992) ;;=> (102.02680736489556) ;;=> (38.047386026088205) ;;=> (9.498429886559977)), ;;=> :sizes (7 1 0 1), ;;=> :type :neural-gas} ``` -------------------------------- ### Usage Example: Polynomial Interpolation (Clojure) Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.interpolation.html Demonstrates how to use the `polynomial` interpolator with the `interpolate` function. ```Clojure (interpolate polynomial ...) ;;=> 0.6789478287861641 ``` -------------------------------- ### Fastmath Signal Processing: Effects and Composition Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.signal.html Explains the core concepts of signal processing within `fastmath.signal`, focusing on how to apply and compose effects. It describes `apply-effects`, `apply-effects-raw`, `effect` creation, and the `effects-list`. ```APIDOC Signal processing --------------------------------------- To process signal use apply-effects or apply-effects-raw (operates on `double-array` only) function. Effect is signal filter, created by effect multimethod. Effects can be composed with compose-effects. Effect can be treated as function and can be called for given sample. Each effect has it’s own parametrization which should be passed during creation. List of all available effects is under effects-list value. ``` -------------------------------- ### lower-bound Usage Example in FastMath Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.random.html Example demonstrating how to retrieve the lower bound of a gamma distribution. ```Clojure (lower-bound (distribution :gamma)) ;;=> 0.0 ``` -------------------------------- ### likelihood Usage Example in FastMath Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.random.html Example demonstrating how to calculate the likelihood of samples for a gamma distribution. ```Clojure (likelihood (distribution :gamma) [10 0.5 0.5 1 2]) ;;=> 4.452548659934162E-6 ``` -------------------------------- ### Define and Sample Continuous Distribution (KDE) in FastMath Source: https://github.com/generateme/fastmath/blob/master/docs/clay/random.html Demonstrates how to create a continuous distribution using Kernel Density Estimation (KDE) from randomly generated data. It shows the process of defining the data source and constructing the distribution object, noting that ':continuous-distribution' and ':kde' are interchangeable names. ```Clojure (def random-data (repeatedly 1000 (fn [] (+ (* (r/drand -2 2) (r/drand -2 2)) (m/sqrt (* (r/drand) (r/drand))))))) (def kde-distr (r/distribution :continuous-distribution {:data random-data})) ``` -------------------------------- ### Create Grid Objects in Clojure Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.grid.html Shows how to create different grid types using the `grid` function, with various parameters for type, size, and optional translation. It also includes examples of inspecting the created grid objects. ```Clojure (grid :pointy-hex 20) ;;=> pointy-hex, size=10.0 (grid :triangular 10 5.0 5.0) ;;=> triangular, size=10.0 (name (grid :square)) ;;=> square (str (grid :rhombus)) ;;=> rhombus, size=10.0 (grid) ;;=> square, size=10.0 ``` -------------------------------- ### lpdf Usage Example in FastMath Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.random.html Example demonstrating how to calculate the log density for a value in a gamma distribution. ```Clojure (lpdf (distribution :gamma) 1) ;;=> -1.8862943611198908 ``` -------------------------------- ### Create and Configure Vector Fields in fastmath.fields Source: https://github.com/generateme/fastmath/blob/master/docs/fastmath.fields.html Instructions on how to create vector fields using the `field` multimethod and how to manage their configurations with the `parametrization` function. It also explains the optional `amount` parameter for scaling vector fields. ```APIDOC Function: field Description: Multimethod to create a vector field. Parameters: - name (keyword): The name of the field. Function: parametrization Description: Creates a random configuration for vector fields or merges with a provided map of parameters. Parameters: - config (map, optional): A map of parameters (keywords and values) to merge. Common Parameter: amount Description: Scaling factor for the vector field. Type: double Default: 1.0 ``` -------------------------------- ### log-likelihood Usage Example in FastMath Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/fastmath.random.html Example demonstrating how to calculate the log likelihood of samples for a gamma distribution. ```Clojure (log-likelihood (distribution :gamma) [10 0.5 0.5 1 2]) ;;=> -12.322033893165353 ``` -------------------------------- ### FastMath Core: Powers and Logarithms Source: https://github.com/generateme/fastmath/blob/master/docs/1.5/index.html Provides a comprehensive set of functions for exponentiation, roots, and various logarithmic calculations, including optimized versions. ```APIDOC cb cbrt exp expm1 fpow high-2-exp high-exp ln log log10 log1p log1pexp log2 logb logit low-2-exp low-exp pow pow2 pow3 qexp qlog qpow qsqrt rqsqrt safe-sqrt sigmoid sq sqrt ```