|
Trying to reproduce deep learning algo
#458984
04/11/16 23:22
04/11/16 23:22
|
Joined: Apr 2016
Posts: 3
Gruber
OP
Guest
|
OP
Guest
Joined: Apr 2016
Posts: 3
|
Hey guys, I'm trying to reproduce the Deep learning algo that JCL used to calculate the probability of the AI getting the next candle right with the 60 minutes time frame. From what I've gathered and understood, it looks like this: #include <r.h> void main(int mode, int model, int numSignals, void* Data) { if(!wait(0)) return 0; // open an R script with the same name as the stratefy script if(mode == NEURAL_INIT) { if(!Rstart(strf("%s.r",Script),2)) return 0; Rx("neural.init()"); return 1; } // export batch training samples and call the R training function if(mode == NEURAL_TRAIN) { string name = strf("Data\\signals%i.csv",Core); file_write(name,Data,0); Rx(strf("XY <- read.csv('%s%s',header = F)",slash(ZorroFolder),slash(name))); Rset("AlgoVar",AlgoVar,8); if(!Rx(strf("neural.train(%i,XY)",model+1),2)) return 0; return 1; } // predict the target with the R predict function if(mode == NEURAL_PREDICT) { Rset("AlgoVar",AlgoVar,8); Rset("X",(double*)Data,numSignals); Rx(strf("Y <- neural.predict(%i,X)",model+1)); return Rd("Y[1]"); } // save all trained models if(mode == NEURAL_SAVE) { print(TO_ANY,"\nStore %s",strrchr(Data,'\\')+1); return Rx(strf("neural.save('%s')",slash(Data)),2); } // load all trained models if(mode == NEURAL_LOAD) { printf("\nLoad %s",strrchr(Data,'\\')+1); return Rx(strf("load('%s')",slash(Data)),2); } return 1; }
and library('deepnet', quietly = T) library('caret', quietly = T)
# called by Zorro for training neural.train = function(model,XY) { XY <- as.matrix(XY) X <- XY[,-ncol(XY)] # predictors Y <- XY[,ncol(XY)] # target Y <- ifelse(Y > 0,1,0) # convert -1..1 to 0..1 Models[[model]] <<- sae.dnn.train(X,Y, hidden = c(20,20,20), activationfun = "tanh", learningrate = 0.5, momentum = 0.5, learningrate_scale = 1.0, output = "sigm", sae_output = "linear", numepochs = 100, batchsize = 100, hidden_dropout = 0, visible_dropout = 0) }
# called by Zorro for prediction neural.predict = function(model,X) { if(is.vector(X)) X <- t(X) # transpose horizontal vector return(nn.predict(Models[[model]],X)) }
# called by Zorro for saving the models neural.save = function(name) { save(Models,file=name) # save trained models }
# called by Zorro for initialization neural.init = function() { set.seed(365) Models <<- vector("list") }
# quick OOS test for experimenting with the settings Test = function() { neural.init() XY <<- read.csv('C:/Project/Zorro/Data/signals0.csv',header = F) splits <- nrow(XY)*0.8 XY.tr <<- head(XY,splits) # training set XY.ts <<- tail(XY,-splits) # test set neural.train(1,XY.tr) X <<- XY.ts[,-ncol(XY.ts)] Y <<- XY.ts[,ncol(XY.ts)] Y.ob <<- ifelse(Y > 0,1,0) Y <<- neural.predict(1,X) Y.pr <<- ifelse(Y > 0.5,1,0) confusionMatrix(Y.pr,Y.ob) # display prediction accuracy }
But I don't seem to understand how they interact with each other and how they're supposed to get data from the software itself, does anyony have some recommendation on how to do that?
|
|
|
Re: Trying to reproduce deep learning algo
[Re: Gruber]
#458985
04/12/16 02:53
04/12/16 02:53
|
Joined: Apr 2014
Posts: 482 Sydney, Australia
boatman
Senior Member
|
Senior Member
Joined: Apr 2014
Posts: 482
Sydney, Australia
|
You need to use an advise() function within the run() function. For example,
var Prediction = adviseLong(NEURAL, Objective, Signal_1, Signal_2.....);
Where "Objective" is the target value you are trying to predict (in this case, positive or negative next-bar return designated as +1 and -1 respectively) and "Signal_1, Signal_2, ... etc" are the variables (otherwise known as features, predictors, independent variables etc) that you are using to forecast "Objective". In terms of the way the script flows, the advise function calls the NEURAL function (the first function in your post). The NEURAL function then calls the R script (the second function in your post). Does that help?
|
|
|
Re: Trying to reproduce deep learning algo
[Re: boatman]
#458986
04/12/16 03:16
04/12/16 03:16
|
Joined: Apr 2016
Posts: 3
Gruber
OP
Guest
|
OP
Guest
Joined: Apr 2016
Posts: 3
|
You need to use an advise() function within the run() function. For example,
var Prediction = adviseLong(NEURAL, Objective, Signal_1, Signal_2.....);
Where "Objective" is the target value you are trying to predict (in this case, positive or negative next-bar return designated as +1 and -1 respectively) and "Signal_1, Signal_2, ... etc" are the variables (otherwise known as features, predictors, independent variables etc) that you are using to forecast "Objective". In terms of the way the script flows, the advise function calls the NEURAL function (the first function in your post). The NEURAL function then calls the R script (the second function in your post). Does that help? I understand how that applies to common machine learning AI's, but I thought deep learning didn't need introductory features. And I also don't know how to take data from the series, as stated in this algo: #include <r.h>
function run() { BarPeriod = 60; WFOPeriod = 20*24; // 4 weeks StartDate = 2010; LookBack = 100; set(RULES); Cores = 4; // train parallel with 4 R instances
// generate 10 signals for prediction... var Sig[10]; Sig[0] = ... ... Detrend = TRADES; ExitTime = 5; // 4 hours prediction horizon var PredictLong = adviseLong(NEURAL+BALANCED,0, // predict next trade outcome Sig[0],Sig[1],Sig[2],Sig[3],Sig[4],Sig[5],Sig[6],Sig[7],Sig[8],Sig[9]); if(Train) enterLong(); // enter always a trade in training mode var PredictShort = adviseShort(); if(Train) enterShort(); if(!Train) { if(PredictLong > 0.6 && PredictShort < 0.4) enterLong; else if(PredictLong < 0.4 && PredictShort > 0.6) enterShort; } } I feel kinda dumb having to ask that, but I really don't how they interact with each other. Btw I love your blog.
Last edited by Gruber; 04/12/16 03:28.
|
|
|
|