Exemplo n.º 1
0
        public static float[,,,,] CincoxCinco(float[,,,,] a, float[,,,,] b)
        {
            c = new float[5, 5, 5, 5, 5];


            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    for (int k = 0; k < 4; k++)
                    {
                        for (int l = 0; l < 4; l++)
                        {
                            for (int m = 0; m < 4; m++)
                            {
                                if (i == j && j == k && k == l && l == m && m == i)
                                {
                                    c[i, j, k, l, m] = a[i, j, k, l, m] + b[i, j, k, l, m];
                                }
                                else
                                {
                                    c[i, j, k, l, m] = 0;
                                }
                            }
                        }
                    }
                }
            }

            return(c);
        }
Exemplo n.º 2
0
        public static Dictionary <string, int> PredictClass(List <DicomImage> dicomList, float age, int gender)
        {
            float[,,,,] image = PrepareImages(dicomList);
            TFTensor data = new[, ] {
                { age, gender }
            };

            using (var graph = new TFGraph())
            {
                graph.Import(File.ReadAllBytes("CNNModel.pb"));
                var session = new TFSession(graph);
                var runner  = session.GetRunner();
                runner.AddInput(graph["convInput"][0], image);
                runner.AddInput(graph["featInput"][0], data);
                runner.Fetch(graph["dense_4/Softmax"][0]);

                var output = runner.Run();

                TFTensor result = output[0];


                var r = (float[, ])output[0].GetValue();

                int[] rArr = new int[4];
                Dictionary <string, int> dict = new Dictionary <string, int>();
                dict.Add("Астроцитома (ступінь 2)", Convert.ToInt16(r[0, 0] * 90));
                dict.Add("Гліобластома", Convert.ToInt16(r[0, 1] * 90));
                dict.Add("Астроцитома (ступінь 3)", Convert.ToInt16(r[0, 2] * 90));
                dict.Add("Олігодендрагліома", Convert.ToInt16(r[0, 3] * 90));

                var orderedDict = dict.OrderByDescending(x => x.Value).Take(2).ToDictionary(x => x.Key, x => x.Value);

                return(orderedDict);
            }
        }
Exemplo n.º 3
0
        public static float[,,,,] TresxTres(float[,,,,] a, float[,,,,] b)
        {
            c = new float[5, 5, 5, 5, 5];


            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        if (i == j && j == k && k == i)
                        {
                            c[i, j, k, 0, 0] = a[i, j, k, 0, 0] + b[i, j, k, 0, 0];
                        }
                        else
                        {
                            c[i, j, k, 0, 0] = 0;
                        }
                    }
                }
            }

            return(c);
        }
Exemplo n.º 4
0
        public override void LoadGZ(string filename)
        {
            var file = new LanguageStatisticsFile(Path.Combine(DirectoryHelper.DirectoryLanguageStatistics, filename));

            Frequencies = (float[, , , , ])file.LoadFrequencies(5);
            Alphabet    = file.Alphabet;
        }
Exemplo n.º 5
0
        private void Awake()
        {
            inputInterface = player.GetComponent <Player.PlayerCharacter>();
            if (inputInterface == null)
            {
                Debug.LogError("Input interface not found");
            }


            QMat = DataStore.Load("QMat");

            if (QMat == null)
            {
                Debug.LogWarning("Coudln't load QMat!");
                QMat = new float[10, 2, 5, countMoves, 3];
            }

            // initialize random seed
            Random.InitState((int)System.DateTime.Now.TimeOfDay.Ticks);

            if (keyboard != null)
            {
                keyboard.SetInputInterface(inputInterface);
                keyboard.SetAction(Moves.Nothing);
            }
            else
            {
                Debug.LogError("Ai keyboard not found!");
            }

            //temps
            qvalues = new float[countMoves];
        }
Exemplo n.º 6
0
        public static float[,,,,] CuatroxCuatro(float[,,,,] a, float[,,,,] b)
        {
            c = new float[5, 5, 5, 5, 5];


            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    for (int k = 0; k < 4; k++)
                    {
                        for (int l = 0; l < 4; l++)
                        {
                            if (i == j && j == k && k == l && l == i)
                            {
                                c[i, j, k, l, 0] = a[i, j, k, l, 0] + b[i, j, k, l, 0];
                            }
                            else
                            {
                                c[i, j, k, l, 0] = 0;
                            }
                        }
                    }
                }
            }

            return(c);
        }
