def test_single_train_hiddenWeights(self): self.assign_io_data() _neurons = 10 _mindSingle = Mindy(self.input, self.output, _neurons, 0.1) _feed = Feeder(_mindSingle) _feed.randomWeights() _feed.feedForward(_mindSingle.inputM, _mindSingle.outputM) _feed.feedBackwards(0.1) _mindSingle.train(10) self.assertEqual(_feed.hiddenOneWeights.shape, _feed.deltaHiddenChange.shape)
def test_single_error_oneLower(self): self.assign_io_data() _neurons = 10 _mindSingle = Mindy(self.input, self.output, _neurons, 0.1) _feed = Feeder(_mindSingle) _feed.randomWeights() _feed.feedForward(_mindSingle.inputM, _mindSingle.outputM) _feed.feedBackwards(0.1) _mindSingle.train(100) _errors = MindyErrors(_mindSingle) self.assertLess(_errors.modelError(), 1)
def test_single_randomWeights_hiddenWeights(self): self.assign_io_data() _neurons = 10 _mindSingle = Mindy(self.input, self.output, _neurons, 0.1) _feed = Feeder(_mindSingle) _feed.randomWeights() self.assertEqual(_neurons, len(_feed.hiddenOneWeights))
def test_single_pushForward_predictedOutput(self): self.assign_io_data() _neurons = 10 _mindSingle = Mindy(self.input, self.output, _neurons, 0.1) _feed = Feeder(_mindSingle) _feed.randomWeights() _feed.feedForward(_mindSingle.inputM, _mindSingle.outputM) self.assertEqual(_feed.predictedOutput.shape, self.output.shape)
def test_single_randomWeights_weightsMatrix(self): self.assign_io_data() _neurons = 10 _mindSingle = Mindy(self.input, self.output, _neurons, 0.1) _feed = Feeder(_mindSingle) _feed.randomWeights() self.assertEqual(_neurons * len(self.input.T), len(_feed.inputWeights) * len(_feed.inputWeights.T))
def test_single_outputSum_deltaOutputSum(self): self.assign_io_data() _neurons = 10 _mindSingle = Mindy(self.input, self.output, _neurons, 0.1) _feed = Feeder(_mindSingle) _feed.randomWeights() _feed.feedForward(_mindSingle.inputM, _mindSingle.outputM) _feed.feedBackwards(0.1) self.assertEqual(_feed.deltaOutputSum.shape, self.output.shape)
def test_single_inputLayerBackward_deltaInputChange(self): self.assign_io_data() _neurons = 10 _mindSingle = Mindy(self.input, self.output, _neurons, 0.1) _feed = Feeder(_mindSingle) _feed.randomWeights() _feed.feedForward(_mindSingle.inputM, _mindSingle.outputM) _feed.feedBackwards(0.1) self.assertEqual(_feed.deltaInputChange.shape, _feed.inputWeights.shape)
def test_computeNumericalGradient(self): self.assign_io_data() _neurons = 10 self.mindSingle = Mindy(self.input, self.output, _neurons, 0.1) self.computeNumericalGradient(1e-4, self.mindSingle.inputM, self.mindSingle.outputM) _numgrad = self.numgrad _grad = self.computeGradients() """VISUAL TEST. CHECK IF THE ARE ALMOST EQUAL""" print _numgrad print _grad
def test_ovrVsSingle(self): self.assign_io_data() #OVR _neurons = 20 _trainingIt = 1000 _mind = Mindy(self.inputM, self.outputM, _neurons, 0.1, multinomial='ovr') _mind.train(_trainingIt) _predictionObs = [1, 1, 1] #remember the bias beta_0 _i = 0 while _i < len(_mind.OVR.outputOvr.T): _outSingle = np.array(_mind.OVR.outputOvr[:, _i]) #Single _mindSingle = Mindy(self.inputM, _outSingle, _neurons, 0.1) _mindSingle.train(_trainingIt) if _i == 0: _singlePredict = _mindSingle.predict(_predictionObs) elif _i > 0: _addSinglePredict = _mindSingle.predict(_predictionObs) _addSinglePredict['Prediction'] = _i _singlePredict = np.hstack((_singlePredict, _addSinglePredict)) if len(_mind.OVR.outputOvr.T) < 3: raise ValueError( 'Doesnt make sense with less than three variabels') exit _i += 1 """VISUAL CONFIRMATION. TEST IF THERE ARE SIGNIFICANT CHANGES IN THE PREDICTIONS WHEN COMPARING OVR AND BIN""" #print sigmoid(np.dot(sigmoid(np.dot(self.inputM, _mindSingle.Feeder.inputWeights)), _mindSingle.Feeder.hiddenOneWeights)) print _singlePredict print '----------------------' print _mind.predict(_predictionObs)