示例#1
0
        public void matrix_test_bytes()
        {
            string localPath = Path.Combine(System.Environment.CurrentDirectory, "Assets", "mat");

            #region doc_matrix_byte
            // Let's say we would like to load different .mat files which can be found at:
            // https://github.com/accord-net/framework/blob/development/Unit%20Tests/ISynergy.Framework.Mathematics.Tests/Resources/mat/

            // Let's assume they all currently reside in a "localPath"
            // folder. So let's start by trying to load a 8-bit matrix:
            string pathInt8 = Path.Combine(localPath, "int8.mat");

            // Create a .MAT reader for the file:
            var reader = new MatReader(pathInt8);

            // The variable in the file is called "arr"
            sbyte[,] matrix = reader.Read <sbyte[, ]>("arr");

            // The arr matrix should be equal to { -128, 127 }

            // (in case he didn't know the name of the variable,
            // we would have inspected the FieldNames property:
            string[] names = reader.FieldNames; // should contain "arr"
            #endregion

            CollectionAssert.AreEqual(new sbyte[, ]
            {
                { -128, 127 },
            }, matrix);

            CollectionAssert.AreEqual(new[] { "arr" }, names);
        }
示例#2
0
        public void matrix_test_int32()
        {
            string localPath = Path.Combine(System.Environment.CurrentDirectory, "Assets", "mat");

            #region doc_matrix_int32
            // Let's say we would like to load different .mat files which can be found at:
            // https://github.com/accord-net/framework/blob/development/Unit%20Tests/ISynergy.Framework.Mathematics.Tests/Resources/mat/

            // Let's assume they all currently reside in a "localPath"
            // folder. So let's start by trying to load a 32-bit matrix:
            string pathInt32 = Path.Combine(localPath, "int32.mat");

            // Create a .MAT reader for the file:
            var reader = new MatReader(pathInt32);

            // Let's check what is the name of the variable we need to load:
            string[] names = reader.FieldNames; // should be { "a" }

            // Ok, so we have to load the matrix called "a".

            // However, what if we didn't know the matrix type in advance?
            // In this case, we could use the non-generic version of Read:
            object unknown = reader.Read("a");

            // And we could check it's type through C#:
            Type t = unknown.GetType(); // should be typeof(int[,])

            // Now we could either cast it to the correct type or
            // use the generic version of Read<> to read it again:
            int[,] matrix = reader.Read <int[, ]>("a");

            // The a matrix should be equal to { 1, 2, 3, 4 }
            #endregion

            Assert.AreEqual(typeof(int[, ]), t);
            CollectionAssert.AreEqual(new int[, ]
            {
                { 1, 2, 3, 4 },
            }, matrix);
            CollectionAssert.AreEqual(new[] { "a" }, names);
        }
示例#3
0
        static void Main(string[] args)
        {
            var reader = new MatReader(@"D:\Учеба\4 курс\Нейроматематика\LAB3\данные к задачам\mnist\data.mat");
            var names  = reader.Fields.Keys;

            foreach (var name in names)
            {
                Console.WriteLine(name);
            }

            var t = reader.Read <byte[, ]>("y");

            t[0, 0] = 0;
            for (int i = 0; i < 5000; i += 500)
            {
                Console.WriteLine(t[i, 0]);
            }

            Console.ReadKey();
        }
示例#4
0
    void cgcoords_setup()
    {
        // Create a new MAT file reader
        string path_src_cage = Path.Combine("C:/Users/vrproject/Downloads/iccm_orig/iccm_v2", "src_cage.mat");
        //var reader = new MatReader(path_src_cage);
        var reader = new MatReader(new BinaryReader(new FileStream(path_src_cage, FileMode.Open)), false, false);

        //foreach (var field in reader.Fields)
        //    Debug.Log(field.Key);
        src_cage = reader.Read <double[, ]>("Y");

        //Debug.Log(src_cage[0, 0]+" "+src_cage[1, 0]);
        //Debug.Log(src_cage.GetLength(0) + " " + src_cage.GetLength(1));
        int cage_length = src_cage.GetLength(1);

        cmplx_cage = new Complex[cage_length];
        cagem1     = new Complex[cage_length];
        A          = new Complex[cage_length];
        Ap1        = new Complex[cage_length];
        B          = new Complex[cage_length];
        Bp1        = new Complex[cage_length];
        Bm1        = new Complex[cage_length];
        logBp1B    = new Complex[cage_length];
        wrongside  = new bool[cage_length];
        badB       = new bool[cage_length];
        badBp1     = new bool[cage_length];
        logBBm1    = new Complex[cage_length];
        C          = new Complex[cage_length];

        for (int i = 0; i < cage_length; i++)
        {
            cmplx_cage[i] = new Complex(src_cage[0, i], src_cage[1, i]);
        }
        //Debug.Log(cmplx_cage[914] + " " + cmplx_cage[234]);
        //Debug.Log(cmplx_cage[775]);
        for (int i = 0; i < cage_length - 1; i++)
        {
            cagem1[i + 1] = cmplx_cage[i];
        }

        cagem1[0] = cmplx_cage[cage_length - 1];
        //Debug.Log(cagem1[775]);


        for (int i = 0; i < cage_length; i++)
        {
            A[i] = cmplx_cage[i] - cagem1[i];
        }
        //Debug.Log(A[775]);


        for (int i = 1; i < cage_length; i++)
        {
            Ap1[i - 1] = A[i];
        }

        Ap1[cage_length - 1] = A[0];
        //Debug.Log(Ap1[775]);


        path_src_cage = Path.Combine("C:/Users/vrproject/Downloads/iccm_orig/iccm_v2", "f_i.mat");
        //var reader = new MatReader(path_src_cage);
        reader = new MatReader(new BinaryReader(new FileStream(path_src_cage, FileMode.Open)), false, false);
        //foreach (var field in reader.Fields)
        //    Debug.Log(field.Key);

        double_f_i = reader.Read <double[, ]>("double_f_i");
        //Debug.Log(double_f_i[0, 0] + " " + double_f_i[1, 0]);
        //Debug.Log(double_f_i.GetLength(0)+" "+double_f_i.GetLength(1));

        f_iLength = double_f_i.GetLength(1);

        f_i = new Complex[f_iLength];
        for (int i = 0; i < f_iLength && 2 * cage_length == f_iLength; i++)
        {
            f_i[i] = new Complex(double_f_i[0, i], double_f_i[1, i]);
        }
    }