当前位置: 首页>>代码示例>>C++>>正文


C++ DataFrame::getDataElement方法代码示例

本文整理汇总了C++中DataFrame::getDataElement方法的典型用法代码示例。如果您正苦于以下问题:C++ DataFrame::getDataElement方法的具体用法?C++ DataFrame::getDataElement怎么用?C++ DataFrame::getDataElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataFrame的用法示例。


在下文中一共展示了DataFrame::getDataElement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _calculateEntropy

  double SymmetricUncertaintyCalculator::_calculateEntropy(const DataFrame& df, int factorIndex)
  {
    typedef HashMap<int, int> ClassCounts;
    ClassCounts cc;
    
    for(unsigned int i = 0; i < df.getNumDataVectors(); i++)
    {
      double v = df.getDataElement(i, factorIndex);
      // null values are not supported Use the DataFrameDiscretizer to "fix" nulls
      if (DataFrame::isNull(v) == true)
      {
        throw Tgs::Exception("Null values are not supported by SymmetricUncertaintyCalculator");
      }
      cc[(int)(v + .5)]++;
    }

    double sum = 0.0;
    double totalSize = df.getNumDataVectors();
    for (ClassCounts::const_iterator classIt = cc.begin(); classIt != cc.end(); classIt++)
    {
      double count = classIt->second;
      sum += count / totalSize * log2(count / totalSize);
    }

    return -sum;
  }
开发者ID:Nanonid,项目名称:hootenanny,代码行数:26,代码来源:SymmetricUncertaintyCalculator.cpp

示例2: _calculateConditionalEntropy

  double SymmetricUncertaintyCalculator::_calculateConditionalEntropy(const DataFrame& dfY, 
    int factorIndexY, const DataFrame& dfX, int factorIndexX)
  {
    CondClassCounts ccc;
    ClassCounts cc;

    for(unsigned int i = 0; i < dfX.getNumDataVectors(); i++)
    {
      double vx = dfX.getDataElement(i, factorIndexX);
      if (DataFrame::isNull(vx) == true)
      {
        throw Tgs::Exception("Null values are not supported by SymmetricUncertaintyCalculator");
      }
      int ex = (int)(vx + 0.5); // x enumeration

      double vy = dfY.getDataElement(i, factorIndexY);
      if (DataFrame::isNull(vy) == true)
      {
        throw Tgs::Exception("Null values are not supported by SymmetricUncertaintyCalculator");
      }      
      int ey = (int)(vy + 0.5); // y enumeration

      ccc[ex][ey]++;
      cc[ex]++;
    }

    double sumX = 0.0;
    double totalSize = dfX.getNumDataVectors();
    for (CondClassCounts::const_iterator condIt = ccc.begin(); condIt != ccc.end(); condIt++)
    {
      const ClassCounts& classCounts = condIt->second;
      double px = (double)cc[condIt->first] / totalSize; // p(x)
      double sumY = 0.0;
      for (ClassCounts::const_iterator classIt = classCounts.begin(); 
        classIt != classCounts.end(); classIt++)
      {
        double count = classIt->second;
        double pyx = count / (double)cc[condIt->first]; // p(y | x)
        sumY += pyx * log2(pyx);
      }
      sumX += px * sumY;
    }

    return -sumX;
  }
开发者ID:Nanonid,项目名称:hootenanny,代码行数:45,代码来源:SymmetricUncertaintyCalculator.cpp

示例3: compute

  void PrincipalComponentsAnalysis::compute(DataFrame& df)
  {
    if (df.getNumFactors() > 2)
    {
      // see PrincipalComponentsAnalysisTest
      cout << "You realize this hasn't been tested, right?" << endl;
    }
    Matrix dataMat(df.getNumFactors(), df.getNumDataVectors());
    Matrix deviates(df.getNumFactors(), df.getNumDataVectors());
    SymmetricMatrix covar(df.getNumFactors());
    DiagonalMatrix eigenValues(df.getNumFactors());
    Matrix eigenVectors;
    ColumnVector means(df.getNumFactors());
    means = 0.0;
    RowVector h(df.getNumDataVectors());
    h = 1.0;

    for (unsigned int j = 0; j < df.getNumFactors(); j++)
    {
      if (df.isNominal(j))
      {
        throw Tgs::Exception("Only numeric values are supported.");
      }
    }


    for(unsigned int i = 0; i < df.getNumDataVectors(); i++)
    {
      for (unsigned int j = 0; j < df.getNumFactors(); j++)
      {
        double v = df.getDataElement(i, j);
        if (df.isNull(v))
        {
          throw Tgs::Exception("Only non-null values are supported.");
        }
        dataMat.element(j, i) = v;
        means.element(j) += v / (double)df.getNumDataVectors();
      }
    }

    try
    {
      deviates = dataMat - (means * h);
      covar << (1.0/(float)df.getNumDataVectors()) * (deviates * deviates.t());
      Jacobi::jacobi(covar, eigenValues, eigenVectors);
    }
    catch (const std::exception&)
    {
      throw;
    }
    catch (...)
    {
      throw Tgs::Exception("Unknown error while calculating PCA");
    }

    _sortEigens(eigenVectors, eigenValues);

    _components.resize(df.getNumFactors());
    for (unsigned int v = 0; v < df.getNumFactors(); v++)
    {
      _components[v].resize(df.getNumFactors());
      for (unsigned int d = 0; d < df.getNumFactors(); d++)
      {
        _components[v][d] = eigenVectors.element(d, v);
      }
    }
  }
开发者ID:Nanonid,项目名称:hootenanny,代码行数:67,代码来源:PrincipalComponentsAnalysis.cpp


注:本文中的DataFrame::getDataElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。