Exemplo n.º 1
0
    public CovarianceItem(CovarianceKey key_, DataTable dt_, string firstId_, string secondId_, int count_)
    {
      int currencyCount = count_;

      m_data = new double[currencyCount, currencyCount];
      m_key = key_;
      int x, y;

      foreach (DataRow row in dt_.Rows)
      {
        x = (int)row[firstId_] - 1;
        y = (int)row[secondId_] - 1;

        m_data[x, y] = (double)row["cov"];
        m_data[y, x] = (double)row["cov"];
      }
    }
Exemplo n.º 2
0
    public CovarianceItem(CovarianceKey key_, DataTable dt_, string firstId_, string secondId_)
    {
      List<CovRow> rows = new List<CovRow>();
      List<int> uniqueIds = new List<int>();

      int x, y;
      double val;

      // extract all the rows and build up list of unique ids
      foreach (DataRow row in dt_.Rows)
      {
        x = (int)row[firstId_] - 1;
        y = (int)row[secondId_] - 1;
        val = (double)row["cov"];
        rows.Add(new CovRow(x, y, val));

        if (uniqueIds.Contains(x) == false)
          uniqueIds.Add(x);
      }

      // sort the ids
      QuickSort.Sort<int>(uniqueIds);

      m_data = new double[uniqueIds.Count, uniqueIds.Count];

      foreach (CovRow cr in rows)
      {
        x = uniqueIds.IndexOf(cr.Id1);
        y = uniqueIds.IndexOf(cr.Id2);

        m_data[x, y] = cr.Value;
        m_data[y, x] = cr.Value;
      }

      m_componentIds = new List<int>();
      foreach (int i in uniqueIds)
        m_componentIds.Add(i + 1);
    }