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


C# System.IO.StreamReader.DiscardBufferedData方法代码示例

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


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

示例1: Learn

        /// <summary>
        /// Counting function
        /// </summary>
        /// <param name="learningData">input csv file</param>
        /// <returns>a [3,x] int array contains all counts</returns>
        static int[,] Learn(string learningData)
        {
            int [,] counts;
            string[] line;
            int[] fields;
            int featuresCount;
            using (System.IO.StreamReader inFile = new System.IO.StreamReader(learningData))
            {
                line = inFile.ReadLine().Split(',');        // read first line to determine the number of features
                featuresCount = line.Length;                // number of features
                counts = new int[3, featuresCount];
                fields = new int[featuresCount];

                inFile.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);      // reset stream
                inFile.DiscardBufferedData();

                while (!inFile.EndOfStream)
                {
                    line = inFile.ReadLine().Split(',');
                    ParseFields(line, fields);
                    ++counts[fields[0], 0];         // increase the respective counts
                    ++counts[2, 0];                 //increase the total counts
                    for (int i = 1; i < featuresCount; ++i)
                    {
                        counts[fields[0], i] += fields[i];  // increase the respective counts
                        counts[2, i] += fields[i];          // increase the total counts
                    }
                }
            }

            //double[,] learned = new double[2, featuresCount];
            //learned[0, 0] = MEstimate(counts[0, 0], counts[2, 0]);
            //learned[1, 0] = MEstimate(counts[1, 0], counts[2, 0]);
            //for (int i = 1; i < featuresCount; ++i)
            //{
            //    learned[0, i] = MEstimate(counts[0, i], counts[0, 0]);
            //    learned[1, i] = MEstimate(counts[1, i], counts[1, 0]);
            //}

            if (debug)
            {
                PrintArr(counts, debugFile);
                //PrintArr(learned, debugFile);
            }

            return counts;
        }
开发者ID:ankel,项目名称:Heart-Anomalies,代码行数:52,代码来源:Program.cs

示例2: openEmissions_Click

        private void openEmissions_Click(object sender, EventArgs e)
        {
            // Set filter options and filter index.
            openFileDialog.FileName = "";
            openFileDialog.Filter = "Emission Files (.emit)|*.emit|All Files (*.*)|*.*";
            openFileDialog.FilterIndex = 1;
            openFileDialog.Multiselect = false;

            // Call the ShowDialog method to show the dialog box.
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string line;
                B = new MySparse2DMatrix();
                emissionsSymbols = new Id2Str();
                var separator = '\t';

                System.IO.StreamReader sr = new System.IO.StreamReader(openFileDialog.FileName);
                emissionsRichTextBox.Text = "";

                if ((line = sr.ReadLine()) != null)
                {
                    if (line.Split(separator).Length == 1)
                        separator = ' ';
                    sr.DiscardBufferedData();
                    sr.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
                    sr.BaseStream.Position = 0;
                }

                while ((line = sr.ReadLine()) != null)
                {
                    emissionsRichTextBox.Text += line + "\n";

                    string[] stateValue = line.Split(separator);
                    if (stateValue.Length == 3)
                    {
                        int row = stateSymbols.setId(stateValue[0]);
                        int col = emissionsSymbols.setId(stateValue[1]);
                        B.setValue(row, col, Double.Parse(stateValue[2], CultureInfo.InvariantCulture));
                    }
                }
                sr.Close();
                if (B.Count > 0)
                {
                    buttonCreateHMM.Enabled = true;
                    openObservationsToolStripMenuItem.Enabled = true;
                }
                else
                {
                    buttonCreateHMM.Enabled = false;
                    openObservationsToolStripMenuItem.Enabled = false;
                    MessageBox.Show("Error! Parsed emissions matrix resulted empty. Check your input file please.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
开发者ID:akyrey,项目名称:HiddenMarkovModel_Solver,代码行数:54,代码来源:MainForm.cs


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