Esempio n. 1
0
        static void Main(string[] args)
        {
            grid_x = 10;
            grid_y = 10;
            Stopwatch sw = new Stopwatch();

            sw.Start();
            FileOperations.Read(@"..\..\..\Datasets\emlak-veri.csv");
            Console.WriteLine("Running SOM...");
            SOM.Run(grid_x, grid_y, 500 * (grid_x * grid_y), 0.1, (grid_x + grid_y) / 2);
            sw.Stop();
            FileOperations.Write("output_weights.txt");
            Console.WriteLine("Total time: " + sw.Elapsed);
            Application.EnableVisualStyles();
            Application.Run(new Visualize());
        }
Esempio n. 2
0
        public double[,] CreateHeatMapForSOM()//Creates heatmap with creating u-matrix
        {
            List <List <int> > neighbours = new List <List <int> >();

            for (int i = 0; i < Program.neuron_locs.Count; i++)//find neighbours of each neuron
            {
                List <int> temp = new List <int>();
                for (int j = 0; j < Program.neuron_locs.Count; j++)
                {
                    if (i != j && SOM.EuclideanDistance(Program.neuron_locs[i], Program.neuron_locs[j]) <= 2)
                    {
                        temp.Add(j);
                    }
                }
                neighbours.Add(temp);
            }

            double[,] heat_map = new double[2 * Program.grid_x - 1, 2 * Program.grid_y - 1];

            for (int i = 0; i < Program.neuron_locs.Count; i++)// fill cells between neurons with distances
            {
                for (int j = 0; j < neighbours[i].Count; j++)
                {
                    if (Program.neuron_locs[i][0] == Program.neuron_locs[neighbours[i][j]][0])    //if they are in same x axis
                    {
                        if (Program.neuron_locs[neighbours[i][j]][1] < Program.neuron_locs[i][1]) //left-side check
                        {
                            if (heat_map[Convert.ToInt32(Program.neuron_locs[i][0]), Convert.ToInt32(Program.neuron_locs[i][1])] == 0)
                            {
                                heat_map[Convert.ToInt32(Program.neuron_locs[i][0]), Convert.ToInt32(Program.neuron_locs[i][1]) - 1] = SOM.EuclideanDistance(Program.weights[i], Program.weights[neighbours[i][j]]);
                            }
                        }
                        else if (Program.neuron_locs[neighbours[i][j]][1] > Program.neuron_locs[i][1])//right-side check
                        {
                            if (heat_map[Convert.ToInt32(Program.neuron_locs[neighbours[i][j]][0]), Convert.ToInt32(Program.neuron_locs[neighbours[i][j]][1])] == 0)
                            {
                                heat_map[Convert.ToInt32(Program.neuron_locs[neighbours[i][j]][0]), Convert.ToInt32(Program.neuron_locs[neighbours[i][j]][1]) - 1] = SOM.EuclideanDistance(Program.weights[i], Program.weights[neighbours[i][j]]);
                            }
                        }
                    }
                    else//if they are in same y axis
                    {
                        if (Program.neuron_locs[neighbours[i][j]][0] < Program.neuron_locs[i][0])//up-side check
                        {
                            if (heat_map[Convert.ToInt32(Program.neuron_locs[i][0]), Convert.ToInt32(Program.neuron_locs[i][1])] == 0)
                            {
                                heat_map[Convert.ToInt32(Program.neuron_locs[i][0]) - 1, Convert.ToInt32(Program.neuron_locs[i][1])] = SOM.EuclideanDistance(Program.weights[i], Program.weights[neighbours[i][j]]);
                            }
                        }
                        else if (Program.neuron_locs[neighbours[i][j]][0] > Program.neuron_locs[i][0])//down-side check
                        {
                            if (heat_map[Convert.ToInt32(Program.neuron_locs[neighbours[i][j]][0]), Convert.ToInt32(Program.neuron_locs[neighbours[i][j]][1])] == 0)
                            {
                                heat_map[Convert.ToInt32(Program.neuron_locs[neighbours[i][j]][0]) - 1, Convert.ToInt32(Program.neuron_locs[neighbours[i][j]][1])] = SOM.EuclideanDistance(Program.weights[i], Program.weights[neighbours[i][j]]);
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < 2 * Program.grid_x - 1; i++)//fills neuron cells with surrounded cell averages
            {
                for (int j = 0; j < 2 * Program.grid_y - 1; j++)
                {
                    if (heat_map[i, j] == 0)
                    {
                        double sum   = 0;
                        int    count = 0;
                        if (j - 1 >= 0)
                        {
                            sum += heat_map[i, j - 1];
                            count++;
                        }
                        if (i - 1 >= 0)
                        {
                            sum += heat_map[i - 1, j];
                            count++;
                        }
                        if (i + 1 <= 2 * Program.grid_x - 2)
                        {
                            sum += heat_map[i + 1, j];
                            count++;
                        }
                        if (j + 1 <= 2 * Program.grid_y - 2)
                        {
                            sum += heat_map[i, j + 1];
                            count++;
                        }
                        heat_map[i, j] = sum / count;
                    }
                }
            }
            for (int i = 0; i < 2 * Program.grid_x - 1; i++)
            {
                for (int j = 0; j < 2 * Program.grid_y - 1; j++)
                {
                    if (heat_map[i, j] < Min_Value)
                    {
                        Min_Value = heat_map[i, j];
                    }
                    if (heat_map[i, j] > Max_Value)
                    {
                        Max_Value = heat_map[i, j];
                    }
                }
            }
            return(heat_map);
        }