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


C++ mat::get_rows方法代码示例

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


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

示例1: subsample

/**
 * Returns a random subsample of X of size n which has minimum (amongst 
 * a set of NSAMPLES similar subsamples) maximum distance between points.
 */     
ivec MaxMinDesign::subsample(mat X, int n)
{
    if (n <= 0)
        cerr << "Invalid sample size in MaxMinDesign::subsample(...)" << endl;
    
    double maxMinDist = 0.0;
    ivec bestSubsample = randperm(X.rows());
    
    for (int i=0; i<nsamples; i++) {
        
    	// Generate random subsample
    	ivec irand = randperm(X.rows());
    	ivec irandn = irand(0,n-1);
        mat S = X.get_rows(irandn);
        
        // Compute max distance in this subsample
        double minDist =  distanceMin(S);

        // Keep subsample if has min max distance
        if (minDist > maxMinDist) {
        	bestSubsample = irandn;
        	maxMinDist = minDist;
        	cout << "New min distance: " << maxMinDist << endl;
        }
    }
    
    return bestSubsample;
}
开发者ID:abdullah38rcc,项目名称:swarmlabatwork,代码行数:32,代码来源:MaxMinDesign.cpp

示例2: subsample

ivec GreedyMaxMinDesign::subsample(mat X, int n)
{
    if (n <= 0)
        cerr << "Invalid sample size in GreedyMaxMinDesign::subsample(...)" << endl;
    
    int imax;
    
    ivec isample(n);        // Indices of points in sample
    ivec iremain;           // Indices of remaining points
    vec D;                  // Vector of min distances to sample
    
    iremain = to_ivec(linspace(0,X.rows()-1,X.rows()));
    
    // Start with location of maximum Z
    max(X.get_col(X.cols()-1), imax);
    isample(0) = imax;
    iremain.del(imax);

    // Add points having maximum minimum distance to sample
    // until subsample size is reached 
    for (int i=1; i<n; i++) 
    {
    	vec xnew = X.get_row(isample(i-1));                // Last point added 
        vec Dnew = dist(X.get_rows(iremain), xnew);        // Distances to xnew
                
        // Update minimum distances to sample
        if (D.length() == 0) 
            D = Dnew;
        else
            D = min(D,Dnew);
        
        // Find point with max min distance
        max(D,imax);
        
        // Add it to sample 
    	isample(i) = iremain(imax);
    	
    	// And delete it from remainder 
    	iremain.del(imax);
    	D.del(imax);
    }
    
    return isample;
}
开发者ID:abdullah38rcc,项目名称:swarmlabatwork,代码行数:44,代码来源:GreedyMaxMinDesign.cpp


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