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


C# CSV.ReadCSV类代码示例

本文整理汇总了C#中Encog.Util.CSV.ReadCSV的典型用法代码示例。如果您正苦于以下问题:C# ReadCSV类的具体用法?C# ReadCSV怎么用?C# ReadCSV使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ReadCSV类属于Encog.Util.CSV命名空间,在下文中一共展示了ReadCSV类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadTestData

        protected override void LoadTestData(string testFile)
        {
            ReadCSV test_csv = new ReadCSV(testFile, true, CSVFormat.DecimalPoint);

            List<double[]> test_input = new List<double[]>();
            test_input_orig = new List<double[]>();

            while (test_csv.Next())
            {
                double x = test_csv.GetDouble(0);

                test_input.Add(new[] { x });
                test_input_orig.Add(new[] { x });
            }

            test_csv.Close();

            //Analyze(ref test_input);
            Normalize(ref test_input, ref vmin, ref vmax);

            testData = new List<IMLData>();
            foreach (var d in test_input)
            {
                testData.Add(new BasicMLData(d));
            }
        }
开发者ID:sealionkat,项目名称:sn-mlp,代码行数:26,代码来源:RegressionNetwork.cs

示例2: LoadCSVTOMemory

        /// <summary>
        /// Load a CSV file into a memory dataset.  
        /// </summary>
        ///
        /// <param name="format">The CSV format to use.</param>
        /// <param name="filename">The filename to load.</param>
        /// <param name="headers">True if there is a header line.</param>
        /// <param name="inputSize">The input size.  Input always comes first in a file.</param>
        /// <param name="idealSize">The ideal size, 0 for unsupervised.</param>
        /// <returns>A NeuralDataSet that holds the contents of the CSV file.</returns>
        public static IMLDataSet LoadCSVTOMemory(CSVFormat format, String filename,
                                                bool headers, int inputSize, int idealSize)
        {
            var result = new BasicMLDataSet();
            var csv = new ReadCSV(filename, headers, format);
            while (csv.Next())
            {
                BasicMLData ideal = null;
                int index = 0;

                var input = new BasicMLData(inputSize);
                for (int i = 0; i < inputSize; i++)
                {
                    double d = csv.GetDouble(index++);
                    input[i] = d;
                }

                if (idealSize > 0)
                {
                    ideal = new BasicMLData(idealSize);
                    for (int i = 0; i < idealSize; i++)
                    {
                        double d = csv.GetDouble(index++);
                        ideal[i] = d;
                    }
                }

                IMLDataPair pair = new BasicMLDataPair(input, ideal);
                result.Add(pair);
            }

            return result;
        }
开发者ID:jongh0,项目名称:MTree,代码行数:43,代码来源:TrainingSetUtil.cs

示例3: Process

        /// <summary>
        /// Process the file and output to the target file.
        /// </summary>
        /// <param name="target">The target file to write to.</param>
        public void Process(string target)
        {
            var csv = new ReadCSV(InputFilename.ToString(), ExpectInputHeaders, Format);
            TextWriter tw = new StreamWriter(target);

            ResetStatus();
            while (csv.Next())
            {
                var line = new StringBuilder();
                UpdateStatus(false);
                line.Append(GetColumnData(FileData.Date, csv));
                line.Append(" ");
                line.Append(GetColumnData(FileData.Time, csv));
                line.Append(";");
                line.Append(Format.Format(double.Parse(GetColumnData(FileData.Open, csv)), Precision));
                line.Append(";");
                line.Append(Format.Format(double.Parse(GetColumnData(FileData.High, csv)), Precision));
                line.Append(";");
                line.Append(Format.Format(double.Parse(GetColumnData(FileData.Low, csv)), Precision));
                line.Append(";");
                line.Append(Format.Format(double.Parse(GetColumnData(FileData.Close, csv)), Precision));
                line.Append(";");
                line.Append(Format.Format(double.Parse(GetColumnData(FileData.Volume, csv)), Precision));

                tw.WriteLine(line.ToString());
            }
            ReportDone(false);
            csv.Close();
            tw.Close();
        }
开发者ID:Romiko,项目名称:encog-dotnet-core,代码行数:34,代码来源:NinjaFileConvert.cs

示例4: ReadAndCallLoader

        /// <summary>
        /// Reads the CSV and call loader.
        /// Used internally to load the csv and place data in the marketdataset.
        /// </summary>
        /// <param name="symbol">The symbol.</param>
        /// <param name="neededTypes">The needed types.</param>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <param name="File">The file.</param>
        /// <returns></returns>
        ICollection<LoadedMarketData> ReadAndCallLoader(TickerSymbol symbol, IEnumerable<MarketDataType> neededTypes, DateTime from, DateTime to, string File)
        {
                //We got a file, lets load it.

                ICollection<LoadedMarketData> result = new List<LoadedMarketData>();
                ReadCSV csv = new ReadCSV(File, true, CSVFormat.English);
                //In case we want to use a different date format...and have used the SetDateFormat method, our DateFormat must then not be null..
                //We will use the ?? operator to check for nullables.
                csv.DateFormat = DateFormat ?? "yyyy-MM-dd HH:mm:ss";
                csv.TimeFormat = "HH:mm:ss";

                DateTime ParsedDate = from;
                bool writeonce = true;

                while (csv.Next())
                {
                    DateTime date = csv.GetDate(0);
                    ParsedDate = date;

                    if (writeonce)
                    {
                        Console.WriteLine(@"First parsed date in csv:" + ParsedDate.ToShortDateString());
                        Console.WriteLine(@"Stopping at date:" + to.ToShortDateString());
                        Console.WriteLine(@"Current DateTime:" + ParsedDate.ToShortDateString() + @" Time:" +
                                          ParsedDate.ToShortTimeString() + @"  Asked Start date was " +
                                          from.ToShortDateString());
                        writeonce = false;
                    }
                    if (ParsedDate >= from && ParsedDate <= to)
                    {
                        DateTime datex = csv.GetDate(0);
                        double open = csv.GetDouble(1);
                        double close = csv.GetDouble(2);
                        double high = csv.GetDouble(3);
                        double low = csv.GetDouble(4);
                        double volume = csv.GetDouble(5);
                        double range = Math.Abs(open - close);
                        double HighLowRange = Math.Abs(high - low);
                        double DirectionalRange = close - open;
                        LoadedMarketData data = new LoadedMarketData(datex, symbol);
                        data.SetData(MarketDataType.Open, open);
                        data.SetData(MarketDataType.High, high);
                        data.SetData(MarketDataType.Low, low);
                        data.SetData(MarketDataType.Close, close);
                        data.SetData(MarketDataType.Volume, volume);
                        data.SetData(MarketDataType.RangeHighLow, Math.Round(HighLowRange, 6));
                        data.SetData(MarketDataType.RangeOpenClose, Math.Round(range, 6));
                        data.SetData(MarketDataType.RangeOpenCloseNonAbsolute, Math.Round(DirectionalRange, 6));
                        result.Add(data);


                    }

                }

                csv.Close();
                return result;
        }
开发者ID:MerlinBrasil,项目名称:encog-dotnet-core,代码行数:68,代码来源:CSVFinal.cs

示例5: ReadAndCallLoader

        public ICollection<LoadedMarketData> ReadAndCallLoader(TickerSymbol symbol, IList<MarketDataType> neededTypes, DateTime from, DateTime to, string File)
        {
            try
            {
                //We got a file, lets load it.
                ICollection<LoadedMarketData> result = new List<LoadedMarketData>();
                ReadCSV csv = new ReadCSV(File, true, CSVFormat.English);
                csv.DateFormat = "yyyy.MM.dd HH:mm:ss";

                DateTime ParsedDate = from;


                //  Time,Open,High,Low,Close,Volume
                while (csv.Next() && ParsedDate >= from && ParsedDate <= to  )
                {
                    DateTime date = csv.GetDate("Time");
                    double Bid= csv.GetDouble("Bid");
                    double Ask = csv.GetDouble("Ask");
                    double AskVolume = csv.GetDouble("AskVolume");
                    double BidVolume= csv.GetDouble("BidVolume");
                    double _trade = ( Bid + Ask ) /2;
                    double _tradeSize = (AskVolume + BidVolume) / 2;
                    LoadedMarketData data = new LoadedMarketData(date, symbol);
                    data.SetData(MarketDataType.Trade, _trade);
                    data.SetData(MarketDataType.Volume, _tradeSize);
                    result.Add(data);

                    Console.WriteLine("Current DateTime:"+ParsedDate.ToShortDateString()+ " Time:"+ParsedDate.ToShortTimeString() +"  Start date was "+from.ToShortDateString());
                    Console.WriteLine("Stopping at date:" + to.ToShortDateString() );
                    ParsedDate = date;
                    //double open = csv.GetDouble("Open");
                    //double close = csv.GetDouble("High");
                    //double high = csv.GetDouble("Low");
                    //double low = csv.GetDouble("Close");
                    //double volume = csv.GetDouble("Volume");
                    //LoadedMarketData data = new LoadedMarketData(date, symbol);
                    //data.SetData(MarketDataType.Open, open);
                    //data.SetData(MarketDataType.High, high);
                    //data.SetData(MarketDataType.Low, low);
                    //data.SetData(MarketDataType.Close, close);
                    //data.SetData(MarketDataType.Volume, volume);
                    result.Add(data);
                }

                csv.Close();
                return result;
            }

            catch (Exception ex)
            {

                Console.WriteLine("Something went wrong reading the csv");
                Console.WriteLine("Something went wrong reading the csv:" + ex.Message);
            }

            Console.WriteLine("Something went wrong reading the csv");
            return null;
        }
开发者ID:JDFagan,项目名称:encog-dotnet-core,代码行数:58,代码来源:csvfileloader.cs

示例6: LoadedRow

 /// <summary>
 /// Construct a loaded row.
 /// </summary>
 ///
 /// <param name="csv">The CSV file to use.</param>
 /// <param name="extra">The number of extra columns to add.</param>
 public LoadedRow(ReadCSV csv, int extra)
 {
     int count = csv.GetCount();
     _data = new String[count + extra];
     for (int i = 0; i < count; i++)
     {
         _data[i] = csv.Get(i);
     }
 }
开发者ID:firestrand,项目名称:encog-dotnet-core,代码行数:15,代码来源:LoadedRow.cs

示例7: QuickParseCSV

 /// <summary>
 /// parses one column of a csv and returns an array of doubles.
 /// you can only return one double array with this method.
 /// </summary>
 /// <param name="file">The file.</param>
 /// <param name="formatused">The formatused.</param>
 /// <param name="Name">The name of the column to parse..</param>
 /// <returns></returns>
 public static List<double> QuickParseCSV(string file, CSVFormat formatused, string Name)
 {
     List<double> returnedArrays = new List<double>();
     ReadCSV csv = new ReadCSV(file, true, formatused);
     while (csv.Next())
     {
         returnedArrays.Add(csv.GetDouble(Name));
     }
     return returnedArrays;
 }
开发者ID:Romiko,项目名称:encog-dotnet-core,代码行数:18,代码来源:QuickCSVUtils.cs

示例8: LoadTrainingData

        public void LoadTrainingData(string trainingDataPath, ProblemType problem, ActivationType activation)
        {
            TrainingDataPath = trainingDataPath;

            var csvReader = new ReadCSV(trainingDataPath, true, CSVFormat.DecimalPoint);

            var values = new List<double[]>();
            var answers = new List<double[]>();

            while (csvReader.Next())
            {
                if (ProblemType.Classification == problem)
                {
                    values.Add(new []{csvReader.GetDouble(0), csvReader.GetDouble(1)});
                    answers.Add(new []{csvReader.GetDouble(2)});
                }
                else
                {
                    values.Add(new[] { csvReader.GetDouble(0)});
                    answers.Add(new[] { csvReader.GetDouble(1) });

                    _originalRegressionValues.Add(values.Last()[0]);
                    _originalRegressionAnswers.Add(answers.Last()[0]);
                }
            }

            csvReader.Close();

            if (problem == ProblemType.Classification)
            {
                answers = SpreadClassificationAnswers(answers, activation);
                FirstLayerSize = 2;
            }
            else
                LastLayerSize = FirstLayerSize = 1;

            AnalizeValues(problem, values);
            Normalize(values, _valuesMins, _valuesMaxes, activation);

            if (problem == ProblemType.Regression)
            {
                AnalizeAnswers(answers);
                Normalize(answers, _answersMins, _answersMaxes, activation);
            }

            values.StableShuffle();
            answers.StableShuffle();
            ListExtensions.ResetStableShuffle();

            var trainingSetSize = (int)(values.Count * 0.85);

            TrainingDataSet = new BasicMLDataSet(values.Take(trainingSetSize).ToArray(), answers.Take(trainingSetSize).ToArray());
            ValidationDataSet = new BasicMLDataSet(values.Skip(trainingSetSize).ToArray(), answers.Skip(trainingSetSize).ToArray());
        }
开发者ID:wazka,项目名称:SN_ProjectOne,代码行数:54,代码来源:ProblemData.cs

示例9: GenerateFields

 /// <summary>
 ///     Generate the header fields.
 /// </summary>
 /// <param name="csv">The CSV file to use.</param>
 private void GenerateFields(ReadCSV csv)
 {
     if (_headers)
     {
         GenerateFieldsFromHeaders(csv);
     }
     else
     {
         GenerateFieldsFromCount(csv);
     }
 }
开发者ID:jongh0,项目名称:MTree,代码行数:15,代码来源:PerformAnalysis.cs

示例10: QuickParseCSV

 /// <summary>
 /// parses one column of a csv and returns an array of doubles.
 /// you can only return one double array with this method.
 /// We are assuming CSVFormat english in this quick parse csv method.
 /// You can input the size (number of lines) to read.
 /// </summary>
 /// <param name="file">The file.</param>
 /// <param name="Name">The name of the column to parse.</param>
 /// <param name="size">The size.</param>
 /// <returns></returns>
 public static List<double> QuickParseCSV(string file, string Name, int size)
 {
     List<double> returnedArrays = new List<double>();
     ReadCSV csv = new ReadCSV(file, true, CSVFormat.English);
     int currentRead = 0;
     while (csv.Next() && currentRead < size)
     {
         returnedArrays.Add(csv.GetDouble(Name));
         currentRead++;
     }
     return returnedArrays;
 }
开发者ID:JDFagan,项目名称:encog-dotnet-core,代码行数:22,代码来源:QuickCSVUtils.cs

示例11: LoadedRow

 public LoadedRow(ReadCSV csv, int extra)
 {
     int count;
     int num2;
     if ((((uint) num2) + ((uint) count)) >= 0)
     {
     }
     count = csv.GetCount();
     this._x4a3f0a05c02f235f = new string[count + extra];
     for (num2 = 0; num2 < count; num2++)
     {
         this._x4a3f0a05c02f235f[num2] = csv.Get(num2);
     }
 }
开发者ID:neismit,项目名称:emds,代码行数:14,代码来源:LoadedRow.cs

示例12: ReadAndCallLoader

        public ICollection<LoadedMarketData> ReadAndCallLoader(TickerSymbol symbol, IList<MarketDataType> neededTypes, DateTime from, DateTime to,string File)
        {
            try
            {


                        //We got a file, lets load it.

                    

                        ICollection<LoadedMarketData> result = new List<LoadedMarketData>();
                        ReadCSV csv = new ReadCSV(File, true,LoadedFormat);


                        csv.DateFormat = DateTimeFormat.Normalize();
                        //  Time,Open,High,Low,Close,Volume
                        while (csv.Next())
                        {
                            DateTime date = csv.GetDate("Time");
                            double open = csv.GetDouble("Open");
                            double close = csv.GetDouble("High");
                            double high = csv.GetDouble("Low");
                            double low = csv.GetDouble("Close");
                            double volume = csv.GetDouble("Volume");
                            LoadedMarketData data = new LoadedMarketData(date, symbol);
                            data.SetData(MarketDataType.Open, open);
                            data.SetData(MarketDataType.High, high);
                            data.SetData(MarketDataType.Low, low);
                            data.SetData(MarketDataType.Close, close);
                            data.SetData(MarketDataType.Volume, volume);
                            result.Add(data);
                        }

                        csv.Close();
                        return result;                 
                }
            
            catch (Exception ex)
            {
                
              Console.WriteLine("Something went wrong reading the csv");
              Console.WriteLine("Something went wrong reading the csv:"+ex.Message);
            }

            Console.WriteLine("Something went wrong reading the csv");
            return null;
        }
开发者ID:jongh0,项目名称:MTree,代码行数:47,代码来源:csvloader.cs

示例13: Process

 public void Process(FileInfo outputFile)
 {
     base.ValidateAnalyzed();
     ReadCSV dcsv = new ReadCSV(base.InputFilename.ToString(), base.ExpectInputHeaders, base.InputFormat);
     if (0 == 0)
     {
         LoadedRow row;
         StreamWriter tw = base.PrepareOutputFile(outputFile);
         base.ResetStatus();
         while ((row = this.x75f8dae9674cb841(dcsv)) != null)
         {
             base.WriteRow(tw, row);
             base.UpdateStatus(false);
         }
         base.ReportDone(false);
         tw.Close();
     }
     dcsv.Close();
 }
开发者ID:neismit,项目名称:emds,代码行数:19,代码来源:ShuffleCSV.cs

示例14: Load

        /// <summary>
        /// Load financial data from a CSV file.
        /// </summary>
        /// <param name="ticker">The ticker being loaded, ignored for a CSV load.</param>
        /// <param name="dataNeeded">The data needed.</param>
        /// <param name="from">The starting date.</param>
        /// <param name="to">The ending date.</param>
        /// <returns></returns>
        public ICollection<LoadedMarketData> Load(TickerSymbol ticker, IList<MarketDataType> dataNeeded, DateTime from,
                                                  DateTime to)
        {
            try
            {
                if (File.Exists(TheFile))
                {
                    //We got a file, lets load it.
                    TheFile = TheFile;
                    ICollection<LoadedMarketData> result = new List<LoadedMarketData>();
                    var csv = new ReadCSV(TheFile, true, CSVFormat.English);

                    //  Time,Open,High,Low,Close,Volume
                    while (csv.Next())
                    {
                        DateTime date = csv.GetDate("Time");
                        double open = csv.GetDouble("Open");
                        double close = csv.GetDouble("High");
                        double high = csv.GetDouble("Low");
                        double low = csv.GetDouble("Close");
                        double volume = csv.GetDouble("Volume");
                        var data = new LoadedMarketData(date, ticker);
                        data.SetData(MarketDataType.Open, open);
                        data.SetData(MarketDataType.Volume, close);
                        data.SetData(MarketDataType.High, high);
                        data.SetData(MarketDataType.Low, low);
                        data.SetData(MarketDataType.Volume, volume);
                        result.Add(data);
                    }

                    csv.Close();
                    return result;
                }
            }
            catch (Exception ex)
            {
                throw new LoaderError(ex);
            }

            throw new LoaderError(@"Something went wrong reading the csv");
        }
开发者ID:JDFagan,项目名称:encog-dotnet-core,代码行数:49,代码来源:CSVTicksLoader.cs

示例15: Analyze

        /// <summary>
        ///     Analyze the data. This counts the records and prepares the data to be
        ///     processed.
        /// </summary>
        /// <param name="theAnalyst">The analyst to use.</param>
        /// <param name="inputFile">The input file to analyze.</param>
        /// <param name="headers">True, if the input file has headers.</param>
        /// <param name="format">The format of the input file.</param>
        public void Analyze(EncogAnalyst theAnalyst,
                            FileInfo inputFile, bool headers, CSVFormat format)
        {
            InputFilename = inputFile;
            ExpectInputHeaders = headers;
            Format = format;

            Analyzed = true;
            _analyst = theAnalyst;

            _data = new BasicMLDataSet();
            ResetStatus();
            int recordCount = 0;

            int outputLength = _analyst.DetermineTotalColumns();
            var csv = new ReadCSV(InputFilename.ToString(),
                                  ExpectInputHeaders, Format);
            ReadHeaders(csv);

            _analystHeaders = new CSVHeaders(InputHeadings);

            while (csv.Next() && !ShouldStop())
            {
                UpdateStatus(true);

                double[] inputArray = AnalystNormalizeCSV.ExtractFields(
                    _analyst, _analystHeaders, csv, outputLength, true);

                IMLData input = new BasicMLData(inputArray);
                _data.Add(new BasicMLDataPair(input));

                recordCount++;
            }
            RecordCount = recordCount;
            Count = csv.ColumnCount;

            ReadHeaders(csv);
            csv.Close();
            ReportDone(true);
        }
开发者ID:jongh0,项目名称:MTree,代码行数:48,代码来源:AnalystClusterCSV.cs


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