Exemple #1
0
 /// <summary>
 /// Division outarray[i] / val
 /// </summary>
 public static void Div(Floatarray outarray, float val)
 {
     for (int i = 0; i < outarray.Length1d(); i++)
     {
         outarray.Put1d(i, outarray.At1d(i) / val);
     }
 }
Exemple #2
0
 /// <summary>
 /// Subtraction val - outarray[i]
 /// </summary>
 public static void Sub(float val, Floatarray outarray)
 {
     for (int i = 0; i < outarray.Length1d(); i++)
     {
         outarray.Put1d(i, val - outarray.At1d(i));
     }
 }
Exemple #3
0
 /// <summary>
 /// Add outarray[i] + val
 /// </summary>
 public static void Add(Floatarray outarray, float val)
 {
     for (int i = 0; i < outarray.Length1d(); i++)
     {
         outarray.UnsafePut1d(i, outarray.UnsafeAt1d(i) + val);
     }
 }
Exemple #4
0
        /// <summary>
        /// Normalize the 1-norm of the array.
        /// </summary>
        public static void Normalize1(Floatarray a)
        {
            double scale = 1.0 / Norm1(a);

            for (int i = 0; i < a.Length1d(); i++)
            {
                a.UnsafePut1d(i, (float)(a.UnsafeAt1d(i) * scale));
            }
        }
Exemple #5
0
        /// <summary>
        /// 1-norm.
        /// </summary>
        public static double Norm1(Floatarray a)
        {
            double total = 0.0;

            for (int i = 0; i < a.Length1d(); i++)
            {
                total += Math.Abs(a.UnsafeAt1d(i));
            }
            return(total);
        }
Exemple #6
0
        /// <summary>
        /// Euclidean norm squared.
        /// </summary>
        public static double Norm2Squared(Floatarray a)
        {
            double total = 0.0;

            for (int i = 0; i < a.Length1d(); i++)
            {
                float value = a.At1d(i);
                total += value * value;
            }
            return(total);
        }
Exemple #7
0
        public static float Fractile(Narray <float> a, double f)
        {
            Floatarray temp = new Floatarray();

            if (!(f >= 0 && f <= 1))
            {
                throw new Exception("CHECK: f >= 0 && f <= 1");
            }
            temp.Copy(a);
            temp.Reshape(temp.Length1d());
            Quicksort(temp);
            return(temp[(int)(f * temp.Length())]);
        }
Exemple #8
0
        public static float Max(Floatarray a)
        {
            float value = a.At1d(0);

            for (int i = 1; i < a.Length1d(); i++)
            {
                float nvalue = a.At1d(i);
                if (nvalue <= value)
                {
                    continue;
                }
                value = nvalue;
            }
            return(value);
        }
Exemple #9
0
        /// <summary>
        /// Euclidean distance squared.
        /// </summary>
        public static double Dist2Squared(Floatarray a, Floatarray b)
        {
            if (!a.SameDims(b))
            {
                throw new Exception("Dist2Squared: !a.SameDims(b)");
            }
            double total = 0.0;

            for (int i = 0; i < a.Length1d(); i++)
            {
                float val = a.At1d(i) - b.At1d(i);
                total += val * val;
            }
            if (double.IsNaN(total))
            {
                throw new Exception("Dist2Squared: total is NaN !");
            }
            return(total);
        }
Exemple #10
0
        public static int ArgMin(Floatarray a)
        {
            if (!(/*a.Rank() == 1 && **/ a.Dim(0) > 0))
            {
                throw new Exception("CHECK_ARG: a.Rank()==1 && a.Dim(0)>0");
            }
            float value = a.At1d(0);
            int   index = 0;

            for (int i = 1; i < a.Length1d(); i++)
            {
                float nvalue = a.At1d(i);
                if (nvalue >= value)
                {
                    continue;
                }
                value = nvalue;
                index = i;
            }
            return(index);
        }