Exemplo n.º 1
0
 public TSKNeuronet(int n, Dictionary <double, List <double[]> > xSet, int m)
 {
     M           = m; N = n;
     firstLayer  = new FirstLayer(n, xSet);
     secondLayer = new SecondLayer(m, n);
     thirdLayer  = new ThirdLayer(m, n);
     fourthLayer = new FourthLayer();
 }
        public void Forward(double[] input, double[] targets, bool doBackpropagation = true)
        {
            FirstLayer.Guess(input);

            if (doBackpropagation)
            {
                //Console.WriteLine("Output in NeuralNetworkOld:");
                //Console.WriteLine(LastLayer.O);

                LastLayer.Backwards(targets);
            }
        }
        public Matrix <double> Guess(double[] input)
        {
            Matrix <double> output = FirstLayer.Guess(input);

            return(output);
        }
 public void Initialize()
 {
     FirstLayer.Initialize(index: -1);
 }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            //IList<double> x = new List<double>() { 0, 1, 6, 12 };
            //IList<double> y = new List<double>() { 8, 10, 7, 0 };
            //ABSolver aBSolver = new ABSolver(x, y, 23);
            //IList<double> x = new List<double>() { 0, 7, 14, 21 };
            //IList<double> y = new List<double>() { 10, 6, 0, 7 };
            //ABSolver aBSolver = new ABSolver(x, y, 28);
            //IList<double> x = new List<double>() { 0, 8, 16, 17, 25 };
            //IList<double> y = new List<double>() { 10, 5, 1, 1, 5 };
            //ABSolver aBSolver = new ABSolver(x, y, 33);
            //FXFY res = aBSolver.Solve(1);
            //using (StreamWriter file = new StreamWriter(@"C:\dell\test.txt"))
            //{
            //    for (int i = 0; i < 10000; i++)
            //    {
            //        file.WriteLine(res.FX[i] + ";" + res.FY[i]);
            //    }
            //}
            //FurSolver furSolver = aBSolver.GetSolver();
            //BinaryFormatter bf = new BinaryFormatter();
            //byte[] serres = null;
            //using (var ms = new MemoryStream())
            //{
            //    bf.Serialize(ms, furSolver);
            //    serres = ms.ToArray();
            //}

            //string initstring = "= new byte[] { ";
            //for(int i = 0; i < serres.Length; i++)
            //{
            //    if (i == serres.Length - 1)
            //    {
            //        initstring += serres[i] + " }";
            //    } else
            //    {
            //        initstring += serres[i] + ", ";
            //    }

            //}
            //using (var memStream = new MemoryStream())
            //{
            //    var binForm = new BinaryFormatter();
            //    memStream.Write(serres, 0, serres.Length);
            //    memStream.Seek(0, SeekOrigin.Begin);
            //    FurSolver asfg = (FurSolver)binForm.Deserialize(memStream);
            //}
            //double yj = furSolver.CalcY(2234243);
            LStruct    lStruct    = new LStruct();
            FirstLayer firstLayer = new FirstLayer();

            IList <double> in1 = new List <double>()
            {
                5, 21, 33, 37, 4, 44, 1
            };
            IList <double> teach1 = new List <double>()
            {
                13, 34, 48, 5, 10, 4, 3
            };

            IList <double> in2 = new List <double>()
            {
                13, 34, 48, 5, 10, 4, 3
            };
            IList <double> teach2 = new List <double>()
            {
                23, 27, 40, 11, 18, 43, 39
            };

            IList <double> in3 = new List <double>()
            {
                23, 27, 40, 11, 18, 43, 39
            };
            IList <double> teach3 = new List <double>()
            {
                7, 18, 19, 20, 1, 46, 12
            };

            IList <double> in4 = new List <double>()
            {
                7, 18, 19, 20, 1, 46, 12
            };
            IList <double> teach4 = new List <double>()
            {
                39, 13, 48, 33, 8, 30, 22
            };

            IList <double> in5 = new List <double>()
            {
                39, 13, 48, 33, 8, 30, 22
            };
            IList <double> teach5 = new List <double>()
            {
                3, 9, 32, 36, 45, 6, 46
            };

            firstLayer.Outs = in1;
            Layer l1 = new Layer(15, AFType.BentIdentity);

            lStruct.Pairs.Add(new KeyValuePair <Guid, Guid>(firstLayer.ID, l1.ID));
            lStruct.Layers.Add(l1);
            Layer l2 = new Layer(30, AFType.sin);

            lStruct.Pairs.Add(new KeyValuePair <Guid, Guid>(l1.ID, l2.ID));
            lStruct.Layers.Add(l2);
            Layer outl = new Layer(7, AFType.arctg);

            lStruct.Pairs.Add(new KeyValuePair <Guid, Guid>(l2.ID, outl.ID));
            lStruct.Layers.Add(outl);

            lStruct.Solve(firstLayer);
            lStruct.Training(teach1, outl);

            firstLayer.Outs = in2;
            lStruct.Solve(firstLayer);
            lStruct.Training(teach2, outl);

            firstLayer.Outs = in3;
            lStruct.Solve(firstLayer);
            lStruct.Training(teach3, outl);

            firstLayer.Outs = in4;
            lStruct.Solve(firstLayer);
            lStruct.Training(teach4, outl);

            firstLayer.Outs = in5;
            lStruct.Solve(firstLayer);
            lStruct.Training(teach5, outl);
        }
Exemplo n.º 6
0
    //esto puede ser optimizado con el SetTileRotation
    //Esta verga no furula
    void PhysicalMap(List <MapTile> MapData)
    {
        //Change this so it goes organized by the order of the map because the order is probably not being respected
        for (int x = 0; x < MapData.Count; x++)
        {
            if (MapData[x] != null)
            {
                Tile ActualTile = null;
                Tile OcupyTile = null;
                bool North = false, East = false, South = false, West = false;
                bool NorthWest = false, NorthEast = false, SouthEast = false, SouthWest = false;
                int  GrassCloseN = 0, GrassFarN = 0;
                //The floor
                switch (MapData[x].Type)
                {
                case TileType.Ground:
                    ActualTile = grass_Tiles.Basic[0];
                    break;

                case TileType.Water:
                    // Debug.Log("agua");
                    //select the one that is actually acurate
                    North     = false; East = false; South = false; West = false;
                    NorthWest = false; NorthEast = false; SouthEast = false; SouthWest = false;

                    for (int nn = 0; nn < MapData[x].Neighbours.Length; nn++)
                    //foreach (MapTile N in AllMapTiles[x].Neighbours)
                    {
                        if (MapData[x].Neighbours[nn] != null && MapData[x].Neighbours[nn].Type == TileType.Ground)
                        {
                            GrassCloseN++;

                            if (nn == 0)     //North
                            {
                                North = true;
                            }

                            if (nn == 2)     //South
                            {
                                South = true;
                            }

                            if (nn == 1)     //East
                            {
                                East = true;
                            }

                            if (nn == 3)     //West
                            {
                                West = true;
                            }
                        }
                    }

                    switch (GrassCloseN)
                    {
                    case 4:
                        ActualTile = water_Tiles.Grass[3];
                        break;

                    case 3:
                        ActualTile = water_Tiles.Grass[2];
                        break;

                    case 2:
                        if ((North && South) || (East && West))
                        {
                            ActualTile = water_Tiles.Grass[4];
                        }
                        else
                        {
                            ActualTile = water_Tiles.Grass[1];
                        }

                        break;

                    case 1:
                        // Debug.Log("should");
                        ActualTile = water_Tiles.Grass[0];
                        break;

                    default:
                        //Algo esta mal aqui
                        for (int fn = 0; fn < MapData[x].FarNeighbours.Length; fn++)
                        //foreach (MapTile FN in AllMapTiles[x].FarNeighbours)
                        {
                            if (MapData[x].FarNeighbours[fn] != null && MapData[x].FarNeighbours[fn].Type == TileType.Ground)
                            {
                                GrassFarN++;

                                if (fn == 0)         // NorthWest
                                {
                                    NorthWest = true;
                                }
                                if (fn == 1)         // NorthEast
                                {
                                    NorthEast = true;
                                }
                                if (fn == 2)         // SouthEast
                                {
                                    SouthEast = true;
                                }
                                if (fn == 3)         // SouthWest
                                {
                                    SouthWest = true;
                                }
                            }
                        }
                        break;
                    }

                    if (GrassCloseN == 0)
                    {
                        switch (GrassFarN)
                        {
                        case 4:
                            ActualTile = water_Tiles.Grass[8];
                            break;

                        case 3:
                            ActualTile = water_Tiles.Grass[7];
                            break;

                        case 2:
                            if ((NorthWest && SouthEast) || (NorthEast && SouthWest))
                            {
                                ActualTile = water_Tiles.Grass[9];
                            }
                            else
                            {
                                ActualTile = water_Tiles.Grass[6];
                            }


                            break;

                        case 1:
                            ActualTile = water_Tiles.Grass[5];
                            break;

                        default:
                            ActualTile = water_Tiles.Basic[0];         //basic water always
                            break;
                        }
                    }


                    // ActualTile = water_Tiles.Basic[0];
                    break;
                }
                //Whats on Layer 2
                switch (MapData[x].OcupedByMat)
                {
                case MaterialTile.None:
                    OcupyTile = null;
                    break;

                case MaterialTile.Tree:
                    int R = UnityEngine.Random.Range(0, materials.Trees.Length);
                    OcupyTile = materials.Trees[R];
                    break;

                case MaterialTile.Wall:
                    OcupyTile = materials.Mountains[0];
                    break;
                }

                // I changed the X and Y and it worked, not sure why tho
                Map.SetTile(new Vector3Int(MapData[x].X, MapData[x].Y, 0), ActualTile);
                SetTileRotation(MapData[x].X, MapData[x].Y, GrassCloseN, GrassFarN, North, East, South, West, NorthWest, NorthEast, SouthEast, SouthWest);

                if (OcupyTile != null)
                {
                    SecondLayer.SetTile(new Vector3Int(AllMapTiles[x].X, AllMapTiles[x].Y, 0), OcupyTile);
                }


                GrassCloseN = 0;
                GrassFarN   = 0;
            }
            else
            {
                Debug.Log("Ay mama");
                MapData.RemoveAt(x);
            }

            //create the Grid show thing (I think we dont need this
            FirstLayer.SetTile(new Vector3Int(MapData[x].X, MapData[x].Y, 0), GridTileShowThing);


            //  Debug.Log("X:" + MapData[0].X + " |Y:" + MapData[0].Y + " / Type:" + MapData[0].Type);
        }
    }