Changeset 17113
- Timestamp:
- 07/08/19 15:40:39 (5 years ago)
- Location:
- stable
- Files:
-
- 6 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk merged: 16820-16821
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis merged: 16820
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis/3.4
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis/3.4 merged: 16820
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs
r17105 r17113 25 25 using System.Collections.ObjectModel; 26 26 using System.Linq; 27 using HEAL.Attic; 27 28 using HeuristicLab.Common; 28 29 using HeuristicLab.Core; 29 30 using HeuristicLab.Data; 30 using HEAL.Attic;31 31 32 32 namespace HeuristicLab.Problems.DataAnalysis { … … 113 113 this.variableValues.Add(columName, values); 114 114 } 115 } 116 117 public static Dataset FromRowData(IEnumerable<string> variableNames, double[,] data) { 118 var colWise = new List<IList>(data.GetLength(1)); 119 for (var col = 0; col < data.GetLength(1); col++) { 120 var column = new List<double>(data.GetLength(0)); 121 for (var row = 0; row < data.GetLength(0); row++) { 122 column.Add(data[row, col]); 123 } 124 colWise.Add(column); 125 } 126 return new Dataset(variableNames, colWise); 127 } 128 129 public static Dataset FromRowData(IEnumerable<string> variableNames, IEnumerable<IList> data) { 130 var vnames = variableNames.ToList(); 131 var transposed = new List<IList>(); 132 var iter = data.GetEnumerator(); 133 if (!iter.MoveNext()) throw new ArgumentException("Data does not contain any rows", nameof(data)); 134 for (var i = 0; i < iter.Current.Count; i++) { 135 if (i >= vnames.Count) throw new ArgumentException("There are more variables in data, than variable names.", nameof(variableNames)); 136 if (iter.Current[i] == null) throw new ArgumentException("Null values are not supported.", nameof(data)); 137 if (!IsAllowedType(iter.Current[i].GetType())) throw new ArgumentException("Data contains types that are not allowed.", nameof(data)); 138 if (iter.Current[i] is double d) 139 transposed.Add(new List<double>() { d }); 140 else if (iter.Current[i] is DateTime dt) 141 transposed.Add(new List<DateTime>() { dt }); 142 else if (iter.Current[i] is string s) 143 transposed.Add(new List<string>() { s }); 144 else throw new NotSupportedException(string.Format("Variable {0} has type {1}. This is not supported when converting from row-wise data.", vnames[i], iter.Current[i].GetType())); 145 } 146 if (transposed.Count < vnames.Count) throw new ArgumentException("There are less variables in data, than variable names.", nameof(variableNames)); 147 while (iter.MoveNext()) { 148 for (var i = 0; i < iter.Current.Count; i++) 149 if (transposed[i].Add(iter.Current[i]) < 0) 150 throw new ArgumentException(string.Format("Variable {0} has invalid value ({1})", vnames[i], iter.Current[i]), nameof(data)); 151 } 152 return new Dataset(vnames, transposed); 115 153 } 116 154 -
stable/HeuristicLab.Tests
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Tests merged: 16820-16821
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Tests/HeuristicLab.Tests.csproj
r17105 r17113 592 592 <Compile Include="HeuristicLab.PluginInfraStructure-3.3\TypeExtensionsTest.cs" /> 593 593 <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\ClassificationVariableImpactCalculationTest.cs" /> 594 <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\DatasetTest.cs" /> 594 595 <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\IntervalTest.cs" /> 595 596 <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\RegressionVariableImpactCalculationTest.cs" />
Note: See TracChangeset
for help on using the changeset viewer.