Skip to content

Commit

Permalink
elabprate of calcylationg correlation defrivatives. (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio Jerez committed Nov 3, 2023
1 parent 38b78ed commit 4ce1903
Showing 1 changed file with 114 additions and 30 deletions.
144 changes: 114 additions & 30 deletions newton-4.00/sdk/dBrain/ndBrainLayerConvolutional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ void ndBrainLayerConvolutional::Debug(ndInt32 width, ndInt32 height, ndInt32 cha
}
ndTrace(("\n"));
}
ndTrace(("\n"));
}
ndTrace(("b(%d)\n", filter));
ndTrace(("\n"));
Expand All @@ -336,28 +335,56 @@ void ndBrainLayerConvolutional::Debug(ndInt32 width, ndInt32 height, ndInt32 cha
int outputHeight = height - filterSize + 1;

// print outputs
//ndTrace(("\n"));
//for (ndInt32 filter = 0; filter < filterCount; ++filter)
//{
// for (ndInt32 y = 0; y < outputWidth; ++y)
// {
// for (ndInt32 x = 0; x < outputHeight; ++x)
// {
// ndTrace(("y(%d,%d,%d) ", filter, y, x));
// }
// ndTrace(("\n"));
// }
// ndTrace(("\n"));
// //ndTrace(("b(%d)\n\n", filter));
//}

// print convolutions outputs
ndTrace(("\n"));
for (ndInt32 filter = 0; filter < filterCount; ++filter)
{
for (ndInt32 y = 0; y < outputWidth; ++y)
for (ndInt32 y0 = 0; y0 < outputHeight; ++y0)
{
for (ndInt32 x = 0; x < outputHeight; ++x)
for (ndInt32 x0 = 0; x0 < outputWidth; ++x0)
{
ndTrace(("y(%d,%d,%d) ", filter, y, x));
ndTrace(("y(%d,%d,%d)=\n", filter, y0, x0));
for (ndInt32 channel = 0; channel < channels; ++channel)
{
for (ndInt32 y = 0; y < filterSize; ++y)
{
ndTrace((" "));
for (ndInt32 x = 0; x < filterSize; ++x)
{
ndTrace(("x(%d,%d,%d) * w(%d,%d,%d,%d) + ", channel, y0 + y, x0 + x, filter, channel, y, x));
}
ndTrace(("\n"));
}
}
ndTrace((" b(%d)\n", filter));
ndTrace(("\n"));
}
ndTrace(("\n"));
}
ndTrace(("\n"));
//ndTrace(("b(%d)\n\n", filter));
//ndTrace(("\n"));
}

ndTrace(("\n"));
ndInt32 index = 0;
for (ndInt32 filter = 0; filter < filterCount; ++filter)
{
for (ndInt32 y = 0; y < outputWidth; ++y)
for (ndInt32 y = 0; y < outputHeight; ++y)
{
for (ndInt32 x = 0; x < outputHeight; ++x)
for (ndInt32 x = 0; x < outputWidth; ++x)
{
ndTrace(("z(%d) = g(y(%d,%d,%d))\n", index, filter, y, x));
index++;
Expand All @@ -370,10 +397,10 @@ void ndBrainLayerConvolutional::Debug(ndInt32 width, ndInt32 height, ndInt32 cha
index = 0;
for (ndInt32 filter = 0; filter < filterCount; ++filter)
{
for (ndInt32 y = 0; y < outputWidth; ++y)
for (ndInt32 y = 0; y < outputHeight; ++y)
{
ndTrace((" "));
for (ndInt32 x = 0; x < outputHeight; ++x)
for (ndInt32 x = 0; x < outputWidth; ++x)
{
ndTrace(("1/2 * (z(%d) - k(%d))^2 + ", index, index));
index++;
Expand All @@ -383,35 +410,92 @@ void ndBrainLayerConvolutional::Debug(ndInt32 width, ndInt32 height, ndInt32 cha
}
ndTrace(("\n"));

// print convolutions

ndTrace(("\n"));
ndTrace(("d(L2)/d(w) =\n"));
index = 0;
for (ndInt32 filter = 0; filter < filterCount; ++filter)
{
for (ndInt32 y0 = 0; y0 < outputWidth; ++y0)
for (ndInt32 y = 0; y < outputHeight; ++y)
{
for (ndInt32 x0 = 0; x0 < outputHeight; ++x0)
ndTrace((" "));
for (ndInt32 x = 0; x < outputWidth; ++x)
{
ndTrace(("y(%d,%d,%d)=\n", filter, y0, x0));
for (ndInt32 channel = 0; channel < channels; ++channel)
{
for (ndInt32 y = 0; y < filterSize; ++y)
{
ndTrace((" "));
for (ndInt32 x = 0; x < filterSize; ++x)
{
ndTrace(("x(%d,%d,%d) * w(%d,%d,%d,%d) + ", channel, y0 + y, x0 + x, filter, channel, y, x));
}
ndTrace(("\n"));
}
}
//ndTrace((" b(%d)\n", filter));
ndTrace(("\n"));
ndTrace(("(z(%d) - k(%d) * d(z(%d))/d(w) + ", index, index));
index++;
}
ndTrace(("\n"));
}
ndTrace(("\n"));
}
ndTrace(("\n"));


ndTrace(("\n"));
ndTrace(("d(L2)/d(w) =\n"));
index = 0;
for (ndInt32 filter = 0; filter < filterCount; ++filter)
{
for (ndInt32 y = 0; y < outputHeight; ++y)
{
ndTrace((" "));
for (ndInt32 x = 0; x < outputWidth; ++x)
{
ndTrace(("l(%d) * d(z(%d))/d(w) + ", index, index));ndTrace(("l(%d) * d(z(%d))/d(w) + ", index, index));
index++;
}
ndTrace(("\n"));
}
}
ndTrace(("\n"));



ndTrace(("\n"));
ndTrace(("d(L2)/d(w) =\n"));
index = 0;
for (ndInt32 filter = 0; filter < filterCount; ++filter)
{
for (ndInt32 y = 0; y < outputHeight; ++y)
{
ndTrace((" "));
for (ndInt32 x = 0; x < outputWidth; ++x)
{
//ndTrace(("z(%d) = g(y(%d,%d,%d))\n", index, filter, y, x));
//ndTrace(("l(%d) * d(z(%d))/d(w) + ", index, index));
ndTrace(("l(%d) * d(g(y(%d,%d,%d)))/d(w) + ", index, filter, y, x));
index++;
}
ndTrace(("\n"));
}
}
ndTrace(("\n"));


ndTrace(("\n"));
ndTrace(("d(L2)/d(w) =\n"));
index = 0;
for (ndInt32 filter = 0; filter < filterCount; ++filter)
{
for (ndInt32 y = 0; y < outputHeight; ++y)
{
ndTrace((" "));
for (ndInt32 x = 0; x < outputWidth; ++x)
{
//ndTrace(("l(%d) * d(z(%d))/d(w) + ", index, index));
//ndTrace(("z(%d) = g(y(%d,%d,%d))\n", index, filter, y, x));
//ndTrace(("l(%d) * d(g(y(%d,%d,%d)))/d(w) + ", index, filter, y, x));
ndTrace(("l(%d) * d(g(y(%d,%d,%d)))/d(y(%d,%d,%d)) * d(y(%d,%d,%d))/d(w) +\n", index, filter, y, x, filter, y, x, filter, y, x));
ndTrace((" "));
index++;
}
ndTrace(("\n"));
}
}
ndTrace(("\n"));


// print weight gradients
ndTrace(("\n"));
for (ndInt32 filter = 0; filter < filterCount; ++filter)
{
for (ndInt32 channel = 0; channel < channels; ++channel)
Expand Down

0 comments on commit 4ce1903

Please sign in to comment.