Changeset 15769
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/GBM/GradientBoostingRegressionAlgorithm.cs
r15583 r15769 258 258 259 259 modifiableDataset.RemoveVariable(targetVarName); 260 modifiableDataset.AddVariable(targetVarName, curY.Concat(curYTest) );260 modifiableDataset.AddVariable(targetVarName, curY.Concat(curYTest).ToList()); 261 261 262 262 SampleTrainingData(rand, modifiableDataset, rRows, problemData.Dataset, curY, problemData.TargetVariable, problemData.TrainingIndices); // all training indices from the original problem data are allowed -
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs
r15583 r15769 78 78 this.variableValues = new Dictionary<string, IList>(this.variableNames.Count); 79 79 for (int i = 0; i < this.variableNames.Count; i++) { 80 var variableName = this.variableNames[i]; 80 81 var values = variableValues.ElementAt(i); 81 this.variableValues.Add(this.variableNames[i], values); 82 83 if (!IsAllowedType(values)) { 84 throw new ArgumentException(string.Format("Unsupported type {0} for variable {1}.", GetElementType(values), variableName)); 85 } 86 87 this.variableValues.Add(variableName, values); 82 88 } 83 89 } … … 125 131 return new ModifiableDataset(variableNames, values); 126 132 } 133 127 134 /// <summary> 128 135 /// Shuffle a dataset's rows … … 249 256 } 250 257 258 protected Type GetVariableType(string variableName) { 259 IList list; 260 variableValues.TryGetValue(variableName, out list); 261 if (list == null) 262 throw new ArgumentException("The variable " + variableName + " does not exist in the dataset."); 263 return GetElementType(list); 264 } 265 266 protected Type GetElementType(IList list) { 267 var type = list.GetType(); 268 return type.IsGenericType ? type.GetGenericArguments()[0] : type.GetElementType(); 269 } 270 271 protected bool IsAllowedType(IList list) { 272 var type = GetElementType(list); 273 return IsAllowedType(type); 274 } 275 276 protected bool IsAllowedType(Type type) { 277 return type == typeof(double) || type == typeof(string) || type == typeof(DateTime); 278 } 279 251 280 #region IStringConvertibleMatrix Members 252 281 [Storable] -
trunk/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs
r15583 r15769 105 105 106 106 // adds a new variable to the dataset 107 public void AddVariable <T>(string variableName, IEnumerable<T>values) {107 public void AddVariable(string variableName, IList values) { 108 108 if (variableValues.ContainsKey(variableName)) 109 throw new ArgumentException("Variable " + variableName + " is already present in the dataset."); 110 int count = values.Count(); 111 if (count != rows) 112 throw new ArgumentException("The number of values must exactly match the number of rows in the dataset."); 113 variableValues[variableName] = new List<T>(values); 109 throw new ArgumentException(string.Format("Variable {0} is already present in the dataset.", variableName)); 110 111 if (values == null || values.Count == 0) 112 throw new ArgumentException("Cannot add variable with no values."); 113 114 if (!IsAllowedType(values)) 115 throw new ArgumentException(string.Format("Unsupported type {0} for variable {1}.", GetElementType(values), variableName)); 116 117 variableValues[variableName] = values; 114 118 variableNames.Add(variableName); 119 115 120 OnColumnsChanged(); 116 121 OnColumnNamesChanged(); … … 120 125 public void RemoveVariable(string variableName) { 121 126 if (!variableValues.ContainsKey(variableName)) 122 throw new ArgumentException( "The variable " + variableName + " does not exist in the dataset.");127 throw new ArgumentException(string.Format("The variable {0} does not exist in the dataset.", variableName)); 123 128 variableValues.Remove(variableName); 124 129 variableNames.Remove(variableName); … … 128 133 } 129 134 130 // slow, avoid to usethis135 // slow, avoid using this 131 136 public void RemoveRow(int row) { 132 137 foreach (var list in variableValues.Values) … … 151 156 } 152 157 153 private Type GetVariableType(string variableName) {154 IList list;155 variableValues.TryGetValue(variableName, out list);156 if (list == null)157 throw new ArgumentException("The variable " + variableName + " does not exist in the dataset.");158 return list.GetType().GetGenericArguments()[0];159 }160 161 158 bool IStringConvertibleMatrix.SetValue(string value, int rowIndex, int columnIndex) { 162 159 var variableName = variableNames[columnIndex];
Note: See TracChangeset
for help on using the changeset viewer.