- Timestamp:
- 11/05/08 21:34:12 (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
r702 r712 45 45 bool differential = GetVariableValue<BoolData>("Differential", scope, true).Data; 46 46 DoubleData apc = GetVariableValue<DoubleData>("APC", scope, false, false); 47 if (apc == null) {47 if (apc == null) { 48 48 apc = new DoubleData(); 49 49 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("APC"), apc)); … … 51 51 52 52 double percentageSum = 0; 53 for (int sample = start; sample < end; sample++) {53 for (int sample = start; sample < end; sample++) { 54 54 double prevOriginal; 55 55 double originalPercentageChange; 56 56 double estimatedPercentageChange; 57 if (differential) {58 prevOriginal = dataset.GetValue( targetVariable,sample - 1);59 originalPercentageChange = (dataset.GetValue( targetVariable,sample) - prevOriginal) / prevOriginal;57 if (differential) { 58 prevOriginal = dataset.GetValue(sample - 1, targetVariable); 59 originalPercentageChange = (dataset.GetValue(sample, targetVariable) - prevOriginal) / prevOriginal; 60 60 estimatedPercentageChange = (evaluator.Evaluate(sample) - prevOriginal) / prevOriginal; 61 if (updateTargetValues) {62 dataset.SetValue( targetVariable, sample, estimatedPercentageChange * prevOriginal + prevOriginal);61 if (updateTargetValues) { 62 dataset.SetValue(sample, targetVariable, estimatedPercentageChange * prevOriginal + prevOriginal); 63 63 } 64 64 } else { 65 originalPercentageChange = dataset.GetValue( targetVariable,sample);65 originalPercentageChange = dataset.GetValue(sample, targetVariable); 66 66 estimatedPercentageChange = evaluator.Evaluate(sample); 67 if (updateTargetValues) {68 dataset.SetValue( targetVariable, sample, estimatedPercentageChange);67 if (updateTargetValues) { 68 dataset.SetValue(sample, targetVariable, estimatedPercentageChange); 69 69 } 70 70 } 71 if (!double.IsNaN(originalPercentageChange) && !double.IsInfinity(originalPercentageChange)) {72 if ((estimatedPercentageChange > 0 && originalPercentageChange > 0) ||71 if (!double.IsNaN(originalPercentageChange) && !double.IsInfinity(originalPercentageChange)) { 72 if ((estimatedPercentageChange > 0 && originalPercentageChange > 0) || 73 73 (estimatedPercentageChange < 0 && originalPercentageChange < 0)) { 74 74 percentageSum += Math.Abs(originalPercentageChange); 75 } else if ((estimatedPercentageChange > 0 && originalPercentageChange < 0) ||75 } else if ((estimatedPercentageChange > 0 && originalPercentageChange < 0) || 76 76 (estimatedPercentageChange < 0 && originalPercentageChange > 0)) { 77 77 percentageSum -= Math.Abs(originalPercentageChange); … … 81 81 82 82 percentageSum /= (end - start); 83 if (double.IsNaN(percentageSum) || double.IsInfinity(percentageSum)) {83 if (double.IsNaN(percentageSum) || double.IsInfinity(percentageSum)) { 84 84 percentageSum = double.MinValue; 85 85 } -
trunk/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/ProfitEvaluator.cs
r702 r712 47 47 double transactionCost = GetVariableValue<DoubleData>("TransactionCost", scope, true).Data; 48 48 DoubleData profit = GetVariableValue<DoubleData>("Profit", scope, false, false); 49 if (profit == null) {49 if (profit == null) { 50 50 profit = new DoubleData(); 51 51 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("Profit"), profit)); … … 55 55 double cB = 0; 56 56 double exchangeRate = double.MaxValue; 57 for (int sample = start; sample < end; sample++) {57 for (int sample = start; sample < end; sample++) { 58 58 exchangeRate = dataset.GetValue(sample, exchangeRateVarIndex); 59 double originalPercentageChange = dataset.GetValue( targetVariable, sample);59 double originalPercentageChange = dataset.GetValue(sample, targetVariable); 60 60 double estimatedPercentageChange = evaluator.Evaluate(sample); 61 if (updateTargetValues) {62 dataset.SetValue( targetVariable, sample, estimatedPercentageChange);61 if (updateTargetValues) { 62 dataset.SetValue(sample, targetVariable, estimatedPercentageChange); 63 63 } 64 if (!double.IsNaN(originalPercentageChange) && !double.IsInfinity(originalPercentageChange)) {65 if (estimatedPercentageChange > 0) {64 if (!double.IsNaN(originalPercentageChange) && !double.IsInfinity(originalPercentageChange)) { 65 if (estimatedPercentageChange > 0) { 66 66 // prediction is the rate of B/A will increase (= get more B for one A) => exchange all B to A 67 67 cA += (cB / exchangeRate) * (1 - transactionCost); 68 68 cB = 0; 69 } else if (estimatedPercentageChange < 0) {69 } else if (estimatedPercentageChange < 0) { 70 70 // prediction is the rate of B/A will drop (= get more A for one B) => exchange all A to B 71 71 cB += (cA * exchangeRate) * (1 - transactionCost); … … 75 75 } 76 76 77 if (double.IsNaN(cA) || double.IsInfinity(cA) || double.IsInfinity(cB) || double.IsNaN(cB)) {77 if (double.IsNaN(cA) || double.IsInfinity(cA) || double.IsInfinity(cB) || double.IsNaN(cB)) { 78 78 cA = 0; 79 79 cB = 0; -
trunk/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/TheilInequalityCoefficientEvaluator.cs
r702 r712 55 55 56 56 public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) { 57 #region create result variables57 #region create result variables 58 58 DoubleData theilInequaliy = GetVariableValue<DoubleData>("TheilInequalityCoefficient", scope, false, false); 59 if (theilInequaliy == null) {59 if (theilInequaliy == null) { 60 60 theilInequaliy = new DoubleData(); 61 61 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TheilInequalityCoefficient"), theilInequaliy)); 62 62 } 63 63 DoubleData uBias = GetVariableValue<DoubleData>("TheilInequalityCoefficientBias", scope, false, false); 64 if (uBias == null) {64 if (uBias == null) { 65 65 uBias = new DoubleData(); 66 66 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TheilInequalityCoefficientBias"), uBias)); 67 67 } 68 68 DoubleData uVariance = GetVariableValue<DoubleData>("TheilInequalityCoefficientVariance", scope, false, false); 69 if (uVariance == null) {69 if (uVariance == null) { 70 70 uVariance = new DoubleData(); 71 71 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TheilInequalityCoefficientVariance"), uVariance)); 72 72 } 73 73 DoubleData uCovariance = GetVariableValue<DoubleData>("TheilInequalityCoefficientCovariance", scope, false, false); 74 if (uCovariance == null) {74 if (uCovariance == null) { 75 75 uCovariance = new DoubleData(); 76 76 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TheilInequalityCoefficientCovariance"), uCovariance)); … … 83 83 double[] originalChanges = new double[end - start]; 84 84 int nSamples = 0; 85 for (int sample = start; sample < end; sample++) {86 double prevValue = dataset.GetValue( targetVariable, sample - 1);85 for (int sample = start; sample < end; sample++) { 86 double prevValue = dataset.GetValue(sample - 1, targetVariable); 87 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);88 double originalChange = dataset.GetValue(sample, targetVariable) - prevValue; 89 if (updateTargetValues) { 90 dataset.SetValue(sample, targetVariable, estimatedChange + prevValue); 91 91 } 92 if (!double.IsNaN(originalChange) && !double.IsInfinity(originalChange)) {92 if (!double.IsNaN(originalChange) && !double.IsInfinity(originalChange)) { 93 93 double error = estimatedChange - originalChange; 94 94 errorsSquaredSum += error * error; … … 100 100 } 101 101 double quality = Math.Sqrt(errorsSquaredSum / nSamples) / Math.Sqrt(originalSquaredSum / nSamples); 102 if (double.IsNaN(quality) || double.IsInfinity(quality))102 if (double.IsNaN(quality) || double.IsInfinity(quality)) 103 103 quality = double.MaxValue; 104 104 theilInequaliy.Data = quality; // U2
Note: See TracChangeset
for help on using the changeset viewer.