Changeset 15919 for branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis
- Timestamp:
- 04/25/18 09:20:54 (7 years ago)
- Location:
- branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/Api
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/Api/MatlabConnector.cs
r15912 r15919 112 112 matLabApi.GetWorkspaceData(varName, workspace, out value); 113 113 } 114 } catch (COMException e) {114 } catch (COMException) { 115 115 throw new ArgumentException(string.Format("The variable {0} does not exist in the current workspace {1}.", varName, workspace)); 116 116 } … … 137 137 matLabApi.Execute("exit"); 138 138 } 139 } catch (COMException e) {139 } catch (COMException) { 140 140 } finally { 141 141 matLabApi = null; -
branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/Api/Types/IMLTimeseries.cs
r15912 r15919 6 6 7 7 namespace HeuristicLab.Problems.Instances.DataAnalysis.Regression.Matlab.Api.Types { 8 public interface IMLTimeseries {8 public interface IMLTimeseries : IMLVariable { 9 9 /// <summary> 10 10 /// Data headers of the timeseries. -
branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/Api/Types/IMLValueVariable.cs
r15912 r15919 6 6 7 7 namespace HeuristicLab.Problems.Instances.DataAnalysis.Regression.Matlab.Api.Types { 8 public interface IMLValueVariable<TData> : IMLVariable<TData> { 9 /// <summary> 10 /// Converts a Matlab variable into a timeseries. 11 /// </summary> 12 /// <returns></returns> 13 IMLTimeseries ToTimeseries(); 14 } 8 public interface IMLValueVariable<TData> : IMLVariable { 9 /// <summary> 10 /// The data of the Matlab variable. 11 /// </summary> 12 TData Data { get; set; } 13 } 15 14 } -
branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/Api/Types/IMLVariable.cs
r15912 r15919 6 6 7 7 namespace HeuristicLab.Problems.Instances.DataAnalysis.Regression.Matlab.Api.Types { 8 public interface IMLVariable<TData>{9 10 11 12 8 public interface IMLVariable { 9 /// <summary> 10 /// The name of the Matlab variable. 11 /// </summary> 12 string Name { get; set; } 13 13 14 /// <summary> 15 /// The data of the Matlab variable. 16 /// </summary> 17 TData Data { get; set; } 18 19 /// <summary> 20 /// The Matlab datatype. 21 /// </summary> 22 MLDatatype Datatype { get; } 23 } 14 /// <summary> 15 /// The Matlab datatype. 16 /// </summary> 17 MLDatatype Datatype { get; } 18 } 24 19 } -
branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/Api/Types/MLDouble.cs
r15912 r15919 22 22 public MLDatatype Datatype { 23 23 get { return MLDatatype.Double; } 24 } 25 26 public IMLTimeseries ToTimeseries() { 27 return new MLTimeseries(Name, new double[,] { { 0 } }, new double[,] { { Data } }); 28 } 24 } 29 25 } 30 26 } -
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 } -
branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/Api/Types/MLTimeseries.cs
r15912 r15919 11 11 12 12 private string[] _dataHeaders; 13 14 #region Constructors 13 15 14 16 protected MLTimeseries() { … … 35 37 } 36 38 } 39 37 40 41 IList<MLTimeseries> tsCollection; 42 if (!(timeseries is IList<MLTimeseries>)) { 43 tsCollection = timeseries.ToList(); 44 } else { 45 tsCollection = timeseries as IList<MLTimeseries>; 46 } 47 48 int[] indices = new int[tsCollection.Count]; 38 49 var numberOfElements = dataHeaders.Count; 39 Parallel.ForEach(times, (time) => { 40 //foreach (var time in times) { 50 foreach (var time in times) { 41 51 var values = new double[numberOfElements]; 42 52 int idx = 0; 43 foreach (var item in timeseries) { 44 double[] vs = item.GetValuesByTime(time); 53 for (int i = 0; i < tsCollection.Count; i++) { 54 var item = tsCollection[i]; 55 double[] vs; 56 if (indices[i] == 0 && item.Data[indices[i]].Key > time) { 57 vs = new double[item.Data[0].Value.Length]; 58 } else { 59 if (indices[i] < item.Count - 1 && item.Data[indices[i] + 1].Key == time) { 60 indices[i]++; 61 } 62 vs = item.Data[indices[i]].Value; 63 } 45 64 46 65 foreach (var v in vs) { … … 48 67 } 49 68 } 69 50 70 lock (_locker) { 51 71 Data.Add(new KeyValuePair<double, double[]>(time, values)); 52 72 } 53 }); 54 73 } 55 74 _dataHeaders = dataHeaders.ToArray(); 56 75 } … … 96 115 } 97 116 } 117 #endregion 98 118 99 119 public string Name { get; set; }
Note: See TracChangeset
for help on using the changeset viewer.