Changeset 15919 for branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/Api/Types/MLDoubleArray.cs
- Timestamp:
- 04/25/18 09:20:54 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/Api/Types/MLDoubleArray.cs
r15912 r15919 7 7 namespace HeuristicLab.Problems.Instances.DataAnalysis.Regression.Matlab.Api.Types { 8 8 public class MLDoubleArray : IMLValueVariable<double[,]> { 9 private string[] _dataHeaders; 10 11 #region Constructors 9 12 10 13 public MLDoubleArray(string name, object values) { … … 14 17 } 15 18 Data = values as double[,]; 19 20 _dataHeaders = new string[Data.GetLength(1)]; 21 for (int i = 0; i < _dataHeaders.Length; i++) { 22 _dataHeaders[i] = string.Format("{0}:{1}", name, i); 23 } 16 24 } 17 25 26 private MLDoubleArray(MLDoubleArray a1, MLDoubleArray a2) { 27 Name = string.Format("{0};{1}", a1.Name, a2.Name); 28 29 if (!ConcatFeasible(a1, a2)) { 30 throw new ArgumentException(string.Format("Cannot concat {0} and {1}. Different number of rows.", a1.Name, a2.Name)); 31 } 32 33 var numberOfColumns = a1.Columns + a2.Columns; 34 _dataHeaders = new string[numberOfColumns]; 35 for (int i = 0; i < numberOfColumns; i++) { 36 if (i < a1.Columns) { 37 _dataHeaders[i] = a1.DataHeader[i]; 38 } else { 39 _dataHeaders[i] = a2.DataHeader[i - a1.Columns]; 40 } 41 } 42 43 Data = new double[a1.Rows, numberOfColumns]; 44 for (int i = 0; i < a1.Rows; i++) { 45 for (int j = 0; j < numberOfColumns; j++) { 46 if (j < a1.Columns) { 47 Data[i, j] = a1.Data[i, j]; 48 } else { 49 Data[i, j] = a1.Data[i, j - a1.Columns]; 50 } 51 } 52 } 53 } 54 #endregion 55 56 57 /// <summary> 58 /// Concats two given MLDoubleArrays if their number of rows equals. 59 /// If they can't be concated, this method returns null. 60 /// </summary> 61 /// <param name="a1"></param> 62 /// <param name="a2"></param> 63 /// <returns></returns> 64 public static MLDoubleArray Concat(MLDoubleArray a1, MLDoubleArray a2) { 65 if (ConcatFeasible(a1, a2)) { 66 return null; 67 } 68 return new MLDoubleArray(a1, a2); 69 } 70 71 public static bool ConcatFeasible(MLDoubleArray a1, MLDoubleArray a2) { 72 return a1.Rows == a2.Rows; 73 } 74 75 76 #region Properties from the interface 77 18 78 public string Name { get; set; } 79 19 80 public double[,] Data { get; set; } 20 81 … … 23 84 } 24 85 25 public IMLTimeseries ToTimeseries() { 26 var times = new double[Data.GetLength(0), 1]; 27 for (int i = 0; i < times.GetLength(0); i++) { 28 times[i, 1] = i; 86 public string[] DataHeader { 87 get { return _dataHeaders; } 88 } 89 #endregion 90 91 public int Rows { get { 92 return Data.GetLength(0); 29 93 } 94 } 30 95 31 return new MLTimeseries(Name, times, Data); 96 public int Columns { 97 get { 98 return Data.GetLength(1); 99 } 32 100 } 33 101 }
Note: See TracChangeset
for help on using the changeset viewer.