Skip to content

Commit

Permalink
fix ForLoop indentation and missing brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkowa committed Jan 22, 2024
1 parent 0bd76df commit 01262f4
Showing 1 changed file with 76 additions and 99 deletions.
175 changes: 76 additions & 99 deletions src/Mdav.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,14 @@ TDist *g_pMissingValueDist = NULL;
TDist DistXX(TData *Valuevs, TData *pT)
{
TDist Dist = 0.0;
ForLoopD (i, g_NbVar)
{
ForLoopD (i, g_NbVar){
TData Value = Valuevs[i];//GetValue(i, s);

if ((Value == g_MissingValue) ^ (pT[i] == g_MissingValue))
{
if ((Value == g_MissingValue) ^ (pT[i] == g_MissingValue)){
Dist += g_pMissingValueDist[i];
}
else
}else{
Dist += (TDist) (Squared(Value - pT[i]) * g_pWeight[i]);
}
}
return Dist;
}
Expand All @@ -50,29 +48,25 @@ TDist DistXX(TData *Valuevs, TData *pT)
TDist Dist(TData *Value1v, TData *Value2v)
{
TDist Dist = 0.0;
ForLoopD (i,g_NbVar)
{
ForLoopD (i,g_NbVar){
TData Value1 = Value1v[i],
Value2 = Value2v[i];

if ((Value1 == g_MissingValue) ^ (Value2 == g_MissingValue))
{
if ((Value1 == g_MissingValue) ^ (Value2 == g_MissingValue)){
Dist += g_pMissingValueDist[i];
}
else
}else{
Dist += (TDist) (Squared(Value1 - Value2) * g_pWeight[i]);
}
}

return Dist;
}
void AddRow(TData *pTotal, TData *Value1v, int *pNbNonMissingValue)
{
ForLoopD (j, g_NbVar)
{
ForLoopD (j, g_NbVar){
TData Value = Value1v[j];//GetValue(j, Row);

if (Value != g_MissingValue)
{
if (Value != g_MissingValue){
pTotal[j] += Value;
++pNbNonMissingValue[j];
}
Expand Down Expand Up @@ -110,61 +104,57 @@ RcppExport SEXP Mdav(SEXP data,SEXP data2,SEXP g_MissingValue_R,SEXP weights_R,S
g_pMissingValueDist = new TDist[g_NbVar];
float g_MissingValue_temp=Rcpp::as<float>(g_MissingValue_R);
g_MissingValue=g_MissingValue_temp;
ForLoop (i, g_NbVar)
ForLoop (i, g_NbVar){
g_pWeight[i] = 1;
//=== Compute Var Variances & Divide Weight by them
ForLoop (i, g_NbVar)
{
//=== Compute Average & Squared Sum
double Avr = 0.0,
SquaredSum = 0.0;
int NbNonMissingRow = 0;
TData MinV = 0.0, MaxV = 0.0;
BOOL First = TRUE;

ForLoop (j, g_NbRow)
{
TData Value = Mat(j, i);

if (Value == g_MissingValue)
}
//=== Compute Var Variances & Divide Weight by them
ForLoop (i, g_NbVar){
//=== Compute Average & Squared Sum
double Avr = 0.0,
SquaredSum = 0.0;
int NbNonMissingRow = 0;
TData MinV = 0.0, MaxV = 0.0;
BOOL First = TRUE;

ForLoop (j, g_NbRow){
TData Value = Mat(j, i);

if (Value == g_MissingValue){
continue;

if (First)
{
MinV = MaxV = Value;
First = FALSE;
}
else
{
MinV = Min(MinV, Value);
MaxV = Max(MaxV, Value);
}

++NbNonMissingRow;
Avr += Value;
SquaredSum += Squared(Value);
}

if (NbNonMissingRow)
{
Avr /= NbNonMissingRow;
SquaredSum /= NbNonMissingRow;
}
double Variance = SquaredSum - Squared(Avr);
if (Variance)
g_pWeight[i] /= Variance;

g_pMissingValueDist[i] = (TDist) (Squared(MaxV - MinV) * g_pWeight[i]);
}
if (First){
MinV = MaxV = Value;
First = FALSE;
}else{
MinV = Min(MinV, Value);
MaxV = Max(MaxV, Value);
}
++NbNonMissingRow;
Avr += Value;
SquaredSum += Squared(Value);
}

if (NbNonMissingRow){
Avr /= NbNonMissingRow;
SquaredSum /= NbNonMissingRow;
}
double Variance = SquaredSum - Squared(Avr);
if (Variance){
g_pWeight[i] /= Variance;
}
g_pMissingValueDist[i] = (TDist) (Squared(MaxV - MinV) * g_pWeight[i]);
}


//=== Build list of active Rows
ForLoop (i, g_NbRow-1)
ForLoop (i, g_NbRow-1){
pNextIndex[i] = i + 1;
}
pNextIndex[g_NbRow-1] = -1;

ForLoop (i, g_NbRow-1)
ForLoop (i, g_NbRow-1){
pPrevIndex[i+1] = i;
}
pPrevIndex[0] = -1;

//=== Core Loop: It always removes to groups of observations of size k therefore it has to stop, when only NbRowLeft-g_K*2>=g_K
Expand Down Expand Up @@ -192,8 +182,7 @@ RcppExport SEXP Mdav(SEXP data,SEXP data2,SEXP g_MissingValue_R,SEXP weights_R,S
AddRow(pCenter, pVar1, pNbNonMissingValue);
}

ForLoop (j, g_NbVar)
{
ForLoop (j, g_NbVar){
if (pNbNonMissingValue[j])
pCenter[j] /= pNbNonMissingValue[j];
else
Expand All @@ -206,8 +195,7 @@ RcppExport SEXP Mdav(SEXP data,SEXP data2,SEXP g_MissingValue_R,SEXP weights_R,S

// k = 0;

for (i = FirstIndex; i >= 0; i = pNextIndex[i])
{
for (i = FirstIndex; i >= 0; i = pNextIndex[i]){
ForLoop (ii, g_NbVar){
pVar1[ii]=Mat(i,ii);
}
Expand All @@ -221,13 +209,11 @@ RcppExport SEXP Mdav(SEXP data,SEXP data2,SEXP g_MissingValue_R,SEXP weights_R,S
// ASSERT(k == NbRowLeft);

// Find the K closest rows & average them, both from Farthest Row & Opposite Farthest Row
ForLoop (l, ngroups)
{
ForLoop (l, ngroups){
//=== Calculate Distances from Farthest Row
int Farthest = FirstIndex, Closest = FirstIndex;

for (i = FirstIndex; i >= 0; i = pNextIndex[i])
{
for (i = FirstIndex; i >= 0; i = pNextIndex[i]){
ForLoop (ii, g_NbVar){
pVar1[ii]=Mat(i,ii);
pVar2[ii]=Mat(CurrentFarthest,ii);
Expand All @@ -252,24 +238,21 @@ RcppExport SEXP Mdav(SEXP data,SEXP data2,SEXP g_MissingValue_R,SEXP weights_R,S

ClearMemV(HashList, -1);

for (i = FirstIndex; i >= 0; i = pNextIndex[i])
{
for (i = FirstIndex; i >= 0; i = pNextIndex[i]){
TDist Dist = pDist[i];
int HashIndex = (int) (es_NbHashListXX * (Dist - MinD) / DeltaD);

int Index = HashList[HashIndex];

if (Index >= 0 && pDist[Index] < Dist)
{
while (pNextInHash[Index] >= 0 && pDist[pNextInHash[Index]] < Dist)
if (Index >= 0 && pDist[Index] < Dist){
while (pNextInHash[Index] >= 0 && pDist[pNextInHash[Index]] < Dist){
Index = pNextInHash[Index];
}

int NextIndex = pNextInHash[Index];
pNextInHash[Index] = i;
pNextInHash[i] = NextIndex;
}
else
{
}else{
pNextInHash[i] = Index;
HashList[HashIndex] = i;
}
Expand All @@ -280,19 +263,16 @@ RcppExport SEXP Mdav(SEXP data,SEXP data2,SEXP g_MissingValue_R,SEXP weights_R,S
ClearMemT(pNbNonMissingValue, g_NbVar);
k = 0;

ForLoop (i, es_NbHashListXX)
{
ForLoop (i, es_NbHashListXX){
int Index = HashList[i];

while (Index >= 0)
{
while (Index >= 0){
ForLoop (ii, g_NbVar){
pVar1[ii]=Mat(Index,ii);
}
AddRow(pCenter, pVar1, pNbNonMissingValue);
++k;
if (k >= g_K)
{
if (k >= g_K){
i = es_NbHashListXX;
break;
}
Expand All @@ -301,8 +281,7 @@ RcppExport SEXP Mdav(SEXP data,SEXP data2,SEXP g_MissingValue_R,SEXP weights_R,S
}
}

ForLoop (j, g_NbVar)
{
ForLoop (j, g_NbVar){
if (pNbNonMissingValue[j])
pCenter[j] /= pNbNonMissingValue[j];
else
Expand All @@ -311,16 +290,14 @@ RcppExport SEXP Mdav(SEXP data,SEXP data2,SEXP g_MissingValue_R,SEXP weights_R,S

k = 0;

ForLoop (i, es_NbHashListXX)
{
ForLoop (i, es_NbHashListXX){
int Index = HashList[i];

while (Index >= 0)
{

ForLoop (j, g_NbVar)
Res(Index,j)=pCenter[j];
while (Index >= 0){

ForLoop (j, g_NbVar){
Res(Index,j)=pCenter[j];
}

//=== Remove from List
if (FirstIndex == Index)
Expand Down Expand Up @@ -365,18 +342,18 @@ RcppExport SEXP Mdav(SEXP data,SEXP data2,SEXP g_MissingValue_R,SEXP weights_R,S
++k;
}

ForLoop (j, g_NbVar)
{
if (pNbNonMissingValue[j])
ForLoop (j, g_NbVar){
if (pNbNonMissingValue[j]){
pCenter[j] /= NbRowLeft;
else
}else{
pCenter[j] = g_MissingValue;
}
}

for (i = FirstIndex; i >= 0; i = pNextIndex[i])
{
ForLoop (j, g_NbVar)
for (i = FirstIndex; i >= 0; i = pNextIndex[i]){
ForLoop (j, g_NbVar){
Res(i, j )=pCenter[j];
}
}
}
// /*funktionieren distanzen?!??!*/
Expand Down

0 comments on commit 01262f4

Please sign in to comment.