Untitled
unknown
plain_text
2 years ago
1.2 kB
15
Indexable
// STUDENT TODO: IMPLEMENT
double NeuralNetwork::contribute(int nodeId, const double& y, const double& p) {
double incomingContribution = 0;
double outgoingContribution = 0;
NodeInfo* currNode = nodes.at(nodeId);
// find each incoming contribution, and contribute to the nodes outgoing weights
// If the node is already found, use its precomputed contribution from the contributions map
for (auto& c : adjacencyList.at(nodeId)) {
int neighbor = c.first;
Connection& connection = c.second;
if (contributions.find(neighbor) == contributions.end())
contributions.insert(make_pair(neighbor, contribute(neighbor, y, p)));
incomingContribution = contributions.at(neighbor);
visitContributeNeighbor(connection, incomingContribution, outgoingContribution);
// cout << nodeId << " Weight Delta After: " << c.second.delta << endl;
}
if (adjacencyList.at(nodeId).empty()) {
// base case, we are at the end
outgoingContribution = -1 * ((y - p) / (p * (1 - p)));
}
// Now contribute to yourself and prepare the outgoing contribution
visitContributeNode(nodeId, outgoingContribution);
return outgoingContribution;
}Editor is loading...
Leave a Comment