Changeset 16388 for branches/2892_LR-prediction-intervals/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs
- Timestamp:
- 12/15/18 12:36:08 (5 years ago)
- Location:
- branches/2892_LR-prediction-intervals
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2892_LR-prediction-intervals
- Property svn:ignore
-
old new 1 *.docstates 2 *.psess 3 *.resharper 4 *.suo 5 *.user 6 *.vsp 7 Doxygen 8 FxCopResults.txt 9 Google.ProtocolBuffers-0.9.1.dll 10 Google.ProtocolBuffers-2.4.1.473.dll 11 HeuristicLab 3.3.5.1.ReSharper.user 12 HeuristicLab 3.3.6.0.ReSharper.user 13 HeuristicLab.4.5.resharper.user 14 HeuristicLab.ExtLibs.6.0.ReSharper.user 15 HeuristicLab.Scripting.Development 16 HeuristicLab.resharper.user 17 ProtoGen.exe 1 18 TestResults 19 _ReSharper.HeuristicLab 20 _ReSharper.HeuristicLab 3.3 21 _ReSharper.HeuristicLab 3.3 Tests 22 _ReSharper.HeuristicLab.ExtLibs 23 bin 24 protoc.exe 25 obj 26 .vs
-
- Property svn:mergeinfo changed
-
Property
svn:global-ignores
set to
*.nuget
packages
- Property svn:ignore
-
branches/2892_LR-prediction-intervals/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
-
branches/2892_LR-prediction-intervals/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs
r15583 r16388 39 39 40 40 private ModifiableDataset(ModifiableDataset original, Cloner cloner) : base(original, cloner) { 41 var variables = variableValues.Keys.ToList(); 42 foreach (var v in variables) { 43 var type = GetVariableType(v); 44 if (type == typeof(DateTime)) { 45 variableValues[v] = GetDateTimeValues(v).ToList(); 46 } else if (type == typeof(double)) { 47 variableValues[v] = GetDoubleValues(v).ToList(); 48 } else if (type == typeof(string)) { 49 variableValues[v] = GetStringValues(v).ToList(); 50 } else { 51 throw new ArgumentException("Unsupported type " + type + " for variable " + v); 41 variableNames = new List<string>(original.variableNames); 42 variableValues = CloneValues(original.variableValues); 43 } 44 45 public override IDeepCloneable Clone(Cloner cloner) { return new ModifiableDataset(this, cloner); } 46 47 public ModifiableDataset() { } 48 49 public ModifiableDataset(IEnumerable<string> variableNames, IEnumerable<IList> variableValues, bool cloneValues = false) : 50 base(variableNames, variableValues, cloneValues) { } 51 52 public Dataset ToDataset() { 53 return new Dataset(variableNames, variableNames.Select(v => variableValues[v])); 54 } 55 56 57 public IEnumerable<object> GetRow(int row) { 58 if (row < 0 || row >= Rows) 59 throw new ArgumentException(string.Format("Invalid row {0} specified. The dataset contains {1} row(s).", row, Rows)); 60 61 return variableValues.Select(x => x.Value[row]); 62 } 63 64 public void AddRow(IEnumerable<object> values) { 65 var list = values.ToList(); 66 if (list.Count != variableNames.Count) 67 throw new ArgumentException("The number of values must be equal to the number of variable names."); 68 // check if all the values are of the correct type 69 for (int i = 0; i < list.Count; ++i) { 70 if (list[i].GetType() != GetVariableType(variableNames[i])) { 71 throw new ArgumentException("The type of the provided value does not match the variable type."); 52 72 } 53 73 } 54 } 55 public override IDeepCloneable Clone(Cloner cloner) { return new ModifiableDataset(this, cloner); } 56 public ModifiableDataset() : base() { } 57 58 public ModifiableDataset(IEnumerable<string> variableNames, IEnumerable<IList> variableValues) : base(variableNames, variableValues) { } 74 // add values 75 for (int i = 0; i < list.Count; ++i) { 76 variableValues[variableNames[i]].Add(list[i]); 77 } 78 Rows++; 79 OnRowsChanged(); 80 OnReset(); 81 } 59 82 60 83 public void ReplaceRow(int row, IEnumerable<object> values) { … … 72 95 variableValues[variableNames[i]][row] = list[i]; 73 96 } 97 OnReset(); 98 } 99 100 // slow, avoid using this 101 public void RemoveRow(int row) { 102 foreach (var list in variableValues.Values) 103 list.RemoveAt(row); 104 Rows--; 105 OnRowsChanged(); 106 OnReset(); 107 } 108 109 // adds a new variable to the dataset 110 public void AddVariable(string variableName, IList values) { 111 InsertVariable(variableName, Columns, values); 112 } 113 114 public void InsertVariable(string variableName, int position, IList values) { 115 if (variableValues.ContainsKey(variableName)) 116 throw new ArgumentException(string.Format("Variable {0} is already present in the dataset.", variableName)); 117 118 if (position < 0 || position > Columns) 119 throw new ArgumentException(string.Format("Incorrect position {0} specified. The position must be between 0 and {1}.", position, Columns)); 120 121 if (values == null) 122 throw new ArgumentNullException("values", "Values must not be null. At least an empty list of values has to be provided."); 123 124 if (values.Count != Rows) 125 throw new ArgumentException(string.Format("{0} values are provided, but {1} rows are present in the dataset.", values.Count, Rows)); 126 127 if (!IsAllowedType(values)) 128 throw new ArgumentException(string.Format("Unsupported type {0} for variable {1}.", GetElementType(values), variableName)); 129 130 variableNames.Insert(position, variableName); 131 variableValues[variableName] = values; 132 133 OnColumnsChanged(); 134 OnColumnNamesChanged(); 74 135 OnReset(); 75 136 } … … 85 146 } 86 147 87 public void AddRow(IEnumerable<object> values) {88 var list = values.ToList();89 if (list.Count != variableNames.Count)90 throw new ArgumentException("The number of values must be equal to the number of variable names.");91 // check if all the values are of the correct type92 for (int i = 0; i < list.Count; ++i) {93 if (list[i].GetType() != GetVariableType(variableNames[i])) {94 throw new ArgumentException("The type of the provided value does not match the variable type.");95 }96 }97 // add values98 for (int i = 0; i < list.Count; ++i) {99 variableValues[variableNames[i]].Add(list[i]);100 }101 rows++;102 OnRowsChanged();103 OnReset();104 }105 106 // adds a new variable to the dataset107 public void AddVariable<T>(string variableName, IEnumerable<T> values) {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);114 variableNames.Add(variableName);115 OnColumnsChanged();116 OnColumnNamesChanged();117 OnReset();118 }119 148 120 149 public void RemoveVariable(string variableName) { 121 150 if (!variableValues.ContainsKey(variableName)) 122 throw new ArgumentException( "The variable " + variableName + " does not exist in the dataset.");151 throw new ArgumentException(string.Format("The variable {0} does not exist in the dataset.", variableName)); 123 152 variableValues.Remove(variableName); 124 153 variableNames.Remove(variableName); … … 128 157 } 129 158 130 // slow, avoid to use this131 public void RemoveRow(int row) {132 foreach (var list in variableValues.Values)133 list.RemoveAt(row);134 rows--;159 public void ClearValues() { 160 foreach (var list in variableValues.Values) { 161 list.Clear(); 162 } 163 Rows = 0; 135 164 OnRowsChanged(); 136 165 OnReset(); 137 166 } 167 138 168 139 169 public void SetVariableValue(object value, string variableName, int row) { … … 151 181 } 152 182 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 183 bool IStringConvertibleMatrix.SetValue(string value, int rowIndex, int columnIndex) { 162 184 var variableName = variableNames[columnIndex];
Note: See TracChangeset
for help on using the changeset viewer.