Example #1
0
        public virtual void TestIsZero()
        {
            double[][]   values  = new double[][] { new double[] { 0.1, 0.2, 0.3, 0.4, 0.5 }, new double[] { 0.0, 0.0, 0.0, 0.0, 0.0 } };
            SimpleMatrix vector1 = new SimpleMatrix(values);

            NUnit.Framework.Assert.IsFalse(NeuralUtils.IsZero(vector1));
            values  = new double[][] { new double[] { 0.0, 0.0, 0.0, 0.0, 0.0 }, new double[] { 0.0, 0.0, 0.0, 0.0, 0.0 } };
            vector1 = new SimpleMatrix(values);
            NUnit.Framework.Assert.IsTrue(NeuralUtils.IsZero(vector1));
        }
        /// <summary>Output the tensor one slice at a time.</summary>
        /// <remarks>
        /// Output the tensor one slice at a time.  Each number is output
        /// with the format given, so for example "%f"
        /// </remarks>
        public virtual string ToString(string format)
        {
            StringBuilder result = new StringBuilder();

            for (int slice = 0; slice < numSlices; ++slice)
            {
                result.Append("Slice ").Append(slice).Append("\n");
                result.Append(NeuralUtils.ToString(slices[slice], format));
            }
            return(result.ToString());
        }
 /// <summary>Returns true iff every element of the tensor is 0</summary>
 public virtual bool IsZero()
 {
     for (int i = 0; i < numSlices; ++i)
     {
         if (!NeuralUtils.IsZero(slices[i]))
         {
             return(false);
         }
     }
     return(true);
 }
Example #4
0
        public virtual void TestCosine()
        {
            double[][] values = new double[][] { new double[5] };
            values[0] = new double[] { 0.1, 0.2, 0.3, 0.4, 0.5 };
            SimpleMatrix vector1 = new SimpleMatrix(values);

            values[0] = new double[] { 0.5, 0.4, 0.3, 0.2, 0.1 };
            SimpleMatrix vector2 = new SimpleMatrix(values);

            NUnit.Framework.Assert.AreEqual(NeuralUtils.Dot(vector1, vector2), 1e-5, 0.35000000000000003);
            NUnit.Framework.Assert.AreEqual(NeuralUtils.Cosine(vector1, vector2), 1e-5, 0.6363636363636364);
            vector1 = vector1.Transpose();
            vector2 = vector2.Transpose();
            NUnit.Framework.Assert.AreEqual(NeuralUtils.Dot(vector1, vector2), 1e-5, 0.35000000000000003);
            NUnit.Framework.Assert.AreEqual(NeuralUtils.Cosine(vector1, vector2), 1e-5, 0.6363636363636364);
        }