Skip to content

Commit

Permalink
Dziala makePrediction na 1 time-slice, podpinam pairwiseFactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kudkudak committed May 19, 2013
1 parent b0a1527 commit 4656ca0
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 54,049 deletions.
Binary file modified server-predictor-tests/server-predictor-tests.v11.suo
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ public void init()
Logger.Instance.log("Error initializing R.NET engine");
throw (e);
}
Logger.Instance.log("Correctly initialized R.NET engine");
}
Logger.Instance.log("Correctly initialized R.NET engine");
engine.Evaluate("source('general.r')");

}
ArrayList pairwiseFactors;
private string p;
Expand All @@ -63,8 +65,6 @@ public void initPairwiseCalculation(string data_file_name)
catch (Exception e)
{
}


}


Expand Down
163 changes: 106 additions & 57 deletions server-predictor-tests/server-predictor-tests/Program.cs

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions server-predictor-tests/server-predictor-tests/SingularModelR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public static REngine engine
get;
set;
}//engine to R
private string m_trained_model_file; //saved trained model
private string m_trained_model_file; //sed trained model
private string m_traffic_test_file;
private string m_source_file;
private string m_alg_name;
private int m_ahead;
Expand All @@ -36,6 +37,7 @@ public SingularModelR(string source_file = "model0b.r", string alg_name = "model
m_source_file = source_file; m_alg_name = alg_name;
m_trained_model_file = "data/" + m_name + ".trained_model.RDa"; //setting up used file paths
m_predict_var_name = "predict_options_" + m_name;
m_traffic_test_file = "data/traffic_test." + m_name + ".txt";


isTrained = false;
Expand Down Expand Up @@ -66,8 +68,9 @@ public void init(int look_behind = 30, int link_count = 20,
Logger.Instance.log("Error initializing R.NET engine");
throw (e);
}
Logger.Instance.log("Correctly initialized R.NET engine");
}
Logger.Instance.log("Correctly initialized R.NET engine");


try
{
Expand All @@ -83,11 +86,16 @@ public void init(int look_behind = 30, int link_count = 20,

SingularModelR.engine.Evaluate(m_predict_var_name + "= " + m_alg_name + ".getDefaultPredictOptions()");

SingularModelR.engine.Evaluate(m_predict_var_name+"= " + look_behind.ToString());
SingularModelR.engine.Evaluate(m_predict_var_name+"$look_behind= " + look_behind.ToString());
SingularModelR.engine.Evaluate(m_predict_var_name+"$link_count= " + link_count.ToString());
SingularModelR.engine.Evaluate(m_predict_var_name + "$look_behind_prediction= " + look_behind_prediction.ToString());
SingularModelR.engine.Evaluate(m_predict_var_name + "$look_behind_prediction_self= " + look_behind_prediction_self.ToString());
SingularModelR.engine.Evaluate(m_predict_var_name + "$ahead= " + ahead.ToString());
SingularModelR.engine.Evaluate(m_predict_var_name + "$name=\"" + m_name.ToString()+"\"");
SingularModelR.engine.Evaluate("model0b.prepareDependList(file_name=\""
+ m_traffic_test_file +
"\",predict_options=" + m_predict_var_name+")");
//SingularModelR.engine.Evaluate(m_predict_var_name + "$name= " + this.m_name.ToString());
Logger.Instance.log("predict_options set correctly");

SingularModelR.engine.Evaluate(m_alg_name + ".calculateGloballyGraph()");
Expand Down Expand Up @@ -172,6 +180,7 @@ public double[] predict(double[] X_input)
Logger.Instance.log_error("Error while predicting " + e.ToString());
throw (e);
}
//0 is dummy !!
double[] Y_output = new double[Y.Length + 1];
Y.AsNumeric().CopyTo(Y_output, Y.Length, 0, 1);
//Console.WriteLine(Y.First().ToString());
Expand Down
53,096 changes: 117 additions & 52,979 deletions server-predictor-tests/server-predictor-tests/bin/Debug/GeneratedSource/Model_Gibbs.cs

Large diffs are not rendered by default.

Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ model0b.getDependList<-function(i, predict_options){

model0b.prepareDependList<-function(file_name = "data/traffic_test.txt", predict_options){
###1. Read 100 lines and feed into get_corr_list
print("Prepare depend list")
print(file_name)
data.sample = read.clump(file_name, 100, 1)
depend_list = general.get_depend_list(data.sample)
save(depend_list, file = paste("data/model0b.",predict_options$name,".depend_list.RDa",sep=""))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ model0b.getDefaultPredictOptions <- function(){
look_behind = 30, #number of steps to include into prediction as it is in THE DATA #quite global
look_behind_prediction_self=30, #number of steps to look behind when considering the link to predict
look_behind_prediction = 10, #-,- other links
name = "Cars", #algorithm name for naming purposes
name = "smrCars", #algorithm name for naming purposes
ahead = 2, #number of steps to predict
ahead_data = 10, #actual number of steps registered in the file
link_count=20, #number of all links int he network to predict for (every link will separately predict for it subset of dependency list)
Expand Down Expand Up @@ -282,25 +282,24 @@ model0b.applyModel0b<-function(model0b, test_data, predict_options){
}
predicted = predicted * (1.0/model0b$normalize_factor_y)
## !!!!!!! REMOVE THIS LINE !!!!!!!!!!!#
return(sum(predicted))
return(c(predicted))
}

### Perform whole (required) prediction ###
model0b.makePrediction <- function(link_models, x, predict_options){
y = matrix(0, ncol = predict_options$link_count, nrow = 1)
y = matrix(0, ncol = predict_options$link_count, nrow = predict_options$ahead)


depend_list = model0b.getCompleteDependList(predict_options)


for(i in 1:predict_options$link_count){
for(i in 1:predict_options$link_count){
indices = c()
for(j in 1:length(depend_list[[i]])){
indices = c(indices, ((depend_list[[i]][j]-1)*predict_options$look_behind+1):(depend_list[[i]][j]*predict_options$look_behind))
indices = c(indices, ((depend_list[[i]][j]-1)*predict_options$look_behind+1):(depend_list[[i]][j]*predict_options$look_behind))
}
y[,i] = model0b.applyModel0b(link_models[[i]], as.vector(x[indices]), predict_options)
}

##note: sligh change - Y1+1 Y1+2 Y2+1 Y2+2 format
return(y)
}

Expand Down Expand Up @@ -382,6 +381,8 @@ model0b.test<-function(){
y_collected = rbind(y_collected, model0b.makePrediction(model0b.model, data_transform$samples[i,], predict_options))
}

print(y_collected)

load("data/model0b.link.general.data.RDa")


Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 4656ca0

Please sign in to comment.