Example #1
0
 /// <summary>
 /// law を利用した加算
 /// </summary>
 protected static double[] plus(Vector l, Vector r)
 {
     VectorChecker.SizeEquals(l, r);
     double[] ret = null;
     krdlab.law.func.daxpy_r(ref ret, 1, l._body, r._body);
     return(ret);
 }
Example #2
0
 /// <summary>
 /// law を利用した減算
 /// </summary>
 protected static double[] sub(Vector l, Vector r)
 {
     VectorChecker.SizeEquals(l, r);
     double[] ret = null;
     // ret := -r + l
     krdlab.law.func.daxpy_r(ref ret, -1, r._body, l._body);
     return(ret);
 }
Example #3
0
        internal static V SubEq <V>(V v1, V v2)
            where V : IRandomAccessible <double>
        {
            VectorChecker.SizeEquals(v1, v2);
            int size = v1.Size;

            for (int i = 0; i < size; ++i)
            {
                v1[i] -= v2[i];
            }
            return(v1);
        }
Example #4
0
        /// <summary>
        /// 2つのベクトルの相関を求める.
        /// </summary>
        /// <param name="vx">ベクトル</param>
        /// <param name="vy">ベクトル</param>
        /// <returns>相関</returns>
        /// <exception cref="System.ArgumentException">
        /// ベクトルのサイズが一致しないときにthrowされる.
        /// </exception>
        public static double Correlate(IVector vx, IVector vy)
        {
            VectorChecker.SizeEquals(vx, vy);

            double sxy   = 0.0;
            double avg_x = vx.Average;
            double avg_y = vy.Average;

            for (int i = 0; i < vx.Size; ++i)
            {
                sxy += ((vx[i] - avg_x) * (vy[i] - avg_y));
            }
            return(sxy / Math.Sqrt(vx.Scatter * vy.Scatter));
        }
Example #5
0
 /// <summary>
 /// law を利用した内積
 /// </summary>
 protected static double dot(Vector l, Vector r)
 {
     VectorChecker.SizeEquals(l, r);
     return(krdlab.law.func.ddot(l._body, r._body));
 }