当前位置: 首页>>代码示例>>C#>>正文


C# net.calculate方法代码示例

本文整理汇总了C#中net.calculate方法的典型用法代码示例。如果您正苦于以下问题:C# net.calculate方法的具体用法?C# net.calculate怎么用?C# net.calculate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net的用法示例。


在下文中一共展示了net.calculate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: button2_Click

        private void button2_Click(object sender, EventArgs e)
        {
            int num_size=int.Parse(textBox2.Text);
            int num_times = int.Parse(textBox1.Text);
            net SOM_net = new net(dim, (int)num_size);
            double[] data = new double[dim];
            double learning_rate = double.Parse(textBox3.Text);
            double var_t = double.Parse(textBox4.Text);
            double var = double.Parse(textBox6.Text);

            if (learning_rate > 1)
            {
                learning_rate = 1;
                textBox3.Text = "1";
            }
            else if (learning_rate < 0)
            {
                learning_rate = 0;
                textBox3.Text = "0";
            }

            //迭代
            for (int i = 0; i < num_times; i++)
            {
                //先跑一遍資料集
                for (int j = 0; j < dataset.Count; j++)
                {
                    for (int k = 0; k < dim; k++)
                        data[k] = dataset[i][k];
                    SOM_net.calculate(data);
                    SOM_net.adjust2(learning_rate * (1 - i / (double)num_times),i + 1, var, var_t);
                }
            }
            //打亂資料
            Random rand = new Random();
            int index;
            double[] temp;
            for (int i = 0; i < dataset.Count; i++)
            {
                index = rand.Next(0, dataset.Count - 1);
                temp = dataset[i];
                dataset[i] = dataset[index];
                dataset[index] = temp;
            }
             //畫出結果
            if (dim == 2)
            {
                Bitmap windowshow = new Bitmap(pictureBox1.Size.Width, pictureBox1.Size.Height);
                windowshow = window.Clone() as Bitmap;
                Graphics graph = Graphics.FromImage(windowshow);
                graph.PageUnit = GraphicsUnit.Pixel;
                graph.TranslateTransform((int)half_height, (int)half_width);
                SolidBrush mybrush = new SolidBrush(Color.Red);

                //畫出神經元連線
                Point begin = new Point(0, 0);
                Point end = new Point(0, 0);
                Pen mypen = new Pen(Color.Blue, 2);

                for (int i = 0; i < SOM_net.net_size; i++)
                    for (int j = 0; j < SOM_net.net_size; j++)
                    {
                        begin.X = (int)(half_width * SOM_net.cell[i, j].weight[0] / max_dis);
                        begin.Y = (int)(-1*half_height * SOM_net.cell[i, j].weight[1] / max_dis);

                        if (j > 0)//左
                        {
                            end.X = (int)(half_width * SOM_net.cell[i, j - 1].weight[0] / max_dis);
                            end.Y = (int)(-1 * half_height * SOM_net.cell[i, j - 1].weight[1] / max_dis);
                            graph.DrawLine(mypen, begin, end);
                        }
                        if (j + 1 < SOM_net.net_size)//右
                        {
                            end.X = (int)(half_width * SOM_net.cell[i, j + 1].weight[0] / max_dis);
                            end.Y = (int)(-1 * half_height * SOM_net.cell[i, j + 1].weight[1] / max_dis);
                            graph.DrawLine(mypen, begin, end);
                        }
                        if (i > 0)//上
                        {
                            end.X = (int)(half_width * SOM_net.cell[i - 1, j].weight[0] / max_dis);
                            end.Y = (int)(-1 * half_height * SOM_net.cell[i - 1, j].weight[1] / max_dis);
                            graph.DrawLine(mypen, begin, end);
                        }
                        if (i + 1 < SOM_net.net_size)//下
                        {
                            end.X = (int)(half_width * SOM_net.cell[i + 1, j].weight[0] / max_dis);
                            end.Y = (int)(-1 * half_height * SOM_net.cell[i + 1, j].weight[1] / max_dis);
                            graph.DrawLine(mypen, begin, end);
                        }
                    }
                //畫出神經元
                for (int i = 0; i < SOM_net.net_size; i++)
                {
                    for (int j = 0; j < SOM_net.net_size; j++)
                    {
                        Rectangle dot = new Rectangle((int)(half_width * SOM_net.cell[i, j].weight[0] / max_dis),(int)(-1 * half_height * SOM_net.cell[i, j].weight[1] / max_dis),6, 6);
                        graph.FillEllipse(mybrush, dot);
                    }
                }

//.........这里部分代码省略.........
开发者ID:yuxiang2025,项目名称:NN,代码行数:101,代码来源:Form1.cs


注:本文中的net.calculate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。