- Timestamp:
- 10/29/08 11:21:04 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.GP.StructureIdentification.TimeSeries
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/AveragePercentageChangeEvaluator.cs
r686 r702 30 30 namespace HeuristicLab.GP.StructureIdentification.TimeSeries { 31 31 public class AvergePercentageChangeEvaluator : GPEvaluatorBase { 32 protected DoubleData apc;33 private bool differential;34 32 public override string Description { 35 33 get { … … 44 42 } 45 43 46 public override IOperation Apply(IScope scope) {47 differential = GetVariableValue<BoolData>("Differential", scope, true).Data;48 apc = GetVariableValue<DoubleData>("APC", scope, false, false);44 public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) { 45 bool differential = GetVariableValue<BoolData>("Differential", scope, true).Data; 46 DoubleData apc = GetVariableValue<DoubleData>("APC", scope, false, false); 49 47 if(apc == null) { 50 48 apc = new DoubleData(); … … 52 50 } 53 51 54 return base.Apply(scope);55 }56 57 public override void Evaluate(int start, int end) {58 52 double percentageSum = 0; 59 53 for(int sample = start; sample < end; sample++) { … … 62 56 double estimatedPercentageChange; 63 57 if(differential) { 64 prevOriginal = GetOriginalValue(sample - 1); 65 originalPercentageChange = (GetOriginalValue(sample) - prevOriginal) / prevOriginal; 66 estimatedPercentageChange = (GetEstimatedValue(sample) - prevOriginal) / prevOriginal; 67 SetOriginalValue(sample, estimatedPercentageChange*prevOriginal + prevOriginal); 58 prevOriginal = dataset.GetValue(targetVariable,sample - 1); 59 originalPercentageChange = (dataset.GetValue(targetVariable,sample) - prevOriginal) / prevOriginal; 60 estimatedPercentageChange = (evaluator.Evaluate(sample) - prevOriginal) / prevOriginal; 61 if(updateTargetValues) { 62 dataset.SetValue(targetVariable, sample, estimatedPercentageChange * prevOriginal + prevOriginal); 63 } 68 64 } else { 69 originalPercentageChange = GetOriginalValue(sample); 70 estimatedPercentageChange = GetEstimatedValue(sample); 71 SetOriginalValue(sample, estimatedPercentageChange); 65 originalPercentageChange = dataset.GetValue(targetVariable,sample); 66 estimatedPercentageChange = evaluator.Evaluate(sample); 67 if(updateTargetValues) { 68 dataset.SetValue(targetVariable, sample, estimatedPercentageChange); 69 } 72 70 } 73 71 if(!double.IsNaN(originalPercentageChange) && !double.IsInfinity(originalPercentageChange)) { -
trunk/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/ProfitEvaluator.cs
r686 r702 30 30 namespace HeuristicLab.GP.StructureIdentification.TimeSeries { 31 31 public class ProfitEvaluator : GPEvaluatorBase { 32 protected DoubleData profit;33 private int exchangeRateVarIndex;34 private double transactionCost;35 32 public override string Description { 36 33 get { … … 46 43 } 47 44 48 public override IOperation Apply(IScope scope) {49 exchangeRateVarIndex = GetVariableValue<IntData>("ExchangeRate", scope, true).Data;50 transactionCost = GetVariableValue<DoubleData>("TransactionCost", scope, true).Data;51 profit = GetVariableValue<DoubleData>("Profit", scope, false, false);45 public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) { 46 int exchangeRateVarIndex = GetVariableValue<IntData>("ExchangeRate", scope, true).Data; 47 double transactionCost = GetVariableValue<DoubleData>("TransactionCost", scope, true).Data; 48 DoubleData profit = GetVariableValue<DoubleData>("Profit", scope, false, false); 52 49 if(profit == null) { 53 50 profit = new DoubleData(); … … 55 52 } 56 53 57 return base.Apply(scope);58 }59 60 public override void Evaluate(int start, int end) {61 54 double cA = 1.0; // start with a capital of one entity of A 62 55 double cB = 0; … … 64 57 for(int sample = start; sample < end; sample++) { 65 58 exchangeRate = dataset.GetValue(sample, exchangeRateVarIndex); 66 double originalPercentageChange = GetOriginalValue(sample); 67 double estimatedPercentageChange = GetEstimatedValue(sample); 68 SetOriginalValue(sample, estimatedPercentageChange); 59 double originalPercentageChange = dataset.GetValue(targetVariable, sample); 60 double estimatedPercentageChange = evaluator.Evaluate(sample); 61 if(updateTargetValues) { 62 dataset.SetValue(targetVariable, sample, estimatedPercentageChange); 63 } 69 64 if(!double.IsNaN(originalPercentageChange) && !double.IsInfinity(originalPercentageChange)) { 70 65 if(estimatedPercentageChange > 0) { 71 66 // prediction is the rate of B/A will increase (= get more B for one A) => exchange all B to A 72 cA += (cB / exchangeRate) * (1 -transactionCost);67 cA += (cB / exchangeRate) * (1 - transactionCost); 73 68 cB = 0; 74 69 } else if(estimatedPercentageChange < 0) { 75 70 // prediction is the rate of B/A will drop (= get more A for one B) => exchange all A to B 76 cB += (cA * exchangeRate) * (1 -transactionCost);71 cB += (cA * exchangeRate) * (1 - transactionCost); 77 72 cA = 0; 78 73 } … … 86 81 // at the end we must exchange all B back to A 87 82 // (because we want to buy the local beer not import one from B-country) 88 profit.Data = cA + ((cB / exchangeRate) * (1 -transactionCost));83 profit.Data = cA + ((cB / exchangeRate) * (1 - transactionCost)); 89 84 profit.Data -= 1.0; // substract the start capital to determine actual profit 90 85 } -
trunk/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/TheilInequalityCoefficientEvaluator.cs
r695 r702 31 31 namespace HeuristicLab.GP.StructureIdentification.TimeSeries { 32 32 public class TheilInequalityCoefficientEvaluator : GPEvaluatorBase { 33 private DoubleData theilInequaliy;34 private DoubleData uBias;35 private DoubleData uVariance;36 private DoubleData uCovariance;37 38 33 public override string Description { 39 34 get { … … 59 54 } 60 55 61 public override IOperation Apply(IScope scope) { 62 theilInequaliy = GetVariableValue<DoubleData>("TheilInequalityCoefficient", scope, false, false); 56 public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) { 57 #region create result variables 58 DoubleData theilInequaliy = GetVariableValue<DoubleData>("TheilInequalityCoefficient", scope, false, false); 63 59 if(theilInequaliy == null) { 64 60 theilInequaliy = new DoubleData(); 65 61 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TheilInequalityCoefficient"), theilInequaliy)); 66 62 } 67 uBias = GetVariableValue<DoubleData>("TheilInequalityCoefficientBias", scope, false, false);63 DoubleData uBias = GetVariableValue<DoubleData>("TheilInequalityCoefficientBias", scope, false, false); 68 64 if(uBias == null) { 69 65 uBias = new DoubleData(); 70 66 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TheilInequalityCoefficientBias"), uBias)); 71 67 } 72 uVariance = GetVariableValue<DoubleData>("TheilInequalityCoefficientVariance", scope, false, false);68 DoubleData uVariance = GetVariableValue<DoubleData>("TheilInequalityCoefficientVariance", scope, false, false); 73 69 if(uVariance == null) { 74 70 uVariance = new DoubleData(); 75 71 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TheilInequalityCoefficientVariance"), uVariance)); 76 72 } 77 uCovariance = GetVariableValue<DoubleData>("TheilInequalityCoefficientCovariance", scope, false, false);73 DoubleData uCovariance = GetVariableValue<DoubleData>("TheilInequalityCoefficientCovariance", scope, false, false); 78 74 if(uCovariance == null) { 79 75 uCovariance = new DoubleData(); 80 76 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TheilInequalityCoefficientCovariance"), uCovariance)); 81 77 } 82 return base.Apply(scope); 83 } 78 #endregion 84 79 85 public override void Evaluate(int start, int end) {86 80 double errorsSquaredSum = 0.0; 87 81 double originalSquaredSum = 0.0; 88 double[] estimatedChanges = new double[end -start];89 double[] originalChanges = new double[end -start];82 double[] estimatedChanges = new double[end - start]; 83 double[] originalChanges = new double[end - start]; 90 84 int nSamples = 0; 91 85 for(int sample = start; sample < end; sample++) { 92 double prevValue = GetOriginalValue(sample - 1); 93 double estimatedChange = GetEstimatedValue(sample) - prevValue; 94 double originalChange = GetOriginalValue(sample) - prevValue; 95 SetOriginalValue(sample, estimatedChange + prevValue); 86 double prevValue = dataset.GetValue(targetVariable, sample - 1); 87 double estimatedChange = evaluator.Evaluate(sample) - prevValue; 88 double originalChange = dataset.GetValue(targetVariable, sample) - prevValue; 89 if(updateTargetValues) { 90 dataset.SetValue(targetVariable, sample, estimatedChange + prevValue); 91 } 96 92 if(!double.IsNaN(originalChange) && !double.IsInfinity(originalChange)) { 97 93 double error = estimatedChange - originalChange; … … 118 114 119 115 // all parts add up to one so I don't have to calculate the correlation coefficient for the covariance propotion 120 uCovariance.Data = 1.0 - uBias.Data - uVariance.Data; 116 uCovariance.Data = 1.0 - uBias.Data - uVariance.Data; 121 117 } 122 118 }
Note: See TracChangeset
for help on using the changeset viewer.