本文整理汇总了C++中gMat2D类的典型用法代码示例。如果您正苦于以下问题:C++ gMat2D类的具体用法?C++ gMat2D怎么用?C++ gMat2D使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了gMat2D类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: inv
GURLS_EXPORT void inv(const gMat2D<float>& A, gMat2D<float>& Ainv, InversionAlgorithm alg)
{
Ainv = A;
int k = std::min(Ainv.cols(), Ainv.rows());
int info;
int* ipiv = new int[k];
int m = Ainv.rows();
int n = Ainv.cols();
int lda = Ainv.rows();
sgetrf_(&m, &n, Ainv.getData(), &lda, ipiv, &info);
float* work = new float[n];
sgetri_(&m, Ainv.getData(), &lda, ipiv, work, &n, &info);
delete[] ipiv;
delete[] work;
}
开发者ID:cshen,项目名称:GURLS,代码行数:21,代码来源:gmath.cpp
示例2: cholesky
GURLS_EXPORT void cholesky(const gMat2D<float>& A, gMat2D<float>& L, bool upper){
typedef float T;
L = A;
int LDA = A.rows();
int n = A.cols();
char UPLO = upper? 'U' : 'L';
int info;
spotrf_(&UPLO,&n, L.getData(),&LDA,&info);
// This is required because we adopted a column major order to store the
// data into matrices
gMat2D<T> tmp(L.rows(), L.cols());
if (!upper){
L.uppertriangular(tmp);
} else {
L.lowertriangular(tmp);
}
tmp.transpose(L);
}
开发者ID:xufango,项目名称:contrib_bk,代码行数:23,代码来源:gmath.cpp
示例3: updateModule
bool updateModule()
{
++updateCount;
if (updateCount > numPred)
{
cout << "Specified number of predictions reached. Shutting down the module." << endl;
return false;
}
// DEBUG
if(verbose) cout << "updateModule #" << updateCount << endl;
// Recursive update support and storage variables declaration and initialization
gMat2D<T> Xnew(1,d);
gMat2D<T> ynew(1,t);
gVec<T> Xnew_v(d);
gVec<T> ynew_v(t);
gMat2D<T> *resptr = 0;
// Wait for input feature vector
if(verbose) cout << "Expecting input vector" << endl;
Bottle *bin = inVec.read(); // blocking call
if (bin != 0)
{
if(verbose) cout << "Got it!" << endl << bin->toString() << endl;
//Store the received sample in gMat2D format for it to be compatible with gurls++
for (int i = 0 ; i < bin->size() ; ++i)
{
if ( i < d )
{
Xnew(0,i) = bin->get(i).asDouble();
}
else if ( (i>=d) && (i<d+t) )
{
ynew(0, i - d ) = bin->get(i).asDouble();
}
}
if(verbose) cout << "Xnew: " << endl << Xnew << endl;
if(verbose) cout << "ynew: " << endl << ynew.rows() << " x " << ynew.cols() << endl;
if(verbose) cout<< ynew << endl;
//-----------------------------------
// Prediction
//-----------------------------------
// Test on the incoming sample
resptr = estimator.eval(Xnew);
Bottle& bpred = pred.prepare(); // Get a place to store things.
bpred.clear(); // clear is important - b might be a reused object
for (int i = 0 ; i < t ; ++i)
{
bpred.addDouble((*resptr)(0 , i));
}
if(verbose) printf("Sending prediction!!! %s\n", bpred.toString().c_str());
pred.write();
if(verbose) printf("Prediction written to port\n");
//----------------------------------
// performance
Bottle& bperf = perf.prepare(); // Get a place to store things.
bperf.clear(); // clear is important - b might be a reused object
if (perfType == "nMSE") // WARNING: The estimated variance could be unreliable...
{
// Compute nMSE and store
//NOTE: In GURLS, "/" operator works like matlab's "\".
error += varCols / ( ynew - *resptr )*( ynew - *resptr ) ;
gMat2D<T> tmp = error / (updateCount); // WARNING: Check
for (int i = 0 ; i < t ; ++i)
{
bperf.addDouble(tmp(0 , i));
}
}
else if (perfType == "RMSE")
{
gMat2D<T> tmp(1,t);
tmp = ( ynew - *resptr )*( ynew - *resptr );
//error = ( error * (updateCount-1) + sqrt(( ynew - *resptr )*( ynew - *resptr )) ) / updateCount;
error = error * (updateCount-1);
for (int i = 0 ; i < ynew.cols() ; ++i)
error(0,i) += sqrt(tmp(0,i));
error = error / updateCount;
/* for (int i = 0 ; i < t ; ++i)
{
//.........这里部分代码省略.........
开发者ID:GiuliaP,项目名称:iRRLS,代码行数:101,代码来源:parametricEstimator.cpp
示例4: configure
bool configure(ResourceFinder &rf)
{
string name=rf.find("name").asString().c_str();
setName(name.c_str());
// Set verbosity
verbose = rf.check("verbose",Value(0)).asInt();
// Set dimensionalities
d = rf.check("d",Value(0)).asInt();
t = rf.check("t",Value(0)).asInt();
if (d <= 0 || t <= 0 )
{
printf("Error: Inconsistent feature or output dimensionalities!\n");
return false;
}
// Set perf type WARNING: perf types should be defined as separate sister classes
perfType = rf.check("perf",Value("RMSE")).asString();
if ( perfType != "MSE" && perfType != "RMSE" && perfType != "nMSE" )
{
printf("Error: Inconsistent performance measure! Set to RMSE.\n");
perfType = "RMSE";
}
// Set number of saved performance measurements
numPred = rf.check("numPred",Value("-1")).asInt();
// Set number of saved performance measurements
savedPerfNum = rf.check("savedPerfNum",Value("0")).asInt();
if (savedPerfNum > numPred)
{
savedPerfNum = numPred;
cout << "Warning: savedPerfNum > numPred, setting savedPerfNum = numPred" << endl;
}
//experimentCount = rf.check("experimentCount",Value("0")).asInt();
experimentCount = rf.find("experimentCount").asInt();
// Print Configuration
cout << endl << "-------------------------" << endl;
cout << "Configuration parameters:" << endl << endl;
cout << "experimentCount = " << experimentCount << endl;
cout << "d = " << d << endl;
cout << "t = " << t << endl;
cout << "perf = " << perfType << endl;
cout << "-------------------------" << endl << endl;
// Open ports
string fwslash="/";
inVec.open((fwslash+name+"/vec:i").c_str());
printf("inVec opened\n");
pred.open((fwslash+name+"/pred:o").c_str());
printf("pred opened\n");
perf.open((fwslash+name+"/perf:o").c_str());
printf("perf opened\n");
rpcPort.open((fwslash+name+"/rpc:i").c_str());
printf("rpcPort opened\n");
// Attach rpcPort to the respond() method
attach(rpcPort);
// Initialize random number generator
srand(static_cast<unsigned int>(time(NULL)));
// Initialize error structures
error.resize(1,t);
error = gMat2D<T>::zeros(1, t); //
if (savedPerfNum > 0)
{
storedError.resize(savedPerfNum,t);
storedError = gMat2D<T>::zeros(savedPerfNum, t); //MSE
}
updateCount = 0;
//------------------------------------------
// Pre-training
//------------------------------------------
if ( pretrain == 1 )
{
if ( pretr_type == "fromFile" )
{
//------------------------------------------
// Pre-training from file
//------------------------------------------
string trainFilePath = rf.getContextPath() + "/data/" + pretrainFile;
try
{
// Load data files
cout << "Loading data file..." << endl;
//.........这里部分代码省略.........
开发者ID:GiuliaP,项目名称:iRRLS,代码行数:101,代码来源:parametricEstimator.cpp
示例5: init
BigArray<T>::BigArray(std::string fileName, const gMat2D<T>& mat)
{
init(fileName, mat.rows(), mat.cols());
MPI_Barrier(MPI_COMM_WORLD);
}
开发者ID:elen4,项目名称:GURLS,代码行数:6,代码来源:bigarray.hpp
示例6: setMatrix
void BigArray<T>::setMatrix(unsigned long startingRow, unsigned long startingCol, const gMat2D<T>&value)
{
setMatrix(startingRow, startingCol, value.getData(), value.rows(), value.cols());
}
开发者ID:elen4,项目名称:GURLS,代码行数:4,代码来源:bigarray.hpp
示例7: cholesky
GURLS_EXPORT void cholesky(const gMat2D<float>& A, gMat2D<float>& L, bool upper)
{
cholesky<float>(A.getData(), A.rows(), A.cols(), L.getData(), upper);
}
开发者ID:elen4,项目名称:GURLS,代码行数:4,代码来源:gmath.cpp
示例8: lu
GURLS_EXPORT void lu(gMat2D<float>& A)
{
gVec<int> pv(std::min(A.cols(), A.rows()));
lu(A, pv);
}
开发者ID:elen4,项目名称:GURLS,代码行数:5,代码来源:gmath.cpp
示例9: svd
GURLS_EXPORT void svd(const gMat2D<float>& A, gMat2D<float>& U, gVec<float>& W, gMat2D<float>& Vt) {
char jobu = 'S', jobvt = 'S';
int m = A.rows();
int n = A.cols();
int k = std::min<int>(m, n);
if ((int)W.getSize() < k) {
throw gException("The length of vector W must be at least equal to the minimum dimension of the input matrix A");
}
if ((int)U.rows() < m || (int)U.cols() < k) {
throw gException("Please check the dimensions of the matrix U where to store the singular vectors");
}
if ((int)Vt.rows() < k || (int)Vt.cols() < n) {
throw gException("Please check the dimensions of the matrix Vt where to store the rigth singular vectors");
}
int lda = A.cols();
int ldu = U.cols();
int ldvt = Vt.cols();
int info, lwork = std::max<int>(3*k+std::max<int>(m,n), 5*k);
float* work = new float[lwork];
float* copy = new float[m*n];
A.asarray(copy, m*n);
sgesvd_(&jobu, &jobvt, &n, &m, copy, &lda, W.getData(), Vt.getData(), &ldvt, U.getData(), &ldu, work, &lwork, &info);
delete[] work;
delete[] copy;
}
开发者ID:xufango,项目名称:contrib_bk,代码行数:28,代码来源:gmath.cpp
示例10: pinv
GURLS_EXPORT void pinv(const gMat2D<float>& A, gMat2D<float>& Ainv, float RCOND){
/*
subroutine SGELSS ( INTEGER M,
INTEGER N,
INTEGER NRHS,
REAL,dimension( lda, * ) A,
INTEGER LDA,
REAL,dimension( ldb, * ) B,
INTEGER LDB,
REAL,dimension( * ) S,
REAL RCOND,
INTEGER RANK,
REAL,dimension( * ) WORK,
INTEGER LWORK,
INTEGER INFO
)
*/
int M = A.rows();
int N = A.cols();
// The following step is required because we are currently storing
// the matrices using a column-major order while LAPACK's
// routines require row-major ordering
float* a = new float[M*N];
const float* ptr_A = A.getData();
float* ptr_a = a;
for (int j = 0; j < N ; j++){
for (int i = 0; i < M ; i++){
*ptr_a++ = *(ptr_A+i*N+j);
}
}
int LDA = M;
int LDB = std::max(M, N);
int NRHS = LDB;
float *b = new float[LDB*NRHS], *b_ptr = b;
for (int i = 0; i < LDB*NRHS; i++){
*b_ptr++=0.f;
}
b_ptr = b;
for (int i = 0; i < std::min(LDB, NRHS); i++, b_ptr+=(NRHS+1)){
*b_ptr = 1.f;
}
float* S = new float[std::min(M,N)];
float condnum = 0.f; // The condition number of A in the 2-norm = S(1)/S(min(m,n)).
if (RCOND < 0){
RCOND = 0.f;
}
int RANK = -1; // std::min(M,N);
int LWORK = -1; //2 * (3*LDB + std::max( 2*std::min(M,N), LDB));
float* WORK = new float[1];
/*
INFO:
= 0: successful exit
< 0: if INFO = -i, the i-th argument had an illegal value.
> 0: the algorithm for computing the SVD failed to converge;
if INFO = i, i off-diagonal elements of an intermediate
bidiagonal form did not converge to zero.
*/
int INFO;
/* Query and allocate the optimal workspace */
/*int res = */sgelss_( &M, &N, &NRHS, a, &LDA, b, &LDB, S, &RCOND, &RANK, WORK, &LWORK, &INFO);
LWORK = static_cast<int>(WORK[0]);
delete [] WORK;
WORK = new float[LWORK];
/*res = */sgelss_( &M, &N, &NRHS, a, &LDA, b, &LDB, S, &RCOND, &RANK, WORK, &LWORK, &INFO);
// TODO: check INFO on exit
condnum = S[0]/(S[std::min(M, N)]-1);
// gMat2D<float> *tmp = new gMat2D<float>(b, LDB, LDB, false);
float *ainv = new float[N*M];
float* ptr_b = ainv;
float* ptr_B = b;
for (int i = 0; i < N ; i++){
for (int j = 0; j < M ; j++){
*(ptr_b+i*M+j) = *(ptr_B+j*NRHS+i);
}
}
Ainv = * new gMat2D<float>(ainv, N, M, true);
// gMat2D<float> *tmp = new gMat2D<float>(b, LDB, NRHS, false);
// gMat2D<float> *tmp1 = new gMat2D<float>(NRHS, LDB);
// tmp->transpose(*tmp1);
// Ainv = * new gMat2D<float>(tmp1->getData(), N, M, true);
// std::cout << "A = " << std::endl << A << std::endl;
// std::cout << "pinv(A) = " << std::endl << Ainv << std::endl;
delete [] S;
delete [] WORK;
delete [] a;
// delete tmp, tmp1;
//.........这里部分代码省略.........
开发者ID:xufango,项目名称:contrib_bk,代码行数:101,代码来源:gmath.cpp
注:本文中的gMat2D类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论