BackProp Fixes
This commit is contained in:
parent
efbb09f8ba
commit
0542b7ba2e
11 changed files with 189 additions and 106 deletions
|
|
@ -1,14 +1,45 @@
|
|||
|
||||
#include "NewPlacement.hpp"
|
||||
|
||||
#include "FullyConnectedNN.hpp"
|
||||
#include "Testing.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static bool init(const tp::ModuleManifest* self) {
|
||||
tp::gTesting.setRootName(self->getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
void test() {}
|
||||
void test() {
|
||||
using namespace tp;
|
||||
|
||||
Buffer<halni> layers = { 4, 4, 3, 2 };
|
||||
Buffer<halnf> input = { (halnf) randomFloat() * 100, (halnf) randomFloat() * 100, (halnf) randomFloat() * 100, (halnf) randomFloat() * 100 };
|
||||
Buffer<halnf> outputExpected = { (halnf) randomFloat(), (halnf) randomFloat() };
|
||||
|
||||
FullyConnectedNN nn;
|
||||
Buffer<halnf> output(2);
|
||||
|
||||
nn.initializeRandom(layers);
|
||||
|
||||
// nn.mLayers.last().neurons.first().weights = { 0.35, 0.35, 0.35, 0.35 };
|
||||
// nn.mLayers.last().neurons.first().bias = 0.9;
|
||||
|
||||
// nn.mLayers.last().neurons.last().weights = { -0.35, -0.35, -0.35, -0.35 };
|
||||
// nn.mLayers.last().neurons.last().bias = -3.9;
|
||||
|
||||
for (auto i : Range(50)) {
|
||||
nn.evaluate(input, output);
|
||||
|
||||
auto lossBefore = nn.calcCost(outputExpected);
|
||||
|
||||
nn.calcGrad(outputExpected);
|
||||
nn.applyGrad(0.1);
|
||||
printf("Loss %f \n", lossBefore);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
tp::ModuleManifest* deps[] = { &tp::gModuleDataAnalysis, &tp::gModuleUtils, nullptr };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue