Example #1
0
 /// <summary>
 /// Performs image denoising using the Block-Matching and 3D-filtering algorithm with several computational optimizations. Noise expected to be a gaussian white noise.
 /// </summary>
 /// <param name="src">Input 8-bit or 16-bit 1-channel image.</param>
 /// <param name="dstStep1">Output image of the first step of BM3D with the same size and type as src.</param>
 /// <param name="dstStep2">Output image of the second step of BM3D with the same size and type as src.</param>
 /// <param name="h">Parameter regulating filter strength. Big h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise.</param>
 /// <param name="templateWindowSize">Size in pixels of the template patch that is used for block-matching. Should be power of 2.</param>
 /// <param name="searchWindowSize">Size in pixels of the window that is used to perform block-matching. Affect performance linearly: greater searchWindowsSize - greater denoising time. Must be larger than templateWindowSize.</param>
 /// <param name="blockMatchingStep1">Block matching threshold for the first step of BM3D (hard thresholding), i.e. maximum distance for which two blocks are considered similar. Value expressed in euclidean distance.</param>
 /// <param name="blockMatchingStep2">Block matching threshold for the second step of BM3D (Wiener filtering), i.e. maximum distance for which two blocks are considered similar. Value expressed in euclidean distance.</param>
 /// <param name="groupSize">Maximum size of the 3D group for collaborative filtering.</param>
 /// <param name="slidingStep">Sliding step to process every next reference block.</param>
 /// <param name="beta">Kaiser window parameter that affects the sidelobe attenuation of the transform of the window. Kaiser window is used in order to reduce border effects. To prevent usage of the window, set beta to zero.</param>
 /// <param name="normType">Norm used to calculate distance between blocks. L2 is slower than L1 but yields more accurate results.</param>
 /// <param name="step">Step of BM3D to be executed. Possible variants are: step 1, step 2, both steps.</param>
 /// <param name="transformType">	Type of the orthogonal transform used in collaborative filtering step. Currently only Haar transform is supported.</param>
 /// <remarks> <c href="http://www.cs.tut.fi/~foi/GCF-BM3D/BM3D_TIP_2007.pdf"/>   </remarks>
 public static void Bm3dDenoising(
     IInputArray src,
     IInputOutputArray dstStep1,
     IOutputArray dstStep2,
     float h = 1,
     int templateWindowSize       = 4,
     int searchWindowSize         = 16,
     int blockMatchingStep1       = 2500,
     int blockMatchingStep2       = 400,
     int groupSize                = 8,
     int slidingStep              = 1,
     float beta                   = 2.0f,
     NormType normType            = NormType.L2,
     Bm3dSteps step               = Bm3dSteps.All,
     TransformTypes transformType = TransformTypes.Haar)
 {
     using (InputArray iaSrc = src.GetInputArray())
         using (InputOutputArray ioaDstStep1 = dstStep1.GetInputOutputArray())
             using (OutputArray oaStep2 = dstStep2.GetOutputArray())
             {
                 cveBm3dDenoising1(iaSrc, ioaDstStep1, oaStep2,
                                   h, templateWindowSize, searchWindowSize, blockMatchingStep1, blockMatchingStep2,
                                   groupSize, slidingStep, beta, normType, step, transformType);
             }
 }
Example #2
0
        private static Tensor normImpl(Tensor x, NormType p, int[] axis = null)
        {
            if (x.Rank == 0)
            {
                return(x.abs());
            }

            // consider vector when no axis is specified
            if (x.Rank != 1 && axis == null)
            {
                return(normImpl(x.reshape(new int[] { -1 }), p, axis));
            }

            // vector
            if (x.Rank == 1 || axis.Length == 1)
            {
                if (p == NormType.One)
                {
                    return(x.abs().sum(axis));
                }
                if (p == NormType.Inf)
                {
                    return(x.abs().max(axis));
                }
                if (p == NormType.NegativeInf)
                {
                    return(x.abs().min(axis));
                }
                if (p == NormType.euclidean || p == NormType.Two)
                {
                    // norm(x, 2) = sum(abs(xi) ^ 2) ^ 1/2
                    return(x.abs().pow(Ops.scalar(2)).sum(axis).sqrt());
                }
            }
            // matrix (assumption axis[0] < axis[1])
            if (axis.Length == 2)
            {
                if (p == NormType.One)
                {
                    return(x.abs().sum(new int[] { axis[0] }).max(new int[] { axis[1] - 1 }));
                }
                if (p == NormType.Inf)
                {
                    return(x.abs().sum(new int[] { axis[1] }).max(new int[] { axis[0] }));
                }
                if (p == NormType.NegativeInf)
                {
                    return(x.abs().sum(new int[] { axis[1] }).min(new int[] { axis[0] }));
                }
                if (p == NormType.fro || p == NormType.euclidean)
                {
                    // norm(x) = sqrt(sum(pow(x, 2)))
                    return(x.square().sum(axis).sqrt());
                }
            }
            throw new Exception("Error in norm: invalid axis");
        }
Example #3
0
 public GiniEngine(recordConfig rc, DB db, NormType mode = NormType.Gini)
 {
     _mode              = mode;
     _labels            = db.training_label;
     _training          = db.training_dt;
     _trainingGridIndex = db.PCAtraining_GridIndex_dt;
     _dataDim           = rc.dim;
     _minWaveSize       = rc.minWaveSize;
     _labelsDim         = _labels[0].Count();
 }
Example #4
0
        /// <summary>
        /// 配列の絶対値ノルム(absolute array norm),絶対値差分ノルム(absolute difference norm),相対値差分ノルム(relative difference norm)を計算する
        /// </summary>
        /// <param name="arr1">1番目の入力画像</param>
        /// <param name="arr2">2番目の入力画像.null の場合,arr1の絶対値ノルムが計算され,そうでない場合は,arr1-arr2 の絶対値あるいは相対値ノルムが計算される. </param>
        /// <param name="normType">ノルムのタイプ</param>
        /// <param name="mask">オプションの処理マスク</param>
        /// <returns></returns>
#else
        /// <summary>
        /// Calculates absolute array norm, absolute difference norm or relative difference norm
        /// </summary>
        /// <param name="arr1">The first source image. </param>
        /// <param name="arr2">The second source image. If it is null, the absolute norm of arr1 is calculated, otherwise absolute or relative norm of arr1-arr2 is calculated. </param>
        /// <param name="normType">Type of norm</param>
        /// <param name="mask">The optional operation mask. </param>
        /// <returns></returns>
#endif
        public static double Norm(CvArr arr1, CvArr arr2, NormType normType, CvArr mask)
        {
            if (arr1 == null)
            {
                throw new ArgumentNullException("arr1");
            }
            IntPtr arr2Ptr = (arr2 == null) ? IntPtr.Zero : arr2.CvPtr;
            IntPtr maskPtr = (mask == null) ? IntPtr.Zero : mask.CvPtr;

            return(NativeMethods.cvNorm(arr1.CvPtr, arr2Ptr, normType, maskPtr));
        }
Example #5
0
        /// <summary>
        /// 配列の絶対値ノルム(absolute array norm),絶対値差分ノルム(absolute difference norm),相対値差分ノルム(relative difference norm)を計算する
        /// </summary>
        /// <param name="arr1">1番目の入力画像</param>
        /// <param name="arr2">2番目の入力画像.null の場合,arr1の絶対値ノルムが計算され,そうでない場合は,arr1-arr2 の絶対値あるいは相対値ノルムが計算される. </param>
        /// <param name="normType">ノルムのタイプ</param>
        /// <param name="mask">オプションの処理マスク</param>
        /// <returns></returns>
#else
        /// <summary>
        /// Calculates absolute array norm, absolute difference norm or relative difference norm
        /// </summary>
        /// <param name="arr1">The first source image. </param>
        /// <param name="arr2">The second source image. If it is null, the absolute norm of arr1 is calculated, otherwise absolute or relative norm of arr1-arr2 is calculated. </param>
        /// <param name="normType">Type of norm</param>
        /// <param name="mask">The optional operation mask. </param>
        /// <returns></returns>
#endif
        public static double Norm(CvArr arr1, CvArr arr2, NormType normType, CvArr mask)
        {
            if (arr1 == null)
            {
                throw new ArgumentNullException("arr1");
            }

            var ret = NativeMethods.cvNorm(arr1.CvPtr, ToPtr(arr2), normType, ToPtr(mask));

            KeepAlive(arr1, arr2, mask);
            return(ret);
        }
Example #6
0
        /// <summary>
        /// Computes the norm of scalar, vectors, and matrices.
        ///This function can compute several different vector norms (the 1-norm, the
        ///Euclidean or 2-norm, the inf-norm, and in general the p-norm for p > 0)
        ///and matrix norms (Frobenius, 1-norm, and inf-norm).
        /// </summary>
        /// <param name="x">The input array.</param>
        /// <param name="ord">Optional. Order of the norm. Supported norm types are
        /// following:
        ///
        ///  | ord          | norm for matrices         | norm for vectors
        ///  |--------------|---------------------------|---------------------
        ///  |euclidean     |euclidean norm             |2-norm
        ///  |fro           |Frobenius norm	            |
        ///  |Inf           |max(sum(abs(x), axis=1))   |max(abs(x))
        ///  |NegativeInf   |min(sum(abs(x), axis=1))   |min(abs(x))
        ///  |One           |max(sum(abs(x), axis=0))   |sum(abs(x))
        ///  |Two           |                           |sum(abs(x)^2)^1/2*</param>
        /// <param name="axis">Optional. If axis is null (the default), the input is
        /// considered a vector and a single vector norm is computed over the entire
        /// set of values in the Tensor, i.e. norm(x, ord) is equivalent
        /// to norm(x.reshape([-1]), ord). If axis is a integer, the input
        /// is considered a batch of vectors, and axis determines the axis in x
        /// over which to compute vector norms. If axis is a 2-tuple of integer it is
        /// considered a batch of matrices and axis determines the axes in NDArray
        /// over which to compute a matrix norm.</param>
        /// <param name="keepDims"> Optional. If true, the norm have the same dimensionality
        /// as the input.</param>
        /// <returns></returns>
        public static Tensor norm(this Tensor x, NormType ord, int[] axis = null, bool keepDims = false)
        {
            var norm          = normImpl(x, ord, axis);
            var keepDimsShape = norm.Shape;

            if (keepDims)
            {
                var axes = Util.parseAxisParam(axis, x.Shape);
                keepDimsShape = Util.expandShapeToKeepDim(norm.Shape, axes);
            }
            return(norm.reshape(keepDimsShape));
        }
Example #7
0
        /// <summary>
        /// 指定のノルムになるように,あるいは値が指定の範囲になるように,配列を正規化する
        /// </summary>
        /// <param name="src">入力配列</param>
        /// <param name="dst">出力配列.インプレース処理が可能.</param>
        /// <param name="a">出力配列の最小値または最大値,あるいは出力配列のノルム.</param>
        /// <param name="b">出力配列の最大値または最小値.</param>
        /// <param name="normType">正規化のタイプ. C, L1, L2, MinMaxのうち1つ.</param>
        /// <param name="mask">操作マスク.特定の配列要素のみを正規化するためのマスク.</param>
#else
        /// <summary>
        /// Normalizes array to a certain norm or value range
        /// </summary>
        /// <param name="src">The input array. </param>
        /// <param name="dst">The output array; in-place operation is supported. </param>
        /// <param name="a">The minimum/maximum value of the output array or the norm of output array. </param>
        /// <param name="b">The maximum/minimum value of the output array. </param>
        /// <param name="normType">The normalization type.</param>
        /// <param name="mask">The operation mask. Makes the function consider and normalize only certain array elements. </param>
#endif
        public static void Normalize(CvArr src, CvArr dst, double a, double b, NormType normType, CvArr mask)
        {
            if (src == null)
            {
                throw new ArgumentNullException("src");
            }
            if (dst == null)
            {
                throw new ArgumentNullException("dst");
            }

            NativeMethods.cvNormalize(src.CvPtr, dst.CvPtr, a, b, normType, ToPtr(mask));
            KeepAlive(src, dst, mask);
        }
Example #8
0
 private static extern void cveBm3dDenoising2(
     IntPtr src,
     IntPtr dst,
     float h,
     int templateWindowSize,
     int searchWindowSize,
     int blockMatchingStep1,
     int blockMatchingStep2,
     int groupSize,
     int slidingStep,
     float beta,
     NormType normType,
     Bm3dSteps step,
     TransformTypes transformType);
Example #9
0
        /// <summary>
        /// 指定のノルムになるように,あるいは値が指定の範囲になるように,配列を正規化する
        /// </summary>
        /// <param name="src">入力配列</param>
        /// <param name="dst">出力配列.インプレース処理が可能.</param>
        /// <param name="a">出力配列の最小値または最大値,あるいは出力配列のノルム.</param>
        /// <param name="b">出力配列の最大値または最小値.</param>
        /// <param name="normType">正規化のタイプ. C, L1, L2, MinMaxのうち1つ.</param>
        /// <param name="mask">操作マスク.特定の配列要素のみを正規化するためのマスク.</param>
#else
        /// <summary>
        /// Normalizes array to a certain norm or value range
        /// </summary>
        /// <param name="src">The input array. </param>
        /// <param name="dst">The output array; in-place operation is supported. </param>
        /// <param name="a">The minimum/maximum value of the output array or the norm of output array. </param>
        /// <param name="b">The maximum/minimum value of the output array. </param>
        /// <param name="normType">The normalization type.</param>
        /// <param name="mask">The operation mask. Makes the function consider and normalize only certain array elements. </param>
#endif
        public static void Normalize(CvArr src, CvArr dst, double a, double b, NormType normType, CvArr mask)
        {
            if (src == null)
            {
                throw new ArgumentNullException("src");
            }
            if (dst == null)
            {
                throw new ArgumentNullException("dst");
            }
            IntPtr maskPtr = (mask == null) ? IntPtr.Zero : mask.CvPtr;

            NativeMethods.cvNormalize(src.CvPtr, dst.CvPtr, a, b, normType, maskPtr);
        }
Example #10
0
        public static double Norm(double[] r, NormType type)
        {
            switch (type)
            {
            case NormType.L1:
                return(norm1(r));

            case NormType.L2:
                return(norm2(r));

            case NormType.LINF:
                return(normINF(r));

            default:
                return(norm2(r));
            }
        }
Example #11
0
        public void Normalize(NormType type)
        {
            double factor = 1;

            if (type == NormType.GeometricMean)
            {
                foreach (double v in Coordinates)
                {
                    factor *= v;
                }
                factor = Math.Pow(factor, 1.0 / Coordinates.Count());
            }
            else if (type == NormType.ArithmeticMean)
            {
                double sum = Coordinates.Sum();
                sum   /= (double)Coordinates.Count();
                factor = sum;
            }
            else if (type == NormType.Max)
            {
                double max = 0;
                foreach (double v in Coordinates)
                {
                    if (v > max)
                    {
                        max = v;
                    }
                }
                factor = max;
            }
            else if (type == NormType.None)
            {
                return;
            }
            else if (type == NormType.MaxAttr)
            {
                return;
            }

            for (int i = 0; i < Coordinates.Count(); i++)
            {
                Coordinates[i] /= factor;
            }
        }
Example #12
0
 private static extern void cudaCalcNorm(IntPtr src, IntPtr dst, NormType normType, IntPtr mask, IntPtr stream);
Example #13
0
 public static void CalcNorm(IInputArray src, IOutputArray dst, NormType normType = NormType.L2, IInputArray mask = null,
    Stream stream = null)
 {
    using (InputArray iaSrc = src.GetInputArray())
    using (OutputArray oaDst = dst.GetOutputArray())
    using (InputArray iaMask = mask == null ? InputArray.GetEmpty() : mask.GetInputArray())
       cudaCalcNorm(iaSrc, oaDst, normType, iaMask, stream);
 }
Example #14
0
 public static extern void cvNormalize(IntPtr src, IntPtr dst, double a, double b, NormType norm_type, IntPtr mask);
