⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 doc.cs

📁 基于BP算法的贝叶斯网络参数学习
💻 CS
📖 第 1 页 / 共 5 页
字号:
            this.toolStripStatusLabel5,
            this.toolStripStatusLabel6,
            this.toolStripStatusLabel7,
            this.toolStripProgressBar1});
            this.statusStrip1.Location = new System.Drawing.Point(0, 398);
            this.statusStrip1.Name = "statusStrip1";
            this.statusStrip1.Size = new System.Drawing.Size(671, 22);
            this.statusStrip1.TabIndex = 1;
            this.statusStrip1.Text = "statusStrip1";
            // 
            // toolStripStatusLabel1
            // 
            this.toolStripStatusLabel1.BackColor = System.Drawing.Color.Yellow;
            this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
            this.toolStripStatusLabel1.Size = new System.Drawing.Size(29, 17);
            this.toolStripStatusLabel1.Text = "    ";
            this.toolStripStatusLabel1.VisitedLinkColor = System.Drawing.Color.Yellow;
            // 
            // toolStripStatusLabel2
            // 
            this.toolStripStatusLabel2.Name = "toolStripStatusLabel2";
            this.toolStripStatusLabel2.Size = new System.Drawing.Size(65, 17);
            this.toolStripStatusLabel2.Text = "无类型节点";
            // 
            // toolStripStatusLabel3
            // 
            this.toolStripStatusLabel3.BackColor = System.Drawing.Color.DarkKhaki;
            this.toolStripStatusLabel3.Name = "toolStripStatusLabel3";
            this.toolStripStatusLabel3.Size = new System.Drawing.Size(29, 17);
            this.toolStripStatusLabel3.Text = "    ";
            // 
            // toolStripStatusLabel4
            // 
            this.toolStripStatusLabel4.Name = "toolStripStatusLabel4";
            this.toolStripStatusLabel4.Size = new System.Drawing.Size(107, 17);
            this.toolStripStatusLabel4.Text = "Noisy_And类型节点";
            // 
            // toolStripStatusLabel5
            // 
            this.toolStripStatusLabel5.BackColor = System.Drawing.Color.OrangeRed;
            this.toolStripStatusLabel5.Name = "toolStripStatusLabel5";
            this.toolStripStatusLabel5.Size = new System.Drawing.Size(29, 17);
            this.toolStripStatusLabel5.Text = "    ";
            // 
            // toolStripStatusLabel6
            // 
            this.toolStripStatusLabel6.Name = "toolStripStatusLabel6";
            this.toolStripStatusLabel6.Size = new System.Drawing.Size(101, 17);
            this.toolStripStatusLabel6.Text = "Noisy_Or类型节点";
            // 
            // toolStripStatusLabel7
            // 
            this.toolStripStatusLabel7.Name = "toolStripStatusLabel7";
            this.toolStripStatusLabel7.Size = new System.Drawing.Size(53, 17);
            this.toolStripStatusLabel7.Text = "训练进度";
            // 
            // toolStripProgressBar1
            // 
            this.toolStripProgressBar1.BackColor = System.Drawing.Color.Yellow;
            this.toolStripProgressBar1.ForeColor = System.Drawing.Color.Red;
            this.toolStripProgressBar1.Name = "toolStripProgressBar1";
            this.toolStripProgressBar1.Size = new System.Drawing.Size(100, 16);
            this.toolStripProgressBar1.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
            // 
            // Doc
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.AutoScroll = true;
            this.BackColor = System.Drawing.Color.Linen;
            this.ClientSize = new System.Drawing.Size(671, 420);
            this.Controls.Add(this.statusStrip1);
            this.Controls.Add(this.toolStrip1);
            this.Name = "Doc";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Doc";
            this.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.Doc_MouseDoubleClick);
            this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Doc_MouseUp);
            this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Doc_MouseDown);
            this.toolStrip1.ResumeLayout(false);
            this.toolStrip1.PerformLayout();
            this.statusStrip1.ResumeLayout(false);
            this.statusStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		public void RemoveAllOfTheForm()
		{
			foreach (Control c in FormControls)
			{
				Controls.Remove(c);
			}

			FormControls.Clear();

			
			Invalidate();
		}//删除所有控件
		public void AddTheControl(Control c)
		{
			Controls.Add(c);
			FormControls.Add(c);
			NumControlsAdded++;
			PreviousControl = LastControl;
			LastControl = Controls[Controls.Count - 1];
		}//添加一个控件
        #region 注释
        //private void Doc_Load(object sender, System.EventArgs e)
		//{
		//this.Parent
		//this.Parent.miView.
		//}
		/*public float fontSize
		{
			get
			{
				return m_fontSize;
			}
			set
			{
				m_fontSize=value;
			}
		}*/

		/**
   * Save a BayesNet object in a stream, in the XMLBIF format
   * version 0.3 (most recent version).
   */
        // 一般情况下(节点的range多于2个时),
        #endregion
        public void save_xml1()
        {
            #region 保存文件代码(xml)
            //写成xml的格式

			SaveFileDialog sfDlg=new SaveFileDialog();
			sfDlg.Filter="Belief Network Format(*.xml)|*.xml|All Files(*.*)|*.*";
			sfDlg.FilterIndex=1;
			sfDlg.DefaultExt="xml";
			sfDlg.AddExtension=true;
			sfDlg.RestoreDirectory=true;
			sfDlg.InitialDirectory="E:\\wy\\xml";
			if(sfDlg.ShowDialog()==DialogResult.OK)
			{
				document = sfDlg.FileName;
				XmlTextWriter myXmlTextWriter = null;
				try
				{
					myXmlTextWriter = new XmlTextWriter (document, null);
					myXmlTextWriter.Formatting = Formatting.Indented;
					myXmlTextWriter.QuoteChar=(char)39;//用 < 来括起属性值
					myXmlTextWriter.Indentation=5;
					myXmlTextWriter.WriteStartDocument(false);				
					myXmlTextWriter.WriteStartElement("BNetNodes");
				
					foreach(BNode1 node in myNodeArray)
					{
						myXmlTextWriter.WriteStartElement(node.name);
						myXmlTextWriter.WriteAttributeString("Range",node.Range.ToString());
				
						myXmlTextWriter.WriteStartElement("Parents");
						myXmlTextWriter.WriteAttributeString("num",this.Parent(node.name).Count.ToString());
                        if (this.Parent(node.name).Count != 0)
                        {
                            for (int i = 0; i < this.Parent(node.name).Count; i++)
                            {
                                myXmlTextWriter.WriteStartElement(this.Parent(node.name)[i].ToString());
                                myXmlTextWriter.WriteEndElement();
                            }
                        }
						myXmlTextWriter.WriteEndElement();

                        /////////////////////////////////////////////////////
                        //yXmlTextWriter.WriteStartElement("type");
                        if (node.m_style != "")
                        {
                            myXmlTextWriter.WriteElementString("style", node.m_style);
                        }
                        else 
                        {
                            myXmlTextWriter.WriteElementString("style", "no_style");
                        }
                        //myXmlTextWriter.WriteEndElement();
                        /////////////////////////////////////////////////////

						myXmlTextWriter.WriteElementString("POSITION", null,"("+node.Left.ToString()+","+node.Top.ToString()+")");

						myXmlTextWriter.WriteStartElement("CPT_Col");
						
						for(int i=0;i<this.AssessNumRows(this.Parent(node.name));i++)
						{
							string ss="";
							ss+=node.CPT[i,0].ToString();
							for(int j=1;j<node.Range;j++)
								ss+=","+node.CPT[i,j].ToString();
							myXmlTextWriter.WriteElementString("CP", null,ss);
						}
                     
						myXmlTextWriter.WriteEndElement();
						myXmlTextWriter.WriteEndElement();					
					}
					myXmlTextWriter.WriteEndElement();
								
					myXmlTextWriter.Flush();
					myXmlTextWriter.Close();
                    MessageBox.Show("已经保存!");
				}
				catch(Exception er)
				{
					MessageBox.Show(er.Message+"\r\n 文档没有保存!");
				}
            }
            #endregion
        }
        #region 注释
        /*int i;
			String property;

			// Heading for the file
			pstream.WriteLine("<?xml version=\"1.0\" encoding=\"US-ASCII\"?>\n\n");
			pstream.WriteLine("<!--");
			pstream.WriteLine("\tBayesian network in XMLBIF v0.3 (BayesNet Interchange Format)");
			//pstream.println("\tProduced by JavaBayes (http://www.cs.cmu.edu/~javabayes/");
			pstream.WriteLine("\tOutput created " + (DateTime.Now.ToString()));
			pstream.WriteLine("-->\n\n\n");

			pstream.WriteLine("<!-- DTD for the XMLBIF 0.3 format -->");
			pstream.WriteLine("<!DOCTYPE BIF [\n" +
				"\t<!ELEMENT BIF ( NETWORK )*>\n" +
				"\t      <!ATTLIST BIF VERSION CDATA #REQUIRED>\n" +
				"\t<!ELEMENT NETWORK ( NAME, ( PROPERTY | VARIABLE | DEFINITION )* )>\n" +
				"\t<!ELEMENT NAME (#PCDATA)>\n" +
				"\t<!ELEMENT VARIABLE ( NAME, ( OUTCOME |  PROPERTY )* ) >\n" +
				"\t      <!ATTLIST VARIABLE TYPE (nature|decision|utility) \"nature\">\n" +
				"\t<!ELEMENT OUTCOME (#PCDATA)>\n" +
				"\t<!ELEMENT DEFINITION ( FOR | GIVEN | TABLE | PROPERTY )* >\n" +
				"\t<!ELEMENT FOR (#PCDATA)>\n" +
				"\t<!ELEMENT GIVEN (#PCDATA)>\n" +
				"\t<!ELEMENT TABLE (#PCDATA)>\n" +
				"\t<!ELEMENT PROPERTY (#PCDATA)>\n" +
				"]>\n\n");

			// Start of Bayes net
			pstream.WriteLine("<BIF VERSION=\"0.3\">");

			// Bayes net description
			pstream.WriteLine("<NETWORK>");
			if (name != null)
				pstream.WriteLine("<NAME>" + name + "</NAME>");
			if ((properties != null) && (properties.size() > 0)) 
			{
				for (Enumeration e = properties.elements(); e.hasMoreElements(); ) 
				{
					property = (String)(e.nextElement());
					pstream.println("\t<PROPERTY>" + property + "</PROPERTY>");
				}
			}
			pstream.println();

			// Variables
			pstream.WriteLine("<!-- Variables -->");
			if (probability_variables != null)
				for (i=0; i<probability_variables.length; i++)
					if (probability_variables[i] != null)
						probability_variables[i].save_xml_0_3(pstream);
			pstream.println();

			// Probability distributions.
			pstream.println("<!-- Probability distributions -->");
			if (probability_functions != null)
				for (i=0; i<probability_functions.length; i++)
					if (probability_functions[i] != null)
						probability_functions[i].save_xml_0_3(pstream);
			pstream.println();

			// End of Bayes net description.
			pstream.println("</NETWORK>");

			// End of Bayes net.
			pstream.println("</BIF>");
			*/

		/*//origin idea	
		 * originfrom=from;
			//originto=to;
		/*	AddEdgeDialog dlg=new AddEdgeDialog();
			dlg.ShowDialog();
			if(dlg.DialogResult == DialogResult.OK )
			{
				foreach(BNode1 node in myNodeArray)
				{
					if(node.Text==dlg.SNode)
						//MessageBox.Show(node.Text);
						from=node.from;
					if(node.Text==dlg.DNode)
						to=node.to;
				}
				if(from!=originfrom&&to!=originto)
				{
					Graphics g=this.CreateGraphics();
					g.DrawLine(new Pen(Color.Blue,1),from,to);
				}
				else
				{
					MessageBox.Show("the edge is already exist");
				}

			}/* Point fromPoint=new Point(0,0);
			Point toPoint=new Point(0,0);
			foreach(BNode1 node in myNodeArray)
			
			{
				if(node.Cursor==Cursors.No)
					//MessageBox.Show(node.from.X.ToString());
					 fromPoint =node.from;
				if(node.Cursor==Cursors.Cross)
					toPoint=node.to;

			}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -