arma::trans to trans

Signed-off-by: Omar Shrit <omar@avontech.fr>
This commit is contained in:
Omar Shrit
2024-01-14 21:05:05 +01:00
parent ffd808332f
commit 081ffcfb3a
17 changed files with 42 additions and 42 deletions
@@ -106,7 +106,7 @@ class SVDBatchLearning
const double val = V(i, j);
if (val != 0)
deltaW.row(i) += (val - arma::dot(W.row(i), H.col(j))) *
arma::trans(H.col(j));
trans(H.col(j));
}
// Add regularization.
if (kw != 0)
@@ -215,7 +215,7 @@ inline void SVDBatchLearning::WUpdate<arma::sp_mat>(const arma::sp_mat& V,
const size_t row = it.row();
const size_t col = it.col();
deltaW.row(it.row()) += (*it - arma::dot(W.row(row), H.col(col))) *
arma::trans(H.col(col));
trans(H.col(col));
}
if (kw != 0)
@@ -217,7 +217,7 @@ class SVDCompleteIncrementalLearning<arma::sp_mat>
deltaW.zeros();
deltaW += (**it - arma::dot(W.row(currentItemIndex),
H.col(currentUserIndex))) * arma::trans(H.col(currentUserIndex));
H.col(currentUserIndex))) * trans(H.col(currentUserIndex));
if (kw != 0) deltaW -= kw * W.row(currentItemIndex);
W.row(currentItemIndex) += u*deltaW;
@@ -243,7 +243,7 @@ class SVDCompleteIncrementalLearning<arma::sp_mat>
size_t currentItemIndex = it->row();
deltaH += (**it - arma::dot(W.row(currentItemIndex),
H.col(currentUserIndex))) * arma::trans(W.row(currentItemIndex));
H.col(currentUserIndex))) * trans(W.row(currentItemIndex));
if (kh != 0) deltaH -= kh * H.col(currentUserIndex);
H.col(currentUserIndex) += u * deltaH;
@@ -171,7 +171,7 @@ inline void SVDIncompleteIncrementalLearning::WUpdate<arma::sp_mat>(
double val = *it;
size_t i = it.row();
deltaW.row(i) += (val - arma::dot(W.row(i), H.col(currentUserIndex))) *
arma::trans(H.col(currentUserIndex));
trans(H.col(currentUserIndex));
if (kw != 0) deltaW.row(i) -= kw * W.row(i);
}
@@ -193,7 +193,7 @@ inline void SVDIncompleteIncrementalLearning::HUpdate<arma::sp_mat>(
if ((val = V(i, currentUserIndex)) != 0)
{
deltaH += (val - arma::dot(W.row(i), H.col(currentUserIndex))) *
arma::trans(W.row(i));
trans(W.row(i));
}
}
if (kh != 0) deltaH -= kh * H.col(currentUserIndex);
@@ -114,11 +114,11 @@ Forward(const MatType& input, MatType& output)
for (size_t i = 0; i < batchSize; ++i)
{
qProj.slice(i) = arma::trans(
qProj.slice(i) = trans(
queryWt * q.slice(i) + repmat(qBias, 1, tgtSeqLen));
kProj.slice(i) = arma::trans(
kProj.slice(i) = trans(
keyWt * k.slice(i) + repmat(kBias, 1, srcSeqLen));
vProj.slice(i) = arma::trans(
vProj.slice(i) = trans(
valueWt * v.slice(i) + repmat(vBias, 1, srcSeqLen));
}
@@ -175,7 +175,7 @@ Forward(const MatType& input, MatType& output)
// The final output is the linear projection of attention output.
for (size_t i = 0; i < batchSize; ++i)
{
output.col(i) = vectorise(arma::trans(attnOut.slice(i) * outWt
output.col(i) = vectorise(trans(attnOut.slice(i) * outWt
+ repmat(outBias, tgtSeqLen, 1)));
}
}
@@ -229,12 +229,12 @@ Backward(const MatType& /* input */,
if (selfAttention)
{
g.submat(0, i, g.n_rows - 1, i) =
vectorise(arma::trans(tmp.slice(i) * valueWt));
vectorise(trans(tmp.slice(i) * valueWt));
}
else
{
g.submat((tgtSeqLen + srcSeqLen) * embedDim, i, g.n_rows - 1, i) =
vectorise(arma::trans(tmp.slice(i) * valueWt));
vectorise(trans(tmp.slice(i) * valueWt));
}
}
@@ -264,13 +264,13 @@ Backward(const MatType& /* input */,
{
// Sum the query, key, and value deltas.
g.submat(0, i, g.n_rows - 1, i) +=
vectorise(arma::trans(tmp.slice(i) * keyWt));
vectorise(trans(tmp.slice(i) * keyWt));
}
else
{
g.submat(tgtSeqLen * embedDim, i,
(tgtSeqLen + srcSeqLen) * embedDim - 1, i) =
vectorise(arma::trans(tmp.slice(i) * keyWt));
vectorise(trans(tmp.slice(i) * keyWt));
}
}
@@ -289,12 +289,12 @@ Backward(const MatType& /* input */,
{
// Sum the query, key, and value deltas.
g.submat(0, i, g.n_rows - 1, i) +=
vectorise(arma::trans(tmp.slice(i) * queryWt));
vectorise(trans(tmp.slice(i) * queryWt));
}
else
{
g.submat(0, i, tgtSeqLen * embedDim - 1, i) =
vectorise(arma::trans(tmp.slice(i) * queryWt));
vectorise(trans(tmp.slice(i) * queryWt));
}
}
}
@@ -117,7 +117,7 @@ void GlimpseType<InputType, OutputType>::Forward(
for (size_t i = 0; i < outputTemp.n_slices; ++i)
{
outputTemp.slice(i) = arma::trans(outputTemp.slice(i));
outputTemp.slice(i) = trans(outputTemp.slice(i));
}
output = OutputType(outputTemp.memptr(), outputTemp.n_elem, 1);
@@ -81,7 +81,7 @@ class BlockKrylovSVDPolicy
w = w * arma::diagmat(sigma);
// Take transpose of the matrix h as required by CF class.
h = arma::trans(h);
h = trans(h);
}
/**
@@ -81,7 +81,7 @@ class QUIC_SVDPolicy
w = w * sigma;
// Take transpose of the matrix h as required by CF class.
h = arma::trans(h);
h = trans(h);
}
/**
@@ -86,7 +86,7 @@ class RandomizedSVDPolicy
w = w * arma::diagmat(sigma);
// Take transpose of the matrix h as required by CF class.
h = arma::trans(h);
h = trans(h);
}
/**
+1 -1
View File
@@ -53,7 +53,7 @@ class SVDWrapper
* @param sigma eigenvalue matrix
* @param H second unitary matrix
*
* @note V = W * sigma * arma::trans(H)
* @note V = W * sigma * trans(H)
*/
double Apply(const arma::mat& V,
arma::mat& W,
+4 -4
View File
@@ -34,7 +34,7 @@ double SVDWrapper<Factorizer>::Apply(const arma::mat& V,
for (size_t i = 0; i < sigma.n_rows && i < sigma.n_cols; ++i)
sigma(i, i) = E(i, 0);
arma::mat V_rec = W * sigma * arma::trans(H);
arma::mat V_rec = W * sigma * trans(H);
// return normalized frobenius error
return arma::norm(V - V_rec, "fro") / arma::norm(V, "fro");
@@ -56,7 +56,7 @@ double SVDWrapper<DummyClass>::Apply(const arma::mat& V,
for (size_t i = 0; i < sigma.n_rows && i < sigma.n_cols; ++i)
sigma(i, i) = E(i, 0);
arma::mat V_rec = W * sigma * arma::trans(H);
arma::mat V_rec = W * sigma * trans(H);
// return normalized frobenius error
return arma::norm(V - V_rec, "fro") / arma::norm(V, "fro");
@@ -94,7 +94,7 @@ double SVDWrapper<Factorizer>::Apply(const arma::mat& V,
W = W * arma::diagmat(sigma);
// take transpose of the matrix H as required by CF module
H = arma::trans(H);
H = trans(H);
// reconstruct the matrix
arma::mat V_rec = W * H;
@@ -135,7 +135,7 @@ double SVDWrapper<DummyClass>::Apply(const arma::mat& V,
W = W * arma::diagmat(sigma);
// take transpose of the matrix H as required by CF module
H = arma::trans(H);
H = trans(H);
// reconstruct the matrix
arma::mat V_rec = W * H;
@@ -273,7 +273,7 @@ inline void LinearRegression<ModelMatType>::Predict(
// the dataset.
util::CheckSameDimensionality(points, parameters,
"LinearRegression::Predict()", "points");
predictions = arma::trans(parameters) * points;
predictions = trans(parameters) * points;
}
}
+11 -11
View File
@@ -580,10 +580,10 @@ void LMNNFunction<MetricType>::Gradient(const arma::mat& transformation,
// Caculate gradient due to impostors.
arma::vec diff = dataset.col(i) - dataset.col(targetNeighbors(j, i));
cil += diff * arma::trans(diff);
cil += diff * trans(diff);
diff = dataset.col(i) - dataset.col(impostors(l, i));
cil -= diff * arma::trans(diff);
cil -= diff * trans(diff);
}
}
}
@@ -654,7 +654,7 @@ void LMNNFunction<MetricType>::Gradient(const arma::mat& transformation,
{
// Calculate gradient due to target neighbors.
arma::vec diff = dataset.col(i) - dataset.col(targetNeighbors(j, i));
cij += diff * arma::trans(diff);
cij += diff * trans(diff);
}
for (int j = k - 1; j >= 0; j--)
@@ -718,10 +718,10 @@ void LMNNFunction<MetricType>::Gradient(const arma::mat& transformation,
// Caculate gradient due to impostors.
arma::vec diff = dataset.col(i) - dataset.col(targetNeighbors(j, i));
cil += diff * arma::trans(diff);
cil += diff * trans(diff);
diff = dataset.col(i) - dataset.col(impostors(l, i));
cil -= diff * arma::trans(diff);
cil -= diff * trans(diff);
}
}
}
@@ -857,10 +857,10 @@ double LMNNFunction<MetricType>::EvaluateWithGradient(
// Caculate gradient due to impostors.
arma::vec diff = dataset.col(i) - dataset.col(targetNeighbors(j, i));
cil += diff * arma::trans(diff);
cil += diff * trans(diff);
diff = dataset.col(i) - dataset.col(impostors(l, i));
cil -= diff * arma::trans(diff);
cil -= diff * trans(diff);
}
}
}
@@ -941,7 +941,7 @@ double LMNNFunction<MetricType>::EvaluateWithGradient(
// Calculate gradient due to target neighbors.
arma::vec diff = dataset.col(i) - dataset.col(targetNeighbors(j, i));
cij += diff * arma::trans(diff);
cij += diff * trans(diff);
}
for (int j = k - 1; j >= 0; j--)
@@ -997,10 +997,10 @@ double LMNNFunction<MetricType>::EvaluateWithGradient(
// Caculate gradient due to impostors.
arma::vec diff = dataset.col(i) - dataset.col(targetNeighbors(j, i));
cil += diff * arma::trans(diff);
cil += diff * trans(diff);
diff = dataset.col(i) - dataset.col(impostors(l, i));
cil -= diff * arma::trans(diff);
cil -= diff * trans(diff);
}
}
}
@@ -1025,7 +1025,7 @@ inline void LMNNFunction<MetricType>::Precalculate()
{
// Calculate gradient due to target neighbors.
arma::vec diff = dataset.col(i) - dataset.col(targetNeighbors(j, i));
pCij += diff * arma::trans(diff);
pCij += diff * trans(diff);
}
}
}
@@ -66,7 +66,7 @@ class ExactSVDPolicy
eigVal %= eigVal / (data.n_cols - 1);
// Project the samples to the principals.
transformedData = arma::trans(eigvec) * centeredData;
transformedData = trans(eigvec) * centeredData;
}
};
@@ -68,7 +68,7 @@ class QUICSVDPolicy
eigVal = arma::pow(arma::diagvec(sigma), 2) / (data.n_cols - 1);
// Project the samples to the principals.
transformedData = arma::trans(eigvec) * centeredData;
transformedData = trans(eigvec) * centeredData;
}
//! Get the error tolerance fraction for calculated subspace.
@@ -73,7 +73,7 @@ class RandomizedBlockKrylovSVDPolicy
eigVal %= eigVal / (data.n_cols - 1);
// Project the samples to the principals.
transformedData = arma::trans(eigvec) * centeredData;
transformedData = trans(eigvec) * centeredData;
}
//! Get the number of iterations for the power method.
@@ -73,7 +73,7 @@ class RandomizedSVDPCAPolicy
eigVal %= eigVal / (data.n_cols - 1);
// Project the samples to the principals.
transformedData = arma::trans(eigvec) * centeredData;
transformedData = trans(eigvec) * centeredData;
}
//! Get the size of the normalized power iterations.
@@ -92,7 +92,7 @@ inline void RandomizedSVD::Apply(const MatType& data,
if (data.n_cols >= data.n_rows)
{
R = arma::randn<arma::mat>(data.n_rows, iteratedPower);
Q = (data.t() * R) - repmat(arma::trans(R.t() * rowMean), data.n_cols, 1);
Q = (data.t() * R) - repmat(trans(R.t() * rowMean), data.n_cols, 1);
}
else
{