Example #15
0
 /// <summary>
 /// scales and shifts array elements so that either the specified norm (alpha) 
 /// or the minimum (alpha) and maximum (beta) array values get the specified values
 /// </summary>
 /// <param name="src"></param>
 /// <param name="dst"></param>
 /// <param name="alpha"></param>
 /// <param name="beta"></param>
 /// <param name="normType"></param>
 /// <param name="dtype"></param>
 /// <param name="mask"></param>
 public static void Normalize( InputArray src, OutputArray dst, double alpha=1, double beta=0,
                      NormType normType=NormType.L2, int dtype=-1, InputArray mask=null)
 {
     if (src == null)
         throw new ArgumentNullException("src");
     if (dst == null)
         throw new ArgumentNullException("dst");
     src.ThrowIfDisposed();
     dst.ThrowIfNotReady();
     NativeMethods.core_normalize(src.CvPtr, dst.CvPtr, alpha, beta, (int)normType, dtype, ToPtr(mask));
     dst.Fix();
 }
Example #16
0
 /// <summary>
 /// naive nearest neighbor finder
 /// </summary>
 /// <param name="src1"></param>
 /// <param name="src2"></param>
 /// <param name="dist"></param>
 /// <param name="dtype"></param>
 /// <param name="nidx"></param>
 /// <param name="normType"></param>
 /// <param name="k"></param>
 /// <param name="mask"></param>
 /// <param name="update"></param>
 /// <param name="crosscheck"></param>
 public static void BatchDistance(InputArray src1, InputArray src2,
                                  OutputArray dist, int dtype, OutputArray nidx,
                                  NormType normType = NormType.L2,
                                  int k = 0, InputArray mask = null,
                                  int update = 0, bool crosscheck = false)
 {
     if (src1 == null)
         throw new ArgumentNullException("src1");
     if (src2 == null)
         throw new ArgumentNullException("src2");
     if (dist == null)
         throw new ArgumentNullException("dist");
     if (nidx == null)
         throw new ArgumentNullException("nidx");
     src1.ThrowIfDisposed();
     src2.ThrowIfDisposed();
     dist.ThrowIfNotReady();
     nidx.ThrowIfNotReady();
     NativeMethods.core_batchDistance(src1.CvPtr, src2.CvPtr, dist.CvPtr, dtype, nidx.CvPtr,
         (int)normType, k, ToPtr(mask), update, crosscheck ? 1 : 0);
     dist.Fix();
     nidx.Fix();
 }
Example #17
0
        /// <summary>
        /// 指定のノルムになるように,あるいは値が指定の範囲になるように,配列を正規化する
        /// </summary>
        /// <param name="src">入力配列</param>
        /// <param name="dst">出力配列.インプレース処理が可能.</param>
        /// <param name="a">出力配列の最小値または最大値,あるいは出力配列のノルム.</param>
        /// <param name="b">出力配列の最大値または最小値.</param>
        /// <param name="normType">正規化のタイプ. C, L1, L2, MinMaxのうち1つ.</param>
#else
        /// <summary>
        /// Normalizes array to a certain norm or value range
        /// </summary>
        /// <param name="src">The input array. </param>
        /// <param name="dst">The output array; in-place operation is supported. </param>
        /// <param name="a">The minimum/maximum value of the output array or the norm of output array. </param>
        /// <param name="b">The maximum/minimum value of the output array. </param>
        /// <param name="normType">The normalization type.</param>
#endif
        public static void Normalize(CvArr src, CvArr dst, double a, double b, NormType normType)
        {
            Normalize(src, dst, a, b, normType, null);
        }
Example #18
0
 public static void Normalize(IInputArray src, IOutputArray dst, double alpha, double beta, NormType normType,
    CvEnum.DepthType depthType, IInputArray mask = null, Stream stream = null)
 {
    using (InputArray iaSrc = src.GetInputArray())
    using (OutputArray oaDst = dst.GetOutputArray())
    using (InputArray iaMask = mask == null ? InputArray.GetEmpty() : mask.GetInputArray())
    {
       cudaNormalize(iaSrc, oaDst, alpha, beta, normType, depthType, iaMask, stream);
    }
 }
Example #19
0
 /// <summary>
 /// computes norm of the selected array part
 /// </summary>
 /// <param name="normType">Type of the norm</param>
 /// <param name="mask">The optional operation mask</param>
 /// <returns></returns>
 public double Norm(NormType normType = NormType.L2, InputArray mask = null)
 {
     return Cv2.Norm(this, normType, mask);
 }
Example #20
0
        /// <summary>
        /// 配列の絶対値ノルム(absolute array norm),絶対値差分ノルム(absolute difference norm),相対値差分ノルム(relative difference norm)を計算する
        /// </summary>
        /// <param name="arr1">1番目の入力画像</param>
        /// <param name="arr2">2番目の入力画像.null の場合,arr1の絶対値ノルムが計算され,そうでない場合は,arr1-arr2 の絶対値あるいは相対値ノルムが計算される. </param>
        /// <param name="normType">ノルムのタイプ</param>
        /// <returns></returns>
#else
        /// <summary>
        /// Calculates absolute array norm, absolute difference norm or relative difference norm
        /// </summary>
        /// <param name="arr1">The first source image. </param>
        /// <param name="arr2">The second source image. If it is null, the absolute norm of arr1 is calculated, otherwise absolute or relative norm of arr1-arr2 is calculated. </param>
        /// <param name="normType">Type of norm</param>
        /// <returns></returns>
#endif
        public static double Norm(CvArr arr1, CvArr arr2, NormType normType)
        {
            return(Norm(arr1, arr2, normType, null));
        }
 public Indicators.SlopeEnhancedOp SlopeEnhancedOp(ISeries <double> input, int period, int detrendPeriod, int smooth, bool detrend, InputSeriesType inputType, NormType normType, Brush colorUp, Brush colorDown, PlotStyle lineStyle)
 {
     return(indicator.SlopeEnhancedOp(input, period, detrendPeriod, smooth, detrend, inputType, normType, colorUp, colorDown, lineStyle));
 }
 public SlopeEnhancedOp SlopeEnhancedOp(ISeries <double> input, int period, int detrendPeriod, int smooth, bool detrend, InputSeriesType inputType, NormType normType, Brush colorUp, Brush colorDown, PlotStyle lineStyle)
 {
     if (cacheSlopeEnhancedOp != null)
     {
         for (int idx = 0; idx < cacheSlopeEnhancedOp.Length; idx++)
         {
             if (cacheSlopeEnhancedOp[idx] != null && cacheSlopeEnhancedOp[idx].Period == period && cacheSlopeEnhancedOp[idx].DetrendPeriod == detrendPeriod && cacheSlopeEnhancedOp[idx].Smooth == smooth && cacheSlopeEnhancedOp[idx].Detrend == detrend && cacheSlopeEnhancedOp[idx].InputType == inputType && cacheSlopeEnhancedOp[idx].NormType == normType && cacheSlopeEnhancedOp[idx].ColorUp == colorUp && cacheSlopeEnhancedOp[idx].ColorDown == colorDown && cacheSlopeEnhancedOp[idx].LineStyle == lineStyle && cacheSlopeEnhancedOp[idx].EqualsInput(input))
             {
                 return(cacheSlopeEnhancedOp[idx]);
             }
         }
     }
     return(CacheIndicator <SlopeEnhancedOp>(new SlopeEnhancedOp()
     {
         Period = period, DetrendPeriod = detrendPeriod, Smooth = smooth, Detrend = detrend, InputType = inputType, NormType = normType, ColorUp = colorUp, ColorDown = colorDown, LineStyle = lineStyle
     }, input, ref cacheSlopeEnhancedOp));
 }
Example #23
0
 public static void CalcNormDiff(IInputArray src1, IInputArray src2, IOutputArray dst, NormType normType = NormType.L2,
    Stream stream = null)
 {
    using (InputArray iaSrc1 = src1.GetInputArray())
    using (InputArray iaSrc2 = src2.GetInputArray())
    using (OutputArray oaDst = dst.GetOutputArray())
       cudaCalcNormDiff(iaSrc1, iaSrc2, oaDst, normType, stream);
 }
Example #24
0
        /// <summary>
        /// Estimates the errors of the fields with name
        /// <paramref name="fieldName"/> in the given
        /// <paramref name="timesteps"/> by computing the errors with respect
        /// to the solution on the finest corresponding grid by making use of
        /// <see cref="BoSSS.Solution.Statistic.DGFieldComparison.ComputeErrors"/>.
        /// The result is then grouped according to the polynomial degree of field
        /// <paramref name="fieldName"/>.
        /// </summary>
        /// <param name="timesteps">
        /// The time-steps containing the fields whose errors should be
        /// estimated.
        /// </param>
        /// <param name="fieldName">
        /// The name of the DG field whose error should be estimated.
        /// </param>
        /// <param name="xAxis_Is_hOrDof">
        /// - true: the x-axis (<see cref="Plot2Ddata.XYvalues.Abscissas"/>) is the grid resolution \f$ h \f$
        /// - false: the x-axis (<see cref="Plot2Ddata.XYvalues.Abscissas"/>) is the number of degrees-of-freedom
        /// </param>
        /// <param name="normType">
        /// H1, L2, etc.
        /// </param>
        /// <returns>
        /// A data set containing information about the grid resolution and the
        /// corresponding errors with respect to the finest corresponding grid,
        /// grouped by the polynomial degree. Obviously, the time-step
        /// associated with the finest grid for each polynomial degree has an
        /// estimated error of zero (by definition) and is thus excluded from
        /// the result.
        /// </returns>
        public static Plot2Ddata ToEstimatedGridConvergenceData(this IEnumerable <ITimestepInfo> timesteps, string fieldName, bool xAxis_Is_hOrDof = true, NormType normType = NormType.L2_approximate)
        {
            Dictionary <string, double[][]> dataGroups = new Dictionary <string, double[][]>();

            foreach (var group in timesteps.GroupBy(t => t.Fields.Find(fieldName).Basis.Degree))
            {
                Dictionary <string, int[]>    DOFs;
                Dictionary <string, double[]> errors;
                double[] resolution;
                Guid[]   tsiIds;

                if (normType == NormType.L2_embedded)
                {
                    DGFieldComparison.ComputeErrors(
                        new string[] { fieldName },
                        group.ToArray(),
                        out resolution,
                        out DOFs,
                        out errors,
                        out tsiIds);
                }
                else if (normType == NormType.L2_approximate)
                {
                    DGFieldComparisonNonEmb.ComputeErrors_L2(
                        new string[] { fieldName },
                        group.ToArray(),
                        out resolution,
                        out DOFs,
                        out errors,
                        out tsiIds);
                }
                else if (normType == NormType.L2noMean_approximate)
                {
                    DGFieldComparisonNonEmb.ComputeErrors_L2noMean(
                        new string[] { fieldName },
                        group.ToArray(),
                        out resolution,
                        out DOFs,
                        out errors,
                        out tsiIds);
                }
                else if (normType == NormType.H1_approximate)
                {
                    DGFieldComparisonNonEmb.ComputeErrors_H1(
                        new string[] { fieldName },
                        group.ToArray(),
                        out resolution,
                        out DOFs,
                        out errors,
                        out tsiIds);
                }
                else
                {
                    throw new NotImplementedException();
                }

                double dim = timesteps.First().Grid.SpatialDimension;

                Debug.Assert(errors.ContainsKey(fieldName));
                Debug.Assert(errors[fieldName].Length == resolution.Length);

                Debug.Assert(DOFs.ContainsKey(fieldName));
                Debug.Assert(DOFs[fieldName].Length == resolution.Length);


                //double[][] resolutionsAndErrors = new double[2][] {
                //    xAxis_Is_hOrDof ? resolution : DOFs[fieldName].Select(ix => (double)ix).ToArray(),
                //    errors[fieldName] };

                double[] xValues = xAxis_Is_hOrDof ? resolution : DOFs[fieldName].Select(ix => Math.Pow((double)ix, 1.0 / dim)).ToArray();
                double[] yValues = errors[fieldName];
                if (xAxis_Is_hOrDof == false)
                {
                    // data is sorted according to mesh width, this may not be equal to sorting according to No. of. DOF
                    Array.Sort(xValues, yValues);
                }

                dataGroups.Add(group.Key.ToString(), new double[2][] { xValues, yValues });
            }

            return(new Plot2Ddata(dataGroups.ToArray()).WithLogX().WithLogY());
        }
Example #25
0
 private static extern void cudaCalcNormDiff(IntPtr src1, IntPtr src2, IntPtr dst, NormType normType, IntPtr stream);
Example #26
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="normType"></param>
 /// <param name="crossCheck"></param>
 public BFMatcher(NormType normType = NormType.L2, bool crossCheck = false)
 {
     ptr = NativeMethods.features2d_BFMatcher_new((int)normType, crossCheck ? 1 : 0);
 }
Example #27
0
 private static extern void cudaNormalize(IntPtr src, IntPtr dst, double alpha, double beta,
    NormType normType, CvEnum.DepthType dtype, IntPtr mask, IntPtr stream);
        public WeightTensor CreateWeightTensor(int row, int column, int deviceId, bool cleanWeights = false, string name = "", bool isTrainable = false, IComputeGraph graphToBind = null, NormType normType = NormType.None)
        {
            WeightTensor r = new WeightTensor(new long[2] {
                row, column
            }, deviceId, name: name, isTrainable: isTrainable, NormType: normType, graphToBind: graphToBind);

            if (cleanWeights)
            {
                r.CleanWeight();
            }

            weights.Add(r);

            return(r);
        }
Example #29
0
 /// <summary>
 /// scales and shifts array elements so that either the specified norm (alpha) 
 /// or the minimum (alpha) and maximum (beta) array values get the specified values
 /// </summary>
 /// <param name="alpha">The norm value to normalize to or the lower range boundary 
 /// in the case of range normalization</param>
 /// <param name="beta">The upper range boundary in the case of range normalization; 
 /// not used for norm normalization</param>
 /// <param name="normType">The normalization type</param>
 /// <param name="dtype">When the parameter is negative, 
 /// the destination array will have the same type as src, 
 /// otherwise it will have the same number of channels as src and the depth =CV_MAT_DEPTH(rtype)</param>
 /// <param name="mask">The optional operation mask</param>
 /// <returns></returns>
 public Mat Normalize(double alpha = 1, double beta = 0,
     NormType normType = NormType.L2, int dtype = -1, InputArray mask = null)
 {
     var dst = new Mat();
     Cv2.Normalize(this, dst, alpha, beta, normType, dtype, mask);
     return dst;
 }
Example #30
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="normType"></param>
 /// <param name="crossCheck"></param>
 public BFMatcher(NormType normType = NormType.L2, bool crossCheck = false)
 {
     ptr = NativeMethods.features2d_BFMatcher_new((int)normType, crossCheck ? 1 : 0);
 }
Example #31
0
 /// <summary>
 /// computes norm of selected part of the difference between two arrays
 /// </summary>
 /// <param name="src1"></param>
 /// <param name="src2"></param>
 /// <param name="normType"></param>
 /// <param name="mask"></param>
 /// <returns></returns>
 public static double Norm(InputArray src1, InputArray src2,
                           NormType normType = NormType.L2, InputArray mask = null)
 {
     if (src1 == null)
         throw new ArgumentNullException("src1");
     if (src2 == null)
         throw new ArgumentNullException("src2");
     src1.ThrowIfDisposed();
     src2.ThrowIfDisposed();
     return NativeMethods.core_norm(src1.CvPtr, src2.CvPtr, (int)normType, ToPtr(mask));
 }
        public WeightTensor CreateWeightTensor(long[] sizes, int deviceId, bool cleanWeights = false, string name = "", IComputeGraph graphToBind = null, NormType normType = NormType.None)
        {
            WeightTensor r = new WeightTensor(sizes, deviceId, name, NormType: normType, graphToBind: graphToBind);

            if (cleanWeights)
            {
                r.CleanWeight();
            }

            weights.Add(r);

            return(r);
        }