Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/25/18 09:20:54 (7 years ago)
Author:
rhanghof
Message:

#2913: The import does now work with Matlab timeseries datatypes.

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  
    112112          matLabApi.GetWorkspaceData(varName, workspace, out value);
    113113        }
    114       } catch (COMException e) {
     114      } catch (COMException) {
    115115        throw new ArgumentException(string.Format("The variable {0} does not exist in the current workspace {1}.", varName, workspace));
    116116      }
     
    137137          matLabApi.Execute("exit");
    138138        }
    139       } catch (COMException e) {
     139      } catch (COMException) {
    140140      } finally {
    141141        matLabApi = null;
  • branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/Api/Types/IMLTimeseries.cs

    r15912 r15919  
    66
    77namespace HeuristicLab.Problems.Instances.DataAnalysis.Regression.Matlab.Api.Types {
    8     public interface IMLTimeseries {
     8    public interface IMLTimeseries : IMLVariable {
    99        /// <summary>
    1010        /// Data headers of the timeseries.
  • branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/Api/Types/IMLValueVariable.cs

    r15912 r15919  
    66
    77namespace 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  }
    1514}
  • branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/Api/Types/IMLVariable.cs

    r15912 r15919  
    66
    77namespace HeuristicLab.Problems.Instances.DataAnalysis.Regression.Matlab.Api.Types {
    8     public interface IMLVariable<TData> {
    9         /// <summary>
    10         /// The name of the Matlab variable.
    11         /// </summary>
    12         string Name { get; set; }
     8  public interface IMLVariable {
     9    /// <summary>
     10    /// The name of the Matlab variable.
     11    /// </summary>
     12    string Name { get; set; }
    1313
    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  }
    2419}
  • branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/Api/Types/MLDouble.cs

    r15912 r15919  
    2222    public MLDatatype Datatype {
    2323      get { return MLDatatype.Double; }
    24     }
    25 
    26     public IMLTimeseries ToTimeseries() {
    27       return new MLTimeseries(Name, new double[,] { { 0 } }, new double[,] { { Data } });
    28     }
     24    }   
    2925  }
    3026}
  • branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/Api/Types/MLDoubleArray.cs

    r15912 r15919  
    77namespace HeuristicLab.Problems.Instances.DataAnalysis.Regression.Matlab.Api.Types {
    88  public class MLDoubleArray : IMLValueVariable<double[,]> {
     9    private string[] _dataHeaders;
     10
     11    #region Constructors
    912
    1013    public MLDoubleArray(string name, object values) {
     
    1417      }
    1518      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      }
    1624    }
    1725
     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
    1878    public string Name { get; set; }
     79
    1980    public double[,] Data { get; set; }
    2081
     
    2384    }
    2485
    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);
    2993      }
     94    }
    3095
    31       return new MLTimeseries(Name, times, Data);
     96    public int Columns {
     97      get {
     98        return Data.GetLength(1);
     99      }
    32100    }
    33101  }
  • branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/Api/Types/MLTimeseries.cs

    r15912 r15919  
    1111
    1212    private string[] _dataHeaders;
     13
     14    #region Constructors
    1315
    1416    protected MLTimeseries() {
     
    3537        }
    3638      }
     39     
    3740
     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];
    3849      var numberOfElements = dataHeaders.Count;
    39       Parallel.ForEach(times, (time) => {
    40         //foreach (var time in times) {
     50      foreach (var time in times) {
    4151        var values = new double[numberOfElements];
    4252        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          }         
    4564
    4665          foreach (var v in vs) {
     
    4867          }
    4968        }
     69
    5070        lock (_locker) {
    5171          Data.Add(new KeyValuePair<double, double[]>(time, values));
    5272        }
    53       });
    54 
     73      }
    5574      _dataHeaders = dataHeaders.ToArray();
    5675    }
     
    96115      }
    97116    }
     117    #endregion
    98118
    99119    public string Name { get; set; }
Note: See TracChangeset for help on using the changeset viewer.