如何在Encog中规范化非CSV数据

时间:2015-03-28 18:48:13

标签: c# neural-network normalization normalize encog

所以我使用Jeff Heaton的神经网络库。

在尝试解决Iris植物分类问题时,我遇到了数据规范化问题。

我可以使用以下方法规范化CSV文件:

public void NormalizeFile(FileInfo SourceDataFile, FileInfo NormalizedDataFile, FileInfo NormalizationConfigFile)
    {

        var wizard = new AnalystWizard(_analyst);
        wizard.Wizard(SourceDataFile, _useHeaders, AnalystFileFormat.DecpntComma);
        var norm = new AnalystNormalizeCSV();
        norm.Analyze(SourceDataFile, _useHeaders, CSVFormat.English, _analyst);
        norm.ProduceOutputHeaders = _useHeaders;
        norm.Normalize(NormalizedDataFile);

        // save normalization configuration, which can be used later to denormalize to get the raw output.
        _analyst.Save(NormalizationConfigFile);

    }

到目前为止一切都很好......该计划的准确性很高。

当我想在控制台应用程序中输入值时,会出现问题。

我有一些输入数据

  • 萼片宽度
  • 萼片长度
  • 花瓣宽度
  • 花瓣长度

这些值中的每一个都有不同的高/低我想将这些值标准化,以便我可以将它们提供到我的网络而无需将CSV文件写入磁盘。

2 个答案:

答案 0 :(得分:1)

根据此link,您可以使用Encog.Util.Arrayutil.NormalizeArray轻松完成此操作:

我假设您的数据存储在double[]

Encog.Util.Arrayutil.NormalizeArray normalizer = new Encog.Util.Arrayutil.NormalizeArray();
var normalizedData = normalizer.Process(dataMatrix, 0, 1);//(yourdata, low, high)

答案 1 :(得分:0)

I later realised that what I really needed as an analyser that would all me to automatically normalise a mixture of qualitative (nominal) and quantitive data (just like the CSV implementation).

The problem was that the existing code was tightly coupled to CSV files. To combat this I wrote my own encog extension method library.

it can be found here: https://github.com/KiransHub/encog-dotnet-core

Here's an example of it in action:

    public void NormalizeDataExample()
    {
        List<LoadedMarketData> AppleMarketData = GetMarketData("AAPL");
        List<LoadedMarketData> MicrosoftMarketData = GetMarketData("MSFT");
        List<LoadedMarketData> YahootMarketData = GetMarketData("YHOO");

        List<LoadedMarketData> MarketData = new List<LoadedMarketData>();
        MarketData.AddRange(AppleMarketData);
        MarketData.AddRange(MicrosoftMarketData);
        MarketData.AddRange(YahootMarketData);

        DataSet dataSet = new DataSet().Convert(MarketData, "Market DataSet");
        var analyst = new EncogAnalyst();
        var wizard = new AnalystWizard(analyst);
        wizard.Wizard(dataSet);

        var normalizer = new AnalystNormalizeDataSet(analyst);
        var normalizedData = normalizer.Normalize(dataSet);


    }