Brain.js GPU慢速训练

时间:2019-12-15 18:08:03

标签: javascript neural-network brain.js

我正在尝试使用brain.js训练神经网络-但想知道我的数据是否已经太大了?

代码:

let resultBought = {}
let resultSold = {}

for (var i = 0; i < tradesTotal; i++) {

symbol = trades[i].fields.orderSymbol
// returns e.g. EUR/USD

symbolBase = symbol.slice(0, 3)
// returns e.g. EUR

symbolCounter = symbol.slice(3, 6)
// returns e.g. USD

lots = trades[i].fields.orderLots
// returns e.g. 1.00

orderType = trades[i].fields.orderType
// orderTypes 0, 2, 4 are long trades, 1, 3, 5 shorts accordingly

// check for major pairs where XXX/YYY = defined currencies
if (symbolBase.match(/^(EUR|GBP|AUD|CHF|JPY|USD|CAD)$/) && symbolCounter.match(/^(EUR|GBP|AUD|CHF|JPY|USD|CAD)$/)) {
    // Long Trades Major Pairs
    if (orderType == '0' || orderType == '2' || orderType == '4') {

        // Base currency
        if(resultBought.hasOwnProperty(symbolBase + 'VolumeBought')) {
            resultBought[symbolBase + 'VolumeBought'] += lots * 100.000
        }
        else {
            resultBought[symbolBase + 'VolumeBought'] = lots * 100.000
        }
        // Counter currency
        if(resultSold.hasOwnProperty(symbolCounter + 'VolumeSold')) {
            resultSold[symbolCounter + 'VolumeSold'] += lots * 100.000
        }
        else {
            resultSold[symbolCounter + 'VolumeSold'] = lots * 100.000
        }

    // Short Trades Major Pairs
    } else if (orderType == '1' || orderType == '3' || orderType == '5') {

        // Base currency
        if(resultSold.hasOwnProperty(symbolBase + 'VolumeSold')) {
            resultSold[symbolBase + 'VolumeSold'] += lots * 100.000
        }
        else {
            resultSold[symbolBase + 'VolumeSold'] = lots * 100.000
        }

        // Counter currency
        if(resultBought.hasOwnProperty(symbolCounter + 'VolumeBought')) {
            resultBought[symbolCounter + 'VolumeBought'] += lots * 100.000
        }
        else {
            resultBought[symbolCounter + 'VolumeBought'] = lots * 100.000
        }
      }
// consider the non major pairs
} else if (symbolBase.match(/^(EUR|GBP|AUD|CHF|JPY|USD|CAD)$/) || symbolCounter.match(/^(EUR|GBP|AUD|CHF|JPY|USD|CAD)$/)) {
    if (orderType == '0' || orderType == '2' || orderType == '4') {

        if(resultBought.hasOwnProperty(symbolBase + 'VolumeBought')) {
            resultBought[symbolBase + 'VolumeBought'] += lots * 100.000
        }
        else {
            resultBought[symbolBase + 'VolumeBought'] = lots * 100.000
        }

    } else if (orderType == '1' || orderType == '3' || orderType == '5') {

        if(resultSold.hasOwnProperty(symbolBase + 'VolumeSold')) {
            resultSold[symbolBase + 'VolumeSold'] += lots * 100.000
        }
        else {
            resultSold[symbolBase + 'VolumeSold'] = lots * 100.000
        }
      }
  }
}

尝试使用Amazon GPU实例-但速度慢。需要100小时的训练时间。

功能:

await getDataSet(type);

  const listings  = await getFilteredListings(type);
  const normalizer = new Normalizer(listings);

  normalizer.setOutputProperties(['runningTime']);
  normalizer.normalize();

  const inputs = normalizer.getBinaryInputDataset();
  const outputs = normalizer.getBinaryOutputDataset();
  const metadata = normalizer.getDatasetMetaData();

  fs.writeFileSync(METADATA_FILE[type],JSON.stringify(metadata));

  const trainingData=[];
  for(let i=0;i<inputs.length;i++){
    trainingData.push({input:inputs[i],output:outputs[i]});
  }
  const options={
    hiddenLayers:[180,60],
  };

  const net = new NeuralNetworkGPU(
    options
  );

  net.train(trainingData,{
    iterations: 60000, // the maximum times to iterate the training data --> number greater than 0
    errorThresh: 0.001, // the acceptable error percentage from training data --> number between 0 and 1
    log:true,
  });

如您所见,我有13个功能-大约有50k训练数据。 为什么要花这么长时间?减少隐藏网络中的单位会加快训练速度,但随后网络将无法理解数据。

0 个答案:

没有答案