Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
818afb9
included xxhash.h
adi-sharma Jun 23, 2016
db6990f
added hashing initializations
adi-sharma Jun 24, 2016
efa2efb
added weightBucket
adi-sharma Jun 24, 2016
c821a57
edited applyWeights() without drop-out as an example
adi-sharma Jun 28, 2016
b6328a7
Updated all applyWeights() with HashedNets
adi-sharma Jul 1, 2016
a58ac1d
Update NeuralNet.h
adi-sharma Jul 1, 2016
c81f248
updated update() and Steepest Gradient Descent
adi-sharma Jul 1, 2016
96c8f42
Updated SGD operator() with HashedNets
adi-sharma Jul 1, 2016
0250775
updated weightDecay()
adi-sharma Jul 1, 2016
7c62f3b
updated weightDecay() with HashedNets
adi-sharma Jul 1, 2016
fe93bb2
Edited dropOutWeightFactor()
adi-sharma Jul 13, 2016
13d151a
Edited dropOutWeightFactor()
adi-sharma Jul 13, 2016
725bba3
Updated with HashedNets
adi-sharma Jul 18, 2016
4ec8917
Updated train() with HashedNets
adi-sharma Jul 18, 2016
b1caf73
Updated with complete HashedNets
adi-sharma Aug 23, 2016
c696958
Updated with complete HashedNets
adi-sharma Aug 23, 2016
8d6b2d4
Updated with Complete HashedNets
adi-sharma Aug 23, 2016
e277c73
Update MethodDNN.h
adi-sharma Aug 23, 2016
a820db6
Update NeuralNet.h
adi-sharma Aug 23, 2016
919a319
Updated with HashedNets
adi-sharma Aug 23, 2016
4d9e46c
Error corrections
adi-sharma Aug 24, 2016
3d7eec3
Error corrections NeuralNet.icc
adi-sharma Aug 24, 2016
d202ae1
Error corrections MethodDNN.cxx
adi-sharma Aug 24, 2016
52dc851
Successful compile
adi-sharma Aug 25, 2016
70484aa
Successful compile
adi-sharma Aug 25, 2016
6a0932f
Successful compile
adi-sharma Aug 25, 2016
4f5b919
Successful compile
adi-sharma Aug 25, 2016
96b29df
Successful build NeuralNet.h
adi-sharma Aug 25, 2016
f301784
Successful build NeuralNet.icc
adi-sharma Aug 25, 2016
9f1dce5
Successful build NeuralNet.cxx
adi-sharma Aug 25, 2016
f5e6943
Update NeuralNet.icc
adi-sharma Aug 26, 2016
c4f8749
Update NeuralNet.h
adi-sharma Aug 26, 2016
9637a69
Update MethodDNN.cxx
adi-sharma Aug 26, 2016
f62fcf2
Update NeuralNet.cxx
adi-sharma Aug 26, 2016
e48d24f
Made some logical changes in HashedNets
adi-sharma Aug 27, 2016
2bf3295
Made some logical changes in HashedNets
adi-sharma Aug 27, 2016
e048347
Update NeuralNet.icc
adi-sharma Aug 28, 2016
24c19c2
Production version v1.0
adi-sharma Aug 28, 2016
3c7f7ac
Production Version v1.0
adi-sharma Aug 28, 2016
e6332d5
Production Version v1.0
adi-sharma Aug 28, 2016
5c33612
Production Version v1.0
adi-sharma Aug 28, 2016
6eed664
Production Version v1.0
adi-sharma Aug 28, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated with HashedNets
  • Loading branch information
adi-sharma authored Jul 18, 2016
commit 725bba3c7c7c119be27fdde8628563edadd43d32
103 changes: 52 additions & 51 deletions tmva/tmva/inc/TMVA/NeuralNet.icc
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ namespace TMVA
*
* itDrop correlates with itSourceBegin
*/
template <typename ItSource, typename ItWeight, typename ItTarget, typename ItDrop>
template <typename ItSource, typename ItTarget, typename ItDrop>
void applyWeights (ItSource itSourceBegin, ItSource itSourceEnd,
int weightIndex, std::vector<double>& weightBucket,
int itWeight, std::vector<double>& weightBucket,
ItTarget itTargetBegin, ItTarget itTargetEnd,
ItDrop itDrop)
{
Expand All @@ -100,8 +100,8 @@ namespace TMVA
for (auto itTarget = itTargetBegin; itTarget != itTargetEnd; ++itTarget)
{
if (*itDrop)
(*itTarget) += (*itSource) * (weightBucket[XXH32(seed, weightIndex) % BUCKET_SIZE]);
++weightIndex;
(*itTarget) += (*itSource) * (weightBucket[XXH32(seed, itWeight) % BUCKET_SIZE]);
++itWeight;
}
++itDrop;
}
Expand All @@ -113,17 +113,17 @@ namespace TMVA
*
*
*/
template <typename ItSource, typename ItWeight, typename ItTarget>
template <typename ItSource, typename ItTarget>
void applyWeights (ItSource itSourceBegin, ItSource itSourceEnd,
int weightIndex, std::vector<double>& weightBucket,
int itWeight, std::vector<double>& weightBucket,
ItTarget itTargetBegin, ItTarget itTargetEnd)
{
for (auto itSource = itSourceBegin; itSource != itSourceEnd; ++itSource)
{
for (auto itTarget = itTargetBegin; itTarget != itTargetEnd; ++itTarget)
{
(*itTarget) += (*itSource) * (weightBucket[XXH32(seed, weightIndex) % BUCKET_SIZE]);
++weightIndex;
(*itTarget) += (*itSource) * (weightBucket[XXH32(seed, itWeight) % BUCKET_SIZE]);
++itWeight;
}
}
}
Expand All @@ -135,17 +135,17 @@ namespace TMVA
*
*
*/
template <typename ItSource, typename ItWeight, typename ItPrev>
template <typename ItSource, typename ItPrev>
void applyWeightsBackwards (ItSource itCurrBegin, ItSource itCurrEnd,
int weightIndex, std::vector<double>& weightBucket,
int itWeight, std::vector<double>& weightBucket,
ItPrev itPrevBegin, ItPrev itPrevEnd)
{
for (auto itPrev = itPrevBegin; itPrev != itPrevEnd; ++itPrev)
{
for (auto itCurr = itCurrBegin; itCurr != itCurrEnd; ++itCurr)
{
(*itPrev) += (*itCurr) * (weightBucket[XXH32(seed, weightIndex) % BUCKET_SIZE]);
++weightIndex;
(*itPrev) += (*itCurr) * (weightBucket[XXH32(seed, itWeight) % BUCKET_SIZE]);
++itWeight;
}
}
}
Expand All @@ -156,9 +156,9 @@ namespace TMVA
*
* itDrop correlates with itPrev (to be in agreement with "applyWeights" where it correlates with itSources (same node as itTarget here in applyBackwards)
*/
template <typename ItSource, typename ItWeight, typename ItPrev, typename ItDrop>
template <typename ItSource, typename ItPrev, typename ItDrop>
void applyWeightsBackwards (ItSource itCurrBegin, ItSource itCurrEnd,
int weightIndex, std::vector<double>& weightBucket,
int itWeight, std::vector<double>& weightBucket,
ItPrev itPrevBegin, ItPrev itPrevEnd,
ItDrop itDrop)
{
Expand All @@ -167,8 +167,8 @@ namespace TMVA
for (auto itCurr = itCurrBegin; itCurr != itCurrEnd; ++itCurr)
{
if (*itDrop)
(*itPrev) += (*itCurr) * (weightBucket[XXH32(seed, weightIndex) % BUCKET_SIZE]);
++weightIndex;
(*itPrev) += (*itCurr) * (weightBucket[XXH32(seed, itWeight) % BUCKET_SIZE]);
++itWeight;
}
++itDrop;
}
Expand Down Expand Up @@ -200,16 +200,16 @@ namespace TMVA
*
*
*/
template <typename ItValue, typename Fnc, typename InvFnc, typename ItGradient>
void applyFunctions (ItValue itValue, ItValue itValueEnd, Fnc fnc, InvFnc invFnc, ItGradient itGradient)
template <typename ItValue, typename Fnc, typename InvFnc>
void applyFunctions (ItValue itValue, ItValue itValueEnd, Fnc fnc, InvFnc invFnc, int itGradient, std::vector<double>& gradientBucket)
{
while (itValue != itValueEnd)
{
auto& value = (*itValue);
value = (*fnc.get ()) (value);
(*itGradient) = (*invFnc.get ()) (value);
(gradientBucket[XXH32(seed, itGradient) % BUCKET_SIZE]) = (*invFnc.get ()) (value);

++itValue; ++itGradient;
++itValue; ++gradientIndex;
}
}

Expand All @@ -221,17 +221,18 @@ namespace TMVA
*/
template <typename ItSource, typename ItDelta, typename ItTargetGradient, typename ItGradient>
void update (ItSource itSource, ItSource itSourceEnd,
ItDelta itTargetDeltaBegin, ItDelta itTargetDeltaEnd,
ItTargetGradient itTargetGradientBegin,
ItGradient itGradient)
int itTargetDeltaBegin, int itTargetDeltaEnd,
int itTargetGradientBegin,
int itGradient,
std::vector<double>& gradientBucket)
{
while (itSource != itSourceEnd)
{
auto itTargetDelta = itTargetDeltaBegin;
auto itTargetGradient = itTargetGradientBegin;
while (itTargetDelta != itTargetDeltaEnd)
int itTargetDelta = itTargetDeltaBegin;
int itTargetGradient = itTargetGradientBegin;
while (targetDeltaIndex != targetDeltaEnd)
{
(*itGradient) += - (*itTargetDelta) * (*itSource) * (*itTargetGradient);
(gradientBucket[XXH32(seed, itGradient) % BUCKET_SIZE]) += - (gradientBucket[XXH32(seed, itTargetDelta) % BUCKET_SIZE]) * (*itSource) * (gradientBucket[XXH32(seed, itTargetGradient) % BUCKET_SIZE]);
++itTargetDelta; ++itTargetGradient; ++itGradient;
}
++itSource;
Expand Down Expand Up @@ -278,7 +279,7 @@ namespace TMVA
ItDelta itTargetDeltaBegin, ItDelta itTargetDeltaEnd,
ItTargetGradient itTargetGradientBegin,
ItGradient itGradient,
int weightIndex, std::vector<double>& weightBucket, double weightDecay)
int itWeight, std::vector<double>& weightBucket, double weightDecay)
{
// ! the factor weightDecay has to be already scaled by 1/n where n is the number of weights
while (itSource != itSourceEnd)
Expand All @@ -287,8 +288,8 @@ namespace TMVA
auto itTargetGradient = itTargetGradientBegin;
while (itTargetDelta != itTargetDeltaEnd)
{
(*itGradient) -= + (*itTargetDelta) * (*itSource) * (*itTargetGradient) + computeRegularization<Regularization>(weightBucket[XXH32(seed, weightIndex) % BUCKET_SIZE],weightDecay);
++itTargetDelta; ++itTargetGradient; ++itGradient; ++weightIndex;
(*itGradient) -= + (*itTargetDelta) * (*itSource) * (*itTargetGradient) + computeRegularization<Regularization>(weightBucket[XXH32(seed, itWeight) % BUCKET_SIZE],weightDecay);
++itTargetDelta; ++itTargetGradient; ++itGradient; ++itWeight;
}
++itSource;
}
Expand All @@ -307,7 +308,7 @@ namespace TMVA
*
* Can be used with multithreading (i.e. "HogWild!" style); see call in trainCycle
*/
template <typename Function, typename Weights, typename PassThrough>
template <typename Function, typename PassThrough>
double Steepest::operator() (Function& fitnessFunction, int currLayerWeightIndex, int nextLayerWeightIndex, std::vector<double>& weightBucket, PassThrough& passThrough)
{
size_t numWeights = nextLayerWeightIndex - currLayerWeightIndex + 1;
Expand All @@ -318,7 +319,7 @@ namespace TMVA
if (m_prevGradients.size () != numWeights)
{
m_prevGradients.clear ();
m_prevGradients.assign (nextLayerWeightIndex - currLayerWeightIndex + 1, 0);
m_prevGradients.assign (numWeights, 0);
}

bool success = true;
Expand All @@ -334,15 +335,15 @@ namespace TMVA
// apply momentum before computing the new gradient
auto itPrevG = begin (m_prevGradients);
auto itPrevGEnd = end (m_prevGradients);
int locWeightIndex = currLayerWeightIndex;
int itLocWeight = currLayerWeightIndex;
for (; itPrevG != itPrevGEnd; ++itPrevG)
{
(*itPrevG) *= m_beta;
(localWeightBucket[XXH32(seed, locWeightIndex) % BUCKET_SIZE]) += (*itPrevG);
++locWeightIndex;
(localWeightBucket[XXH32(seed, itLocWeight) % BUCKET_SIZE]) += (*itPrevG);
++itLocWeight;
}

E = fitnessFunction (passThrough, localWeights, gradients);
E = fitnessFunction (passThrough, localWeights, gradients); //************** Edit this later ***************
// plotGradients (gradients);

double alpha = gaussDouble (m_alpha, m_alpha/2.0);
Expand Down Expand Up @@ -371,19 +372,19 @@ namespace TMVA
{
m_alpha /= 2;
std::cout << "\nlearning rate reduced to " << m_alpha << std::endl;
std::for_each (weights.begin (), weights.end (), [maxGrad](double& w)
std::for_each (weights.begin(), weights.end(), [maxGrad](double& w) //************ Edit this later ***************
{
w /= maxGrad;
});
m_prevGradients.clear ();
}
else
{
int weightIndex = currLayerWeightIndex;
std::for_each (std::begin (gradients), std::end (gradients), [&weightIndex](double& g)
int itWeight = currLayerWeightIndex;
std::for_each (std::begin (gradients), std::end (gradients), [&itWeight](double& g)
{
weightBucket[XXH32(seed, weightIndex) % BUCKET_SIZE] += g;
++weightIndex;
weightBucket[XXH32(seed, itWeight) % BUCKET_SIZE] += g;
++itWeight;
});
}

Expand Down Expand Up @@ -537,10 +538,10 @@ namespace TMVA
// weight decay (regularization)
double w = 0;
size_t n = 0;
int weightIndex;
for (weightIndex = currLayerWeightIndex; weightIndex != nextLayerWeightIndex; ++weightIndex, ++n)
int itWeight;
for (itWeight = currLayerWeightIndex; itWeight != nextLayerWeightIndex; ++itWeight, ++n)
{
double weight = (weightBucket[XXH32(seed, weightIndex) % BUCKET_SIZE]);
double weight = (weightBucket[XXH32(seed, itWeight) % BUCKET_SIZE]);
w += std::fabs (weight);
}
return error + 0.5 * w * factorWeightDecay / n;
Expand All @@ -550,9 +551,9 @@ namespace TMVA
// weight decay (regularization)
double w = 0;
size_t n = 0;
for (weightIndex = currLayerWeightIndex; weightIndex != nextLayerWeightIndex; ++weightIndex, ++n)
for (itWeight = currLayerWeightIndex; itWeight != nextLayerWeightIndex; ++itWeight, ++n)
{
double weight = (weightBucket[XXH32(seed, weightIndex) % BUCKET_SIZE]);
double weight = (weightBucket[XXH32(seed, itWeight) % BUCKET_SIZE]);
w += weight*weight;
}
return error + 0.5 * w * factorWeightDecay / n;
Expand All @@ -570,7 +571,7 @@ namespace TMVA




// ********* Edit this later ***************



Expand Down Expand Up @@ -707,7 +708,7 @@ namespace TMVA
if (drops.empty () || weights.empty ()) //Edit this later. *****************
return;

int weightIndex = currLayerWeightIndex;
int itWeight = currLayerWeightIndex;
auto itDrop = std::begin (drops);
auto itDropEnd = std::end (drops);
size_t numNodesPrev = inputSize ();
Expand All @@ -733,11 +734,11 @@ namespace TMVA
size_t _numWeights = layer.numWeights (numNodesPrev);
for (size_t iWeight = 0; iWeight < _numWeights; ++iWeight)
{
if (weightIndex == nextLayerWeightIndex)
if (itWeight == nextLayerWeightIndex)
break;

*(weightBucket[XXH32(seed, weightIndex) % BUCKET_SIZE]) *= p;
++weightIndex;
*(weightBucket[XXH32(seed, itWeight) % BUCKET_SIZE]) *= p;
++itWeight;
}
numNodesPrev = numNodes;
dropFractionPrev = dropFraction;
Expand Down