本文整理汇总了C++中linalg::Matrix::getNumberOfRows方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix::getNumberOfRows方法的具体用法?C++ Matrix::getNumberOfRows怎么用?C++ Matrix::getNumberOfRows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类linalg::Matrix
的用法示例。
在下文中一共展示了Matrix::getNumberOfRows方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: A
void restrictedOptimizationHandler::simplex<Type>::simplexOptimization(const LinAlg::Matrix<Type> &c,
const LinAlg::Matrix<Type> &A,
const LinAlg::Matrix<Type> &b,
LinAlg::Matrix<Type> &B,
LinAlg::Matrix<Type> &N)
{
// %% selecione uma base B e calcule B^-1
LinAlg::Matrix<Type> An = A(from(1)-->A.getNumberOfRows(),N);
LinAlg::Matrix<Type> Ab = A(from(1)-->A.getNumberOfRows(),B);
// std::cout << N << "\n";
LinAlg::Matrix<Type> Abinv = LinAlg::inv_numeric(Ab);
// LinAlg::Matrix<Type> Abinv = (Ab^-1);
LinAlg::Matrix<Type> xb;
// %% Verifique o vetor dos custos reduzidos
for(unsigned terminate = 1; terminate <= 100; ++terminate)
{
LinAlg::Matrix<Type> cn = c(N,1);
LinAlg::Matrix<Type> cb = c(B,1);
LinAlg::Matrix<Type>An = A(from(1)-->A.getNumberOfRows(),N);
Ab = A(from(1)-->A.getNumberOfRows(),B);
LinAlg::Matrix<Type> r = (~cn) - (~cb)*Abinv*An;
this->cost = ((~cb)*Abinv*b)(1,1);
xb = Abinv*b;
unsigned contFlag = 0;
for (unsigned i=1; i <= r.getNumberOfColumns(); ++i)
if(r(1,i) >= 0)
{
contFlag = contFlag + 1;
//% break;
}
if(contFlag == r.getNumberOfColumns())
break;
//%determine o vetor de chegada
unsigned indMinD = LinAlg::lineOfMinValue(~r);
this->x = Abinv*An(from(1)-->An.getNumberOfRows(),indMinD);
LinAlg::Matrix<Type> d = LinAlg::divPoint(xb,this->x);
Type dMin = INFINITY;
unsigned indMinB = 1;
for (unsigned i = 1; i <= d.getNumberOfRows(); ++i)
if(this->x(i,1) > 0 && d(i,1) < dMin)
{
dMin = d(i,1);
indMinB = i;
}
Abinv = EscalSimplex((Abinv | xb | this->x),indMinB);
Type Bout = B(1,indMinB);
Type Nout = N(1,indMinD);
N = N(1,from(1)-->(indMinD-1)) | Bout | N(1, from(indMinD+1)-->(N.getNumberOfColumns()));
B = B(1,from(1)-->(indMinB-1)) | Nout | B(1,from(indMinB+1)-->(B.getNumberOfColumns()));
}
this->x = xb || LinAlg::Zeros<Type>(An.getNumberOfColumns(),1);
LinAlg::Matrix<Type> ind = LinAlg::sortColumnVectorIndices<Type>(B|N);
this->x = this->x(ind,1);
// std::cout << "\n\n" << ind << "\n\n";
N = LinAlg::sortColumnVector<Type>(N);
B = LinAlg::sortColumnVector<Type>(B);
}
示例2: MatrizRes
LinAlg::Matrix<float> SistemasLineares::GaussJacobi(LinAlg::Matrix<float> MatrizUni, unsigned MaxIterations)
{
//Matriz Resposta
LinAlg::Matrix<float> MatrizRes(MaxIterations, MatrizUni.getNumberOfColumns());
LinAlg::Matrix<float> C (MatrizUni.getNumberOfRows(), MatrizUni.getNumberOfColumns() - 1);
LinAlg::Matrix<float> g (MatrizUni.getNumberOfRows(), 1);
LinAlg::Matrix<float> x0(C.getNumberOfColumns(), 1);
// //Deixa o vetor de chute inicial padronizado como vetor linha
if(this->X0.getNumberOfColumns() < this->X0.getNumberOfRows())
~this->X0;
// //Insere o chute inicial na Matriz resposta
for(unsigned i = 1; i < MatrizRes.getNumberOfColumns() - 1; ++i)
x0(1,i) = this->X0(1,i);
//Laço para contar as linhas da MatrizUni e Matriz C.
for(unsigned i = 1; i <= MatrizUni.getNumberOfRows(); ++i)
{ //Laço para contar as colunas da MAtrizUni e Matriz C.
for(unsigned j = 1; j < MatrizUni.getNumberOfColumns(); ++j)
{
if(i != j)
C(i,j) = - MatrizUni(i,j)/MatrizUni(i,i);//Matriz com a diagonal zerada.
}
g(i,1) = MatrizUni(i,MatrizUni.getNumberOfColumns()) / MatrizUni(i,i);//Matriz dos termos independentes.
}
MatrizRes = ~x0;
for(unsigned k = 1; k < MaxIterations; ++k)
{
x0 = (C * x0) + g;
MatrizRes = MatrizRes || ~x0;
}
return MatrizRes;
}
示例3: newNumRoots
PolynomHandler::Polynom<Type> PolynomHandler::simplify(const Type *num,const Type *den,const unsigned &numSize,const unsigned &denSize)
{
LinAlg::Matrix<Type> numRoots = Roots<Type>(num, numSize);
LinAlg::Matrix<Type> denRoots = Roots<Type>(den, denSize);
unsigned equalRootsCount = 0;
for(unsigned i = 1; i <= numRoots.getNumberOfRows(); ++i)
if(PolynomHandler::rootsContainRoot(numRoots(i,1),denRoots))
++equalRootsCount;
LinAlg::Matrix<Type> newNumRoots(numSize - equalRootsCount,2);
LinAlg::Matrix<Type> newDenRoots(denSize - equalRootsCount,2);
unsigned cont = 1;
for(unsigned i = 1; i <= numRoots.getNumberOfRows(); ++i)
if(!PolynomHandler::rootsContainRoot(numRoots(i,1),denRoots))
{
newNumRoots(cont,1) = numRoots(i,1);
newNumRoots(cont,2) = numRoots(i,2);
cont++;
}
cont = 1;
for(unsigned i = 1; i <= denRoots.getNumberOfRows(); ++i)
if(!PolynomHandler::rootsContainRoot(denRoots(1,i),numRoots))
{
newDenRoots(cont,1) = denRoots(i,1);
newDenRoots(cont,2) = denRoots(i,2);
cont++;
}
return Polynom<Type>(Root2Poly(newNumRoots),Root2Poly(newDenRoots));
// return ret;
}
示例4: ret
LinAlg::Matrix<Type> LinAlg::Matrix<Type>::operator|| (LinAlg::Matrix<RightType> rhs)
{
LinAlg::Matrix<Type>ret;
if(this->mat == NULL)
ret = rhs;
else
{
unsigned aux = this->rows;
if(this->columns < rhs.getNumberOfColumns())
ret.Init(this->rows + rhs.getNumberOfRows(), rhs.getNumberOfColumns());
else
ret.Init(this->rows + rhs.getNumberOfRows(), this->columns);
for(unsigned i = 0; i < this->rows; i++)
for(unsigned j = 0; j < this->columns; j++)
ret.mat[i][j] = this->mat[i][j];
for(unsigned i = 1; i <= rhs.getNumberOfRows(); i++)
for(unsigned j = 1; j <= rhs.getNumberOfColumns(); j++)
ret(i + aux, j) = rhs(i, j);
}
return ret;
}
示例5: MatrizUni
LinAlg::Matrix<float> SistemasLineares::Gauss(LinAlg::Matrix<float> MatrizUni)
{
LinAlg::Matrix<float> MatrizGauss;
//Laço para contagem das colunas de MatrizUni.
for(unsigned i = 1; i < MatrizUni.getNumberOfColumns(); i++)
{ //Laço para contagem das linhas de MatrizUni.
for(unsigned j = i + 1; j <= MatrizUni.getNumberOfRows(); j++)
{
float m = MatrizUni(j,i)/MatrizUni(i,i);
//Laço para contagem das colunas da equação.
for(unsigned z = i ; z <= MatrizUni.getNumberOfColumns(); z++)
MatrizUni(j,z) = MatrizUni(j,z) - m*MatrizUni(i,z);
}
}
MatrizGauss = LinAlg::Zeros<float>(1, MatrizUni.getNumberOfRows());
float R;
for(unsigned i = 1; i <= MatrizUni.getNumberOfRows(); ++i)
{
unsigned k = MatrizUni.getNumberOfRows() - i + 1;
R = 0;
for(unsigned j = k + 1; j <= MatrizUni.getNumberOfColumns() - 1; ++j)
R = R + MatrizUni(k, j) * MatrizGauss(1, j);
MatrizGauss(1, k) = (MatrizUni(k, MatrizUni.getNumberOfColumns()) - R) / MatrizUni(k, k);
}
return MatrizGauss;
}
示例6: temp
LinAlg::Matrix<Type> LinAlg::operator~ (LinAlg::Matrix<Type> mat)
{
LinAlg::Matrix<Type> temp(mat.getNumberOfColumns(), mat.getNumberOfRows());
for(unsigned i = 1; i <= mat.getNumberOfRows(); i++)
for(unsigned j = 1; j <= mat.getNumberOfColumns(); j++)
temp(j, i) = mat(i, j);
return temp;
}
示例7: Output
void OptimizationHandler::RecursiveLeastSquare<Type>::Optimize(LinAlg::Matrix<Type> Input, LinAlg::Matrix<Type> Output)
{
this->model->setLinearVector(Input, Output(from(1)-->Output.getNumberOfRows(),1));
LinAlg::Matrix<Type> phi = this->model->getLinearVectorA();
E = Output(from(1)-->Output.getNumberOfRows(),2) - phi*this->model->getModelCoef();
K = (P*~phi)/(((phi*P)*~phi) + lambda);
this->model->setModelCoef(this->model->getModelCoef() + K*E);
P = (P - (K*(phi*P)))/lambda;
}
示例8: QCustomPlot
void PlotHandler::plot<Type>::generalPlot(LinAlg::Matrix<Type> X, LinAlg::Matrix<Type> Y)
{
// centralWidget = new QWidget(this->properties.MainWindow);
// centralWidget->setGeometry(QRect(this->properties.windowPosX, this->properties.windowPosY, this->properties.windowSizeX, this->properties.windowSizeY));
customPlot = new QCustomPlot(this->properties.PlotFrame);
customPlot->setGeometry(QRect(0, 0,this->properties.PlotFrame->geometry().width(), this->properties.PlotFrame->geometry().height()));
// add title layout element:
if(this->properties.titleFlag)
{
customPlot->plotLayout()->insertRow(0);
customPlot->plotLayout()->addElement(0, 0, new QCPPlotTitle(this->customPlot, this->properties.title.c_str()));
}
if(X.getNumberOfColumns() == Y.getNumberOfColumns() && X.getNumberOfRows() == Y.getNumberOfRows())
{
this->properties.rows = X.getNumberOfRows();
this->properties.columns = X.getNumberOfColumns();
// this->setLegend();
QPen pen;
// add graphs with different scatter styles:
for (unsigned i = 0; i < this->properties.rows; ++i)
{
customPlot->addGraph();
pen.setColor(QColor(qSin(i*0.3)*100+100, qSin(i*0.6+0.7)*100+100, qSin(i*0.4+0.6)*100+100));
// generate data:
QVector<double> x(this->properties.columns), y(this->properties.columns);
for (unsigned k = 0; k < this->properties.columns; ++k)
{
x[k] = X(i+1,k+1);
y[k] = Y(i+1,k+1);
}
customPlot->graph()->setData(x, y);
customPlot->graph()->rescaleAxes(true);
customPlot->graph()->setPen(pen);
if(this->properties.variablesNameFlag)
customPlot->graph()->setName("Grafico" + QString::number(i+1));
customPlot->graph()->setLineStyle(QCPGraph::lsLine);
if(this->properties.xLabelFlag)
customPlot->xAxis->setLabel(this->properties.xLabel.c_str());
if(this->properties.yLabelFlag)
customPlot->yAxis->setLabel(this->properties.yLabel.c_str());
// set scatter style:
}
}
customPlot->rescaleAxes();
}
示例9: S
void restrictedOptimizationHandler::activeSet<Type>::KKT(LinAlg::Matrix<Type> A,
LinAlg::Matrix<Type> b,
LinAlg::Matrix<Type> &x,
LinAlg::Matrix<Type> &v)
{
LinAlg::Matrix<Type> K = (this->QuadMat | (~A)) ||
(A | LinAlg::Zeros<Type>(A.getNumberOfRows(),A.getNumberOfRows()));
LinAlg::Matrix<Type> L = -this->LinMat || b;
LinAlg::Matrix<Type> S = (((~K)*K)^-1)*(~K)*L;
x = S(from(1)-->this->LinMat.getNumberOfRows(),1);
if(A.getNumberOfRows() > 0)
v = S(from(this->LinMat.getNumberOfRows()+1)-->(this->LinMat.getNumberOfRows() + b.getNumberOfRows()),
from(1)-->S.getNumberOfColumns());
}
示例10: LU_Factorization
void SistemasLineares::LU_Factorization(LinAlg::Matrix<float> Matriz, LinAlg::Matrix<float> &L, LinAlg::Matrix<float> &U)//Para Matriz Quadrada.
{
L = LinAlg::Eye<float>(Matriz.getNumberOfRows());
for(unsigned i = 1; i < Matriz.getNumberOfColumns(); ++i)
{ //Laço para contagem das linhas de MatrizUni.
for(unsigned j = i + 1; j <= Matriz.getNumberOfRows(); ++j)
{
L(j, i) = Matriz(j, i)/Matriz(i, i);
//Laço para contagem das colunas da equação.
for(unsigned z = i ; z <= Matriz.getNumberOfColumns(); ++z)
Matriz(j, z) = Matriz(j, z) - L(j, i)*Matriz(i, z);
}
}
U = Matriz;
}
示例11: Trace
Type LinAlg::Trace (const LinAlg::Matrix<Type>& mat)
{
Type ret = 0;
if(mat.getNumberOfRows() != mat.getNumberOfColumns())
std::cout << "O traco so e calculado para matrizes quadradas.";
else
{
for(unsigned i = 1; i <= mat.getNumberOfRows(); i++)
for(unsigned j = 1; j <= mat.getNumberOfColumns(); j++)
if(i == j)
ret += mat(i, j);
}
return ret;
}
示例12: rootsContainRoot
bool PolynomHandler::rootsContainRoot(const Type &root, const LinAlg::Matrix<Type> &roots)
{
for(unsigned i = 1; i <= roots.getNumberOfRows(); ++i)
{
if(root == roots(1,i))
return 1;
}
return 0;
}
示例13: if
Type NeuralNetworkHandler::Neuron<Type>::sim(LinAlg::Matrix<Type> Input, LinAlg::Matrix<Type> Weight, Type Bias){
Type tempOutput = 0;
if(Input.getNumberOfRows() < Input.getNumberOfColumns() || Weight.getNumberOfRows() < Weight.getNumberOfColumns())
std::cout<<"As dimensoes nao batem. Impossivel realizar operacao."<<std::endl;
else{
this->Input = Input;
this->Weight = Weight;
this->Bias = Bias;
tempOutput = ((~this->Input * this->Weight) - this->Bias)(1,1);
//std::cout<<tempOutput<<std::endl;
if(this->ActiveFunctionType == "Signal")
this->Output = this->Signal(tempOutput);
else if(this->ActiveFunctionType == "HardLimit")
this->Output = this->HardLimit(tempOutput);
else if(this->ActiveFunctionType == "Linear")
this->Output = this->Linear(tempOutput);
else if(this->ActiveFunctionType == "PositiveLinear")
this->Output = this->PositiveLinear(tempOutput);
else if(this->ActiveFunctionType == "SymmetricLinear")
this->Output = this->SymmetricLinear(tempOutput);
else if(this->ActiveFunctionType == "SaturatingLinear")
this->Output = this->SaturatingLinear(tempOutput);
else if(this->ActiveFunctionType == "Gaussian")
this->Output = this->Gaussian(tempOutput);
else if(this->ActiveFunctionType == "Multiquadrics")
this->Output = this->Multiquadrics(tempOutput);
else if(this->ActiveFunctionType == "InverseMultiquadrics")
this->Output = this->InverseMultiquadrics(tempOutput);
else if(this->ActiveFunctionType == "Sigmoid")
this->Output = this->Sigmoid(tempOutput);
else if(this->ActiveFunctionType == "HyperbolicTangentSigmoid")
this->Output = this->HyperbolicTangentSigmoid(tempOutput);
else{
std::cout<<"Metodo nao encontrado"<<std::endl;
this->Output = tempOutput;
}
return Output;
}
return 0;
}
示例14: CritLinhas
void SistemasLineares::CritLinhas(LinAlg::Matrix<float> MatrizUni)
{
LinAlg::Matrix<float> MatrizRes(1,MatrizUni.getNumberOfRows());
for(unsigned i = 1; i <= MatrizUni.getNumberOfRows(); i++)
{
for(unsigned j =1; j <= MatrizUni.getNumberOfColumns(); j++)
{
if(i != j)
{
MatrizRes(1, i) += MatrizUni(i,j)/MatrizUni(i,i);
}
}
if(MatrizRes(1, i) > 1)
{
cout<<"O sistema não possui solução para qualquer valor inicial de X0";
break;
}
}
}
示例15: Type
LinAlg::Matrix<Type> restrictedOptimizationHandler::activeSet<Type>::activeRestrictions(const LinAlg::Matrix<Type> &A,
const LinAlg::Matrix<Type> &b,
Type tol)
{
LinAlg::Matrix<Type> restrictionsTest = (A*this->x - b), ind;
for(unsigned i = 1; i <= restrictionsTest.getNumberOfRows(); ++i)
if(restrictionsTest(i,1) >= tol)
ind = ind | Type(i);
return ind;
}