/// <summary> /// Computes the sum of the absolute value of the vector's elements. /// </summary> /// <returns>The sum of the absolute value of the vector's elements.</returns> public override Complex SumMagnitudes() { return(CommonParallel.Aggregate( 0, Count, i => Data[i].Magnitude)); }
/// <summary> /// Computes the p-Norm. /// </summary> /// <param name="p">The p value.</param> /// <returns>Scalar <c>ret = (sum(abs(this[i])^p))^(1/p)</c></returns> public override Complex Norm(double p) { if (p < 0.0) { throw new ArgumentOutOfRangeException("p"); } if (1.0 == p) { return(SumMagnitudes()); } if (2.0 == p) { return(Data.Aggregate(Complex.Zero, SpecialFunctions.Hypotenuse).Magnitude); } if (Double.IsPositiveInfinity(p)) { return(CommonParallel.Aggregate(Data, (i, v) => v.Magnitude, Math.Max, 0d)); } var sum = 0.0; for (var i = 0; i < Count; i++) { sum += Math.Pow(Data[i].Magnitude, p); } return(Math.Pow(sum, 1.0 / p)); }
/// <summary> /// Computes the p-Norm. /// </summary> /// <param name="p">The p value.</param> /// <returns>Scalar <c>ret = (sum(abs(this[i])^p))^(1/p)</c></returns> public override Complex32 Norm(double p) { if (p < 0.0) { throw new ArgumentOutOfRangeException("p"); } if (1.0 == p) { return(SumMagnitudes()); } if (2.0 == p) { return(_values.Aggregate(Complex32.Zero, SpecialFunctions.Hypotenuse).Magnitude); } if (Double.IsPositiveInfinity(p)) { return(CommonParallel.Aggregate(_values, (i, v) => v.Magnitude, Math.Max, 0f)); } var sum = 0.0; for (var i = 0; i < _length; i++) { sum += Math.Pow(_values[i].Magnitude, p); } return((float)Math.Pow(sum, 1.0 / p)); }
/// <summary> /// Computes the sum of the vector's elements. /// </summary> /// <returns>The sum of the vector's elements.</returns> public override Complex Sum() { return(CommonParallel.Aggregate( 0, Count, i => Data[i])); }
/// <summary> /// Computes the dot product between this vector and another vector. /// </summary> /// <param name="other"> /// The other vector to add. /// </param> /// <returns>s /// The result of the addition. /// </returns> protected override Complex32 DoDotProduct(Vector <Complex32> other) { return(CommonParallel.Aggregate( 0, Count, i => this[i] * other[i])); }
/// <summary> /// Computes the trace of this matrix. /// </summary> /// <returns>The trace of this matrix</returns> /// <exception cref="ArgumentException">If the matrix is not square</exception> public override double Trace() { if (RowCount != ColumnCount) { throw new ArgumentException(Resources.ArgumentMatrixSquare); } return(CommonParallel.Aggregate(0, RowCount, i => Data[(i * RowCount) + i])); }
/// <summary> /// Computes the trace of this matrix. /// </summary> /// <returns>The trace of this matrix</returns> /// <exception cref="ArgumentException">If the matrix is not square</exception> public override Complex32 Trace() { if (RowCount != ColumnCount) { throw new ArgumentException(Resources.ArgumentMatrixSquare); } return(CommonParallel.Aggregate(0, RowCount, i => At(i, i))); }
public double EstimateDensity(double x) { var n = Samples.Count; var estimate = CommonParallel.Aggregate(0, n, i => { var s = Samples[i]; return(Kernel((x - s) / Bandwidth)); }, (a, b) => a + b, 0d) / (n * Bandwidth); return(estimate); }
/// <summary> /// Computes the p-Norm. /// </summary> /// <param name="p"> /// The p value. /// </param> /// <returns> /// <c>Scalar ret = (sum(abs(this[i])^p))^(1/p)</c> /// </returns> public override double Norm(double p) { if (p < 0.0) { throw new ArgumentOutOfRangeException("p"); } if (Double.IsPositiveInfinity(p)) { return(CommonParallel.Aggregate(0, Count, i => Math.Abs(At(i)), Math.Max, 0d)); } var sum = 0.0; for (var index = 0; index < Count; index++) { sum += Math.Pow(Math.Abs(At(index)), p); } return(Math.Pow(sum, 1.0 / p)); }
/// <summary> /// Computes the p-Norm. /// </summary> /// <param name="p"> /// The p value. /// </param> /// <returns> /// <c>Scalar ret = (sum(abs(this[i])^p))^(1/p)</c> /// </returns> public override Complex Norm(double p) { if (p < 0.0) { throw new ArgumentOutOfRangeException("p"); } if (double.IsPositiveInfinity(p)) { return(CommonParallel.Select( 0, Count, (index, localData) => Math.Max(localData, this[index].Magnitude), Math.Max)); } var sum = CommonParallel.Aggregate( 0, Count, index => Math.Pow(this[index].Magnitude, p)); return(Math.Pow(sum, 1.0 / p)); }
/// <summary> /// Computes the p-Norm. /// </summary> /// <param name="p">The p value.</param> /// <returns>Scalar <c>ret = (sum(abs(this[i])^p))^(1/p)</c></returns> public override Complex Norm(double p) { if (p < 0.0) { throw new ArgumentOutOfRangeException("p"); } if (1.0 == p) { return(CommonParallel.Aggregate( 0, Count, index => Data[index].Magnitude)); } if (2.0 == p) { return(Data.Aggregate(Complex.Zero, SpecialFunctions.Hypotenuse).Magnitude); } if (Double.IsPositiveInfinity(p)) { return(CommonParallel.Select( 0, Count, (index, localData) => Math.Max(localData, Data[index].Magnitude), Math.Max)); } var sum = CommonParallel.Aggregate( 0, Count, index => Math.Pow(Data[index].Magnitude, p)); return(Math.Pow(sum, 1.0 / p)); }
/// <summary> /// Factorize matrix using the modified Gram-Schmidt method. /// </summary> /// <param name="q">Initial matrix. On exit is replaced by <see cref="Matrix{T}"/> Q.</param> /// <param name="rowsQ">Number of rows in <see cref="Matrix{T}"/> Q.</param> /// <param name="columnsQ">Number of columns in <see cref="Matrix{T}"/> Q.</param> /// <param name="r">On exit is filled by <see cref="Matrix{T}"/> R.</param> private static void Factorize(Complex32[] q, int rowsQ, int columnsQ, Complex32[] r) { for (var k = 0; k < columnsQ; k++) { var norm = 0.0f; for (var i = 0; i < rowsQ; i++) { norm += q[(k * rowsQ) + i].Magnitude * q[(k * rowsQ) + i].Magnitude; } norm = (float)Math.Sqrt(norm); if (norm == 0.0f) { throw new ArgumentException(Resources.ArgumentMatrixNotRankDeficient); } r[(k * columnsQ) + k] = norm; for (var i = 0; i < rowsQ; i++) { q[(k * rowsQ) + i] /= norm; } for (var j = k + 1; j < columnsQ; j++) { int k1 = k; int j1 = j; var dot = CommonParallel.Aggregate(0, rowsQ, index => q[(k1 * rowsQ) + index].Conjugate() * q[(j1 * rowsQ) + index]); r[(j * columnsQ) + k] = dot; for (var i = 0; i < rowsQ; i++) { var value = q[(j * rowsQ) + i] - (q[(k * rowsQ) + i] * dot); q[(j * rowsQ) + i] = value; } } } }
/// <summary> /// Calculates the infinity norm of the vector. /// </summary> /// <returns>The maximum absolute value.</returns> public override double InfinityNorm() { return(CommonParallel.Aggregate(0, Count, i => At(i).Magnitude, System.Math.Max, 0f)); }