- Timestamp:
- 05/19/13 11:47:34 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/sluengo/HeuristicLab.Problems.TradeRules/Solution/TradeRulesSolutionBase.cs
r9386 r9499 9 9 using HeuristicLab.Optimization; 10 10 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; 11 using HeuristicLab.Problems.TradeRules.Evaluator; 11 12 12 13 namespace HeuristicLab.Problems.TradeRules … … 17 18 private const string TrainingCashResultName = "Cash after the operation (training)"; 18 19 private const string TestCashResultName = "Cash after the operation (test)"; 20 private const string TrainingUpDaysResultName = "Number of days that stock market goes up (training)"; 21 private const string TrainingDownDaysResultName = "Number of days that stock market goes down (training)"; 22 private const string TrainingHeuristicResultName = "Percentage of right actions after the operation (training)"; 23 private const string TestHeuristicResultName = "Percentage of right actions after the operation (test)"; 19 24 private const string TrainingMeanSquaredErrorResultName = "Mean squared error (training)"; 20 25 private const string TestMeanSquaredErrorResultName = "Mean squared error (test)"; … … 63 68 private set { ((DoubleValue)this[TestCashResultName].Value).Value = value; } 64 69 } 70 71 public double TrainingHeuristic 72 { 73 get { return ((DoubleValue)this[TrainingHeuristicResultName].Value).Value; } 74 private set { ((DoubleValue)this[TrainingHeuristicResultName].Value).Value = value; } 75 } 76 public double TestHeuristic 77 { 78 get { return ((DoubleValue)this[TestHeuristicResultName].Value).Value; } 79 private set { ((DoubleValue)this[TestHeuristicResultName].Value).Value = value; } 80 } 81 82 public double NumberUpDays 83 { 84 get { return ((DoubleValue)this[TrainingUpDaysResultName].Value).Value; } 85 private set { ((DoubleValue)this[TrainingUpDaysResultName].Value).Value = value; } 86 } 87 88 public double NumberDownDays 89 { 90 get { return ((DoubleValue)this[TrainingDownDaysResultName].Value).Value; } 91 private set { ((DoubleValue)this[TrainingDownDaysResultName].Value).Value = value; } 92 } 93 65 94 public double TradeDays 66 95 { … … 78 107 private set { ((DoubleValue)this[TestTotalTradesResultName].Value).Value = value; } 79 108 } 80 109 public double TrainingMeanSquaredError 81 110 { 82 111 get { return ((DoubleValue)this[TrainingMeanSquaredErrorResultName].Value).Value; } … … 148 177 protected TradeRulesSolutionBase(IRegressionModel model, IRegressionProblemData problemData) 149 178 : base(model, problemData) { 150 Add(new Result(TrainingCashResultName, "Cash obtained after training period in the stock market", new DoubleValue()));179 /*Add(new Result(TrainingCashResultName, "Cash obtained after training period in the stock market", new DoubleValue()));*/ 151 180 Add(new Result(TestCashResultName, "Cash obtained after test period in the stock market", new DoubleValue())); 181 Add(new Result(TrainingHeuristicResultName, "Percentage of right actions after training period in the stock market", new DoubleValue())); 182 Add(new Result(TestHeuristicResultName, "Percentage of right actions after test period in the stock market", new DoubleValue())); 183 Add(new Result(TrainingUpDaysResultName, "Number of days actions go up in the stock market", new DoubleValue())); 184 Add(new Result(TrainingDownDaysResultName, "Number of days actions down up in the stock market", new DoubleValue())); 185 152 186 Add(new Result(TestTradeDaysResultName, "Number of trading days", new DoubleValue())); 153 187 Add(new Result(TestNumberTradesResultName, "Number of trades", new DoubleValue())); 154 188 Add(new Result(TestTotalTradesResultName, "Total trades", new DoubleValue())); 155 189 } 156 157 [StorableHook(HookType.AfterDeserialization)]158 private void AfterDeserialization()159 {160 // BackwardsCompatibility3.4161 162 #region Backwards compatible code, remove with 3.5163 164 if (!ContainsKey(TrainingMeanAbsoluteErrorResultName))165 {166 OnlineCalculatorError errorState;167 Add(new Result(TrainingMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the training partition", new DoubleValue()));168 double trainingMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(EstimatedTrainingValues, ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices), out errorState);169 TrainingMeanAbsoluteError = errorState == OnlineCalculatorError.None ? trainingMAE : double.NaN;170 }171 172 if (!ContainsKey(TestMeanAbsoluteErrorResultName))173 {174 OnlineCalculatorError errorState;175 Add(new Result(TestMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the test partition", new DoubleValue()));176 double testMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(EstimatedTestValues, ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices), out errorState);177 TestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMAE : double.NaN;178 }179 180 if (!ContainsKey(TrainingMeanErrorResultName))181 {182 OnlineCalculatorError errorState;183 Add(new Result(TrainingMeanErrorResultName, "Mean of errors of the model on the training partition", new DoubleValue()));184 double trainingME = OnlineMeanErrorCalculator.Calculate(EstimatedTrainingValues, ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices), out errorState);185 TrainingMeanError = errorState == OnlineCalculatorError.None ? trainingME : double.NaN;186 }187 if (!ContainsKey(TestMeanErrorResultName))188 {189 OnlineCalculatorError errorState;190 Add(new Result(TestMeanErrorResultName, "Mean of errors of the model on the test partition", new DoubleValue()));191 double testME = OnlineMeanErrorCalculator.Calculate(EstimatedTestValues, ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices), out errorState);192 TestMeanError = errorState == OnlineCalculatorError.None ? testME : double.NaN;193 }194 #endregion195 }196 197 198 190 protected void CalculateResults() 199 191 { … … 203 195 IEnumerable<double> estimatedTestValues = EstimatedTestValues; // cache values 204 196 IEnumerable<double> originalTestValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices); 205 206 double trainingCTR = OnlineTradeRulesCalculator.Calculate(estimatedTrainingValues, ProblemData, ProblemData.TrainingIndices); 207 TrainingCash = trainingCTR; 197 198 /*double trainingCTR = OnlineTradeRulesCalculator.Calculate(estimatedTrainingValues, ProblemData, ProblemData.TrainingIndices); 199 TrainingCash = trainingCTR;*/ 200 201 double trainingHTR = OnlineHeuristicTradeRulesCalculator.Calculate(estimatedTrainingValues, ProblemData, ProblemData.TrainingIndices); 202 TrainingHeuristic = trainingHTR; 203 double trainingUpDays = OnlineHeuristicTradeRulesCalculator.getNumberUpDays(); 204 NumberUpDays = trainingUpDays; 205 double trainingDownDays = OnlineHeuristicTradeRulesCalculator.getNumberDownDays(); 206 NumberDownDays = trainingDownDays; 207 208 double testHTR = OnlineHeuristicTradeRulesCalculator.Calculate(estimatedTestValues, ProblemData, ProblemData.TestIndices); 209 TestHeuristic = testHTR; 210 208 211 double testCTR = OnlineTradeRulesCalculator.Calculate(estimatedTestValues, ProblemData, ProblemData.TestIndices); 209 212 TestCash = testCTR;
Note: See TracChangeset
for help on using the changeset viewer.