Changeset 2619 for trunk/sources
- Timestamp:
- 01/10/10 21:01:03 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.ArtificialNeuralNetworks/3.2/Predictor.cs
r2562 r2619 37 37 } 38 38 39 public override double[]Predict(Dataset input, int start, int end) {39 public override IEnumerable<double> Predict(Dataset input, int start, int end) { 40 40 41 41 if (start < 0 || end <= start) throw new ArgumentException("start must be larger than zero and strictly smaller than end"); 42 42 if (end > input.Rows) throw new ArgumentOutOfRangeException("number of rows in input is smaller then end"); 43 double[] result = new double[end - start]; 44 for (int i = 0; i < result.Length; i++) { 45 try { 46 double[] output = new double[1]; 47 double[] inputRow = new double[input.Columns - 1]; 48 for (int c = 1; c < inputRow.Length; c++) { 49 inputRow[c - 1] = input.GetValue(i + start, c); 50 } 51 alglib.mlpbase.multilayerperceptron p = perceptron.Perceptron; 52 alglib.mlpbase.mlpprocess(ref p, ref inputRow, ref output); 53 perceptron.Perceptron = p; 54 result[i] = Math.Max(Math.Min(output[0], UpperPredictionLimit), LowerPredictionLimit); 43 44 for (int i = 0; i < end - start; i++) { 45 double[] output = new double[1]; 46 double[] inputRow = new double[input.Columns - 1]; 47 for (int c = 1; c < inputRow.Length; c++) { 48 inputRow[c - 1] = input.GetValue(i + start, c); 55 49 } 56 catch (ArgumentException) { 57 result[i] = double.NaN; 58 } 50 alglib.mlpbase.multilayerperceptron p = perceptron.Perceptron; 51 alglib.mlpbase.mlpprocess(ref p, ref inputRow, ref output); 52 perceptron.Perceptron = p; 53 yield return Math.Max(Math.Min(output[0], UpperPredictionLimit), LowerPredictionLimit); 59 54 } 60 return result;61 55 } 62 56 -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Predictor.cs
r2567 r2619 29 29 using System.Xml; 30 30 using HeuristicLab.DataAnalysis; 31 using System.Linq; 31 32 32 33 namespace HeuristicLab.GP.StructureIdentification { … … 50 51 } 51 52 52 public override double[]Predict(Dataset input, int start, int end) {53 public override IEnumerable<double> Predict(Dataset input, int start, int end) { 53 54 treeEvaluator.UpperEvaluationLimit = UpperPredictionLimit; 54 55 treeEvaluator.LowerEvaluationLimit = LowerPredictionLimit; … … 56 57 if (start < 0 || end <= start) throw new ArgumentException("start must be larger than zero and strictly smaller than end"); 57 58 if (end > input.Rows) throw new ArgumentOutOfRangeException("number of rows in input is smaller then end"); 58 treeEvaluator.PrepareForEvaluation(input, functionTree.FunctionTree); 59 double[] result = new double[end - start]; 60 for (int i = 0; i < result.Length; i++) { 61 try { 62 result[i] = treeEvaluator.Evaluate(i + start); 63 } 64 catch (ArgumentException) { 65 result[i] = double.NaN; 66 } 67 } 68 return result; 59 return treeEvaluator.Evaluate(input, functionTree.FunctionTree, Enumerable.Range(start, end - start)); 69 60 } 70 61 -
trunk/sources/HeuristicLab.Modeling/3.2/IPredictor.cs
r2381 r2619 30 30 double UpperPredictionLimit { get; set; } 31 31 double LowerPredictionLimit { get; set; } 32 double[]Predict(Dataset dataset, int start, int end);32 IEnumerable<double> Predict(Dataset dataset, int start, int end); 33 33 IEnumerable<string> GetInputVariables(); 34 34 } -
trunk/sources/HeuristicLab.Modeling/3.2/PredictorBase.cs
r2381 r2619 31 31 public double UpperPredictionLimit { get; set; } 32 32 public double LowerPredictionLimit { get; set; } 33 public abstract double[]Predict(Dataset dataset, int start, int end);33 public abstract IEnumerable<double> Predict(Dataset dataset, int start, int end); 34 34 public abstract IEnumerable<string> GetInputVariables(); 35 35 -
trunk/sources/HeuristicLab.Modeling/3.2/VariableEvaluationImpactCalculator.cs
r2559 r2619 85 85 Dataset dirtyDataset = (Dataset)dataset.Clone(); 86 86 IPredictor dirtyPredictor = (IPredictor)predictor.Clone(); 87 double[] referenceValues = predictor.Predict(dataset, start, end) ;87 double[] referenceValues = predictor.Predict(dataset, start, end).ToArray(); 88 88 89 89 double mean; … … 101 101 mean = dataset.GetMean(variableName, start, end); 102 102 oldValues = dirtyDataset.ReplaceVariableValues(variableName, Enumerable.Repeat(mean, end - start), start, end); 103 newValues = dirtyPredictor.Predict(dirtyDataset, start, end) ;103 newValues = dirtyPredictor.Predict(dirtyDataset, start, end).ToArray(); 104 104 evaluationImpacts[variableName] = 1 - CalculateVAF(referenceValues, newValues); 105 105 dirtyDataset.ReplaceVariableValues(variableName, oldValues, start, end); -
trunk/sources/HeuristicLab.Modeling/3.2/VariableQualityImpactCalculator.cs
r2559 r2619 85 85 IPredictor dirtyPredictor = (IPredictor)predictor.Clone(); 86 86 87 double[] predictedValues = predictor.Predict(dataset, start, end) ;87 double[] predictedValues = predictor.Predict(dataset, start, end).ToArray(); 88 88 double[] targetValues = dataset.GetVariableValues(targetVariableName, start, end); 89 89 … … 105 105 mean = dataset.GetMean(variableName, start, end); 106 106 oldValues = dirtyDataset.ReplaceVariableValues(variableName, Enumerable.Repeat(mean, end - start), start, end); 107 predictedValues = dirtyPredictor.Predict(dirtyDataset, start, end) ;107 predictedValues = dirtyPredictor.Predict(dirtyDataset, start, end).ToArray(); 108 108 newMSE = CalculateMSE(predictedValues, targetValues); 109 109 evaluationImpacts[variableName] = newMSE / oldMSE; -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/Predictor.cs
r2436 r2619 66 66 } 67 67 68 public override double[]Predict(Dataset input, int start, int end) {68 public override IEnumerable<double> Predict(Dataset input, int start, int end) { 69 69 if (start < 0 || end <= start) throw new ArgumentException("start must be larger than zero and strictly smaller than end"); 70 70 if (end > input.Rows) throw new ArgumentOutOfRangeException("number of rows in input is smaller then end"); … … 78 78 int targetVariableIndex = input.GetVariableIndex(targetVariable); 79 79 int rows = end - start; 80 double[] result = new double[rows];80 //double[] result = new double[rows]; 81 81 int problemRow = 0; 82 82 for (int resultRow = 0; resultRow < rows; resultRow++) { 83 83 if (double.IsNaN(input.GetValue(resultRow, targetVariableIndex))) 84 result[resultRow] =UpperPredictionLimit;84 yield return UpperPredictionLimit; 85 85 else if (resultRow + maxTimeOffset < 0) { 86 result[resultRow] = UpperPredictionLimit;87 86 problemRow++; 87 yield return UpperPredictionLimit; 88 88 } else { 89 result[resultRow] =Math.Max(Math.Min(SVM.Prediction.Predict(model, scaledProblem.X[problemRow++]), UpperPredictionLimit), LowerPredictionLimit);89 yield return Math.Max(Math.Min(SVM.Prediction.Predict(model, scaledProblem.X[problemRow++]), UpperPredictionLimit), LowerPredictionLimit); 90 90 } 91 91 } 92 return result;93 92 } 94 93
Note: See TracChangeset
for help on using the changeset viewer.