Exemplo n.º 7
0
    private void Awake()
    {
        string filename = "QMat";

        float[,,,,] oldKnowledge = DataStore.Load(filename); // 10,2,5,4,3
        float[,,,,] newKnowledge = new float[10, 2, 5, 4, 4];
        for (int pos = 0; pos < 10; pos++)
        {
            for (int height = 0; height < 2; height++)
            {
                for (int dist = 0; dist < 5; dist++)
                {
                    for (int move = 0; move < 4; move++)
                    {
                        for (int obst = 0; obst < 3; obst++)
                        {
                            newKnowledge[pos, height, dist, move, obst] =
                                oldKnowledge[pos, height, dist, move, obst];
                        }
                        newKnowledge[pos, height, dist, move, 3] = 0;
                    }
                }
            }
        }
        DataStore.Store(newKnowledge, filename);
        Debug.Log("Done!");
    }
Exemplo n.º 8
0
        float[,,,] _segDestinationVol;           //computed destination volume at dwnstrm junctions
        //1st = segmentIndex
        //2nd = segmentDirection
        //3rd = junctionNo
        //4th = downstream movement, 1 = downleft, 2 = downthru, 3 = downright, 4 = midblock
        /// <summary>
        /// Contains parameters necessary for creating an OD matrix.
        /// </summary>
        /// <param name="numSegments"></param>
        /// <param name="numAccessPointsWithinSegment"></param>
        public OriginDestinationData(int numSegments, int numAccessPointsWithinSegment)
        {
            _odSeeds           = new float[4, 4];
            _odMatrix          = new float[numSegments - 1, 2, numAccessPointsWithinSegment, 4, 4];  // Segment Index - Direction - AP Index (within Segment) - Upstream Mvmt - Downstream Mvmt
            _segOriginVol      = new float[numSegments - 1, 2, numAccessPointsWithinSegment, 4];     // Segment Index - Direction - AP Index (within Segment) - Upstream Mvmt
            _segDestinationVol = new float[numSegments - 1, 2, numAccessPointsWithinSegment, 4];     // Segment Index - Direction - AP Index (within Segment) - Downstream Mvmt

            //default values (HCM 2016, Chap. 30, p. 5)
            _odSeeds[0, 0] = 0.02f;
            _odSeeds[0, 1] = 0.91f;
            _odSeeds[0, 2] = 0.05f;
            _odSeeds[0, 3] = 0.02f;
            _odSeeds[1, 0] = 0.10f;
            _odSeeds[1, 1] = 0.78f;
            _odSeeds[1, 2] = 0.10f;
            _odSeeds[1, 3] = 0.02f;
            _odSeeds[2, 0] = 0.05f;
            _odSeeds[2, 1] = 0.92f;
            _odSeeds[2, 2] = 0.02f;
            _odSeeds[2, 3] = 0.01f;
            _odSeeds[3, 0] = 0.02f;
            _odSeeds[3, 1] = 0.97f;
            _odSeeds[3, 2] = 0.01f;
            _odSeeds[3, 3] = 0;
        }
Exemplo n.º 9
0
 private void SetUpData(int x, int y, int z, int t)
 {
     XDim        = x;
     YDim        = y;
     ZDim        = z;
     TimeSteps   = t;
     VectorArray = new Vector3[x, y, z, t, VectorNames.Count];
     ScalarArray = new float[x, y, z, t, ScalarNames.Count];
 }
Exemplo n.º 10
0
 void Start()
 {
     //Read Kerbin Climatology data
     _kwx_read = new read_climo();
     get_dims(); //Get coordinates of data
     //Retrieve climatological data for the full atmosphere (3D) and at the surface (2D)
     climo_3d = _kwx_read.getMPAS_3D("year");
     climo_2d = _kwx_read.getMPAS_2D("year");
 }
Exemplo n.º 11
0
    // Use this for initialization
    void Start()
    {
        gamma    = 0.96f;
        epsilon  = 0.05f;
        Q        = new float[distance_max, distance_max, distance_max, velocity_max, actions];
        counts   = new int[distance_max, distance_max, distance_max, velocity_max, actions];
        memories = new Memory[memories_max];

        memories_index       = 0;
        current_memories_num = 0;
    }
Exemplo n.º 12
0
        public static void Store(float [,,,,] mat, string name)
        {
            string path   = Application.persistentDataPath + "/" + name + ".bin";
            Stream stream = File.Open(path, FileMode.Create);

            var bformatter = new System.Runtime.Serialization
                             .Formatters.Binary.BinaryFormatter();

            bformatter.Serialize(stream, mat);
            stream.Flush();
            stream.Close();
        }
Exemplo n.º 13
0
 public Agent(bool enemy = false)
 {
     if (enemy)
     {
         random = new Random(DateTime.Now.Millisecond % DateTime.Now.Second);
     }
     else
     {
         random = new Random(DateTime.Now.Millisecond);
     }
     qTable_NoEnemy = new float[5, 10, 4];
     qTable_Enemy   = new float[5, 10, 5, 10, 4];
 }
Exemplo n.º 14
0
        public static float[,,,,] DosxDos(float[,,,,] a, float[,,,,] b)
        {
            c = new float[5, 5, 5, 5, 5];


            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    c[i, j, 0, 0, 0] = a[i, j, 0, 0, 0] * b[i, j, 0, 0, 0];
                }
            }

            return(c);
        }
Exemplo n.º 15
0
        internal void AssertArray(ndarray arrayData, float[,,,,] expectedData)
        {
            int lengthd0 = expectedData.GetLength(0);
            int lengthd1 = expectedData.GetLength(1);
            int lengthd2 = expectedData.GetLength(2);
            int lengthd3 = expectedData.GetLength(3);
            int lengthd4 = expectedData.GetLength(4);

            AssertShape(arrayData, lengthd0, lengthd1, lengthd2, lengthd3, lengthd4);
            AssertDataTypes(arrayData, expectedData);

            for (int i = 0; i < lengthd0; i++)
            {
                ndarray dim1Data = arrayData[i] as ndarray;
                for (int j = 0; j < lengthd1; j++)
                {
                    ndarray dim2Data = dim1Data[j] as ndarray;
                    for (int k = 0; k < lengthd2; k++)
                    {
                        ndarray dim3Data = dim2Data[k] as ndarray;
                        for (int l = 0; l < lengthd3; l++)
                        {
                            ndarray dim4Data = dim3Data[l] as ndarray;

                            for (int m = 0; m < lengthd4; m++)
                            {
                                float E1 = expectedData[i, j, k, l, m];
                                float A1 = (float)dim4Data[m];

                                if (float.IsNaN(E1) && float.IsNaN(A1))
                                {
                                    continue;
                                }
                                if (float.IsInfinity(E1) && float.IsInfinity(A1))
                                {
                                    continue;
                                }

                                Assert.AreEqual(E1, A1, 0.00000001);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 16
0
        public static float[,,,,] TresxTres(float[,,,,] a, float[,,,,] b)
        {
            c = new float[5, 5, 5, 5, 5];


            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        c[i, j, k, 0, 0] = a[i, j, k, 0, 0] * b[i, j, k, 0, 0];
                    }
                }
            }

            return(c);
        }
Exemplo n.º 17
0
        public static float[,,,,] Load(string name)
        {
            string path = Application.persistentDataPath + "/" + name + ".bin";

            if (!File.Exists(path))
            {
                return(null);
            }

            Stream stream = File.Open(path, FileMode.Open);

            var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

            float[,,,,] result = (float[, , , , ])bformatter.Deserialize(stream);

            stream.Close();

            return(result);
        }
Exemplo n.º 18
0
        public static float[,,,,] CuatroxCuatro(float[,,,,] a, float[,,,,] b)
        {
            c = new float[5, 5, 5, 5, 5];


            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    for (int k = 0; k < 4; k++)
                    {
                        for (int l = 0; l < 4; l++)
                        {
                            c[i, j, k, l, 0] = a[i, j, k, l, 0] + b[i, j, k, l, 0];
                        }
                    }
                }
            }

            return(c);
        }
Exemplo n.º 19
0
        public static float[,,,,] CincoxCinco(float[,,,,] a, float[,,,,] b)
        {
            c = new float[5, 5, 5, 5, 5];


            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    for (int k = 0; k < 4; k++)
                    {
                        for (int l = 0; l < 4; l++)
                        {
                            for (int m = 0; m < 4; m++)
                            {
                                c[i, j, k, l, m] = a[i, j, k, l, m] + b[i, j, k, l, m];
                            }
                        }
                    }
                }
            }

            return(c);
        }
Exemplo n.º 20
0
 public static Tensor <float> Values(float[,,,,] array)
 {
     return(Values <float>(array));
 }
Exemplo n.º 21
0
        //En este método se realiza la operación correspondiente a la selección en el combobox de la operación,
        // y en el combobox del tamaño, llamando el método correspondiente desde la librería creada por nosotros
        public void Operacion()
        {
            switch (op)
            {
            case "A+B":
                if (opc == "2x2")
                {
                    matrizC = Suma.DosxDos(matrizA, matrizB);
                }
                else if (opc == "3x3")
                {
                    matrizC = Suma.TresxTres(matrizA, matrizB);
                }
                else if (opc == "4x4")
                {
                    matrizC = Suma.CuatroxCuatro(matrizA, matrizB);
                }
                else if (opc == "5x5")
                {
                    matrizC = Suma.CincoxCinco(matrizA, matrizB);
                }

                break;

            case "B-A":
                if (opc == "2x2")
                {
                    matrizC = Resta.DosxDos(matrizB, matrizA);
                }
                else if (opc == "3x3")
                {
                    matrizC = Resta.TresxTres(matrizB, matrizA);
                }
                else if (opc == "4x4")
                {
                    matrizC = Resta.CuatroxCuatro(matrizB, matrizA);
                }
                else if (opc == "5x5")
                {
                    matrizC = Resta.CincoxCinco(matrizB, matrizA);
                }

                break;

            case "A-B":
                if (opc == "2x2")
                {
                    matrizC = Resta.DosxDos(matrizA, matrizB);
                }
                else if (opc == "3x3")
                {
                    matrizC = Resta.TresxTres(matrizA, matrizB);
                }
                else if (opc == "4x4")
                {
                    matrizC = Resta.CuatroxCuatro(matrizA, matrizB);
                }
                else if (opc == "5x5")
                {
                    matrizC = Resta.CincoxCinco(matrizA, matrizB);
                }

                break;

            case "B*A":
                if (opc == "2x2")
                {
                    matrizC = Multiplicacion.DosxDos(matrizA, matrizB);
                }
                else if (opc == "3x3")
                {
                    matrizC = Multiplicacion.TresxTres(matrizA, matrizB);
                }
                else if (opc == "4x4")
                {
                    matrizC = Multiplicacion.CuatroxCuatro(matrizA, matrizB);
                }
                else if (opc == "5x5")
                {
                    matrizC = Multiplicacion.CincoxCinco(matrizA, matrizB);
                }

                break;

            case "Suma de la diagonal":
                if (opc == "2x2")
                {
                    matrizC = Diagonal.DosxDos(matrizA, matrizB);
                }
                else if (opc == "3x3")
                {
                    matrizC = Diagonal.TresxTres(matrizA, matrizB);
                }
                else if (opc == "4x4")
                {
                    matrizC = Diagonal.CuatroxCuatro(matrizA, matrizB);
                }
                else if (opc == "5x5")
                {
                    matrizC = Diagonal.CincoxCinco(matrizA, matrizB);
                }

                break;
            }
        }
Exemplo n.º 22
0
 ///<summary>Constructs a tensor with data.</summary>
 ///<param name = "data">Initial data for the tensor.</param>
 ///<param name = "dtype">The desired data type of returned tensor. Default: if not passed, infers data type from data.</param>
 ///<param name = "requires_grad">If autograd should record operations on the returned tensor. Default: false.</param>
 public static Tensor tensor(float[,,,,] data, dtype dtype = torch.dtype.float32, bool requires_grad = false)
 {
     return(new Tensor(data, dtype, requires_grad));
 }