本文整理汇总了C#中Encog.Util.CSV.ReadCSV.Next方法的典型用法代码示例。如果您正苦于以下问题:C# ReadCSV.Next方法的具体用法?C# ReadCSV.Next怎么用?C# ReadCSV.Next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Encog.Util.CSV.ReadCSV
的用法示例。
在下文中一共展示了ReadCSV.Next方法的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));
}
}
示例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;
}
示例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();
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例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.
/// 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;
}
示例8: 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;
}
示例9: 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");
}
示例10: Load
/// <summary>
/// Load financial data from Google.
/// </summary>
/// <param name="ticker">The ticker to load from.</param>
/// <param name="dataNeeded">The data needed.</param>
/// <param name="from">The starting time.</param>
/// <param name="to">The ending time.</param>
/// <returns>The loaded data.</returns>
public ICollection<LoadedMarketData> Load(TickerSymbol ticker, IList<MarketDataType> dataNeeded, DateTime from,
DateTime to)
{
ICollection<LoadedMarketData> result = new List<LoadedMarketData>();
Uri url = BuildUrl(ticker, from, to);
WebRequest http = WebRequest.Create(url);
var response = (HttpWebResponse) http.GetResponse();
if (response != null)
using (Stream istream = response.GetResponseStream())
{
var csv = new ReadCSV(istream, true, CSVFormat.DecimalPoint);
while (csv.Next())
{
DateTime date = csv.GetDate("date");
double open = csv.GetDouble("open");
double close = csv.GetDouble("close");
double high = csv.GetDouble("high");
double low = csv.GetDouble("low");
double volume = csv.GetDouble("volume");
var data =
new LoadedMarketData(date, ticker);
data.SetData(MarketDataType.Open, open);
data.SetData(MarketDataType.Close, close);
data.SetData(MarketDataType.High, high);
data.SetData(MarketDataType.Low, low);
data.SetData(MarketDataType.Open, open);
data.SetData(MarketDataType.Volume, volume);
result.Add(data);
}
csv.Close();
if (istream != null) istream.Close();
}
return result;
}
示例11: CSVHeaders
/// <summary>
/// Construct the object.
/// </summary>
///
/// <param name="filename">The filename.</param>
/// <param name="headers">False if headers are not extended.</param>
/// <param name="format">The CSV format.</param>
public CSVHeaders(FileInfo filename, bool headers,
CSVFormat format)
{
_headerList = new List<String>();
_columnMapping = new Dictionary<String, Int32>();
ReadCSV csv = null;
try
{
csv = new ReadCSV(filename.ToString(), headers, format);
if (csv.Next())
{
if (headers)
{
foreach (String str in csv.ColumnNames)
{
_headerList.Add(str);
}
}
else
{
for (int i = 0; i < csv.ColumnCount; i++)
{
_headerList.Add("field:" + (i + 1));
}
}
}
Init();
}
finally
{
if (csv != null)
{
csv.Close();
}
}
}
示例12: CalibrateFile
/// <summary>
/// Used to calibrate the training file.
/// </summary>
/// <param name="file">The file to consider.</param>
protected void CalibrateFile(string file)
{
var csv = new ReadCSV(file, true, CSVFormat.English);
while (csv.Next())
{
var a = new double[1];
double close = csv.GetDouble(1);
const int fastIndex = 2;
const int slowIndex = fastIndex + Config.InputWindow;
a[0] = close;
for (int i = 0; i < Config.InputWindow; i++)
{
double fast = csv.GetDouble(fastIndex + i);
double slow = csv.GetDouble(slowIndex + i);
if (!double.IsNaN(fast) && !double.IsNaN(slow))
{
double diff = (fast - slow)/Config.PipSize;
_minDifference = Math.Min(_minDifference, diff);
_maxDifference = Math.Max(_maxDifference, diff);
}
}
_window.Add(a);
if (_window.IsFull())
{
double max = (_window.CalculateMax(0, Config.InputWindow) - close)/Config.PipSize;
double min = (_window.CalculateMin(0, Config.InputWindow) - close)/Config.PipSize;
double o = Math.Abs(max) > Math.Abs(min) ? max : min;
_maxPiPs = Math.Max(_maxPiPs, (int) o);
_minPiPs = Math.Min(_minPiPs, (int) o);
}
}
}
示例13: Process
/// <summary>
/// Process and balance the data.
/// </summary>
/// <param name="outputFile">The output file to write data to.</param>
/// <param name="targetField"></param>
/// <param name="countPer">The desired count per class.</param>
public void Process(FileInfo outputFile, int targetField,
int countPer)
{
ValidateAnalyzed();
StreamWriter tw = PrepareOutputFile(outputFile);
_counts = new Dictionary<String, Int32>();
var csv = new ReadCSV(InputFilename.ToString(),
ExpectInputHeaders, Format);
ResetStatus();
while (csv.Next() && !ShouldStop())
{
var row = new LoadedRow(csv);
UpdateStatus(false);
String key = row.Data[targetField];
int count;
if (!_counts.ContainsKey(key))
{
count = 0;
}
else
{
count = _counts[key];
}
if (count < countPer)
{
WriteRow(tw, row);
count++;
}
_counts[key] = count;
}
ReportDone(false);
csv.Close();
tw.Close();
}
示例14: LoadBuffer
/// <summary>
/// Load the buffer from the underlying file.
/// </summary>
///
/// <param name="csv">The CSV file to load from.</param>
private void LoadBuffer(ReadCSV csv)
{
for (int i = 0; i < _buffer.Length; i++)
{
_buffer[i] = null;
}
int index = 0;
while (csv.Next() && (index < _bufferSize) && !ShouldStop())
{
var row = new LoadedRow(csv);
_buffer[index++] = row;
}
_remaining = index;
}
示例15: Execute
/// <summary>
/// Program entry point.
/// </summary>
/// <param name="app">Holds arguments and other info.</param>
public void Execute(IExampleInterface app)
{
// Download the data that we will attempt to model.
string filename = DownloadData(app.Args);
// Define the format of the data file.
// This area will change, depending on the columns and
// format of the file that you are trying to model.
var format = new CSVFormat('.', ' '); // decimal point and space separated
IVersatileDataSource source = new CSVDataSource(filename, false, format);
var data = new VersatileMLDataSet(source);
data.NormHelper.Format = format;
ColumnDefinition columnMPG = data.DefineSourceColumn("mpg", 0, ColumnType.Continuous);
ColumnDefinition columnCylinders = data.DefineSourceColumn("cylinders", 1, ColumnType.Ordinal);
// It is very important to predefine ordinals, so that the order is known.
columnCylinders.DefineClass(new[] {"3", "4", "5", "6", "8"});
data.DefineSourceColumn("displacement", 2, ColumnType.Continuous);
ColumnDefinition columnHorsePower = data.DefineSourceColumn("horsepower", 3, ColumnType.Continuous);
data.DefineSourceColumn("weight", 4, ColumnType.Continuous);
data.DefineSourceColumn("acceleration", 5, ColumnType.Continuous);
ColumnDefinition columnModelYear = data.DefineSourceColumn("model_year", 6, ColumnType.Ordinal);
columnModelYear.DefineClass(new[]
{"70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82"});
data.DefineSourceColumn("origin", 7, ColumnType.Nominal);
// Define how missing values are represented.
data.NormHelper.DefineUnknownValue("?");
data.NormHelper.DefineMissingHandler(columnHorsePower, new MeanMissingHandler());
// Analyze the data, determine the min/max/mean/sd of every column.
data.Analyze();
// Map the prediction column to the output of the model, and all
// other columns to the input.
data.DefineSingleOutputOthersInput(columnMPG);
// Create feedforward neural network as the model type. MLMethodFactory.TYPE_FEEDFORWARD.
// You could also other model types, such as:
// MLMethodFactory.SVM: Support Vector Machine (SVM)
// MLMethodFactory.TYPE_RBFNETWORK: RBF Neural Network
// MLMethodFactor.TYPE_NEAT: NEAT Neural Network
// MLMethodFactor.TYPE_PNN: Probabilistic Neural Network
var model = new EncogModel(data);
model.SelectMethod(data, MLMethodFactory.TypeFeedforward);
// Send any output to the console.
model.Report = new ConsoleStatusReportable();
// Now normalize the data. Encog will automatically determine the correct normalization
// type based on the model you chose in the last step.
data.Normalize();
// Hold back some data for a final validation.
// Shuffle the data into a random ordering.
// Use a seed of 1001 so that we always use the same holdback and will get more consistent results.
model.HoldBackValidation(0.3, true, 1001);
// Choose whatever is the default training type for this model.
model.SelectTrainingType(data);
// Use a 5-fold cross-validated train. Return the best method found.
var bestMethod = (IMLRegression) model.Crossvalidate(5, true);
// Display the training and validation errors.
Console.WriteLine(@"Training error: " + model.CalculateError(bestMethod, model.TrainingDataset));
Console.WriteLine(@"Validation error: " + model.CalculateError(bestMethod, model.ValidationDataset));
// Display our normalization parameters.
NormalizationHelper helper = data.NormHelper;
Console.WriteLine(helper.ToString());
// Display the final model.
Console.WriteLine("Final model: " + bestMethod);
// Loop over the entire, original, dataset and feed it through the model.
// This also shows how you would process new data, that was not part of your
// training set. You do not need to retrain, simply use the NormalizationHelper
// class. After you train, you can save the NormalizationHelper to later
// normalize and denormalize your data.
source.Close();
var csv = new ReadCSV(filename, false, format);
var line = new String[7];
IMLData input = helper.AllocateInputVector();
while (csv.Next())
{
var result = new StringBuilder();
line[0] = csv.Get(1);
line[1] = csv.Get(2);
line[2] = csv.Get(3);
line[3] = csv.Get(4);
line[4] = csv.Get(5);
line[5] = csv.Get(6);
//.........这里部分代码省略.........