Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createHiddenLayerNetsForCount expect too small a number #1

Closed
emilianbold opened this issue Jan 6, 2018 · 8 comments
Closed

createHiddenLayerNetsForCount expect too small a number #1

emilianbold opened this issue Jan 6, 2018 · 8 comments

Comments

@emilianbold
Copy link

It seems to me RNN createHiddenLayerNetsForCount expects at most patterns[0].features.count.

If I use a bigger number the app crashes.

If I have a time series, the number of features is small so it seems to me this might be a reason why the network doesn't really converge and I get no predictions.

Of course, I might also be miss-using the library. I appreciate you making it public, I didn't have to try implement all of that!

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 3 beyond bounds [0 .. 2]'
*** First throw call stack:
(
	0   CoreFoundation                      0x0000000104a70b0b __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x00000001044d5141 objc_exception_throw + 48
	2   CoreFoundation                      0x00000001049a5ffb -[__NSArrayM objectAtIndex:] + 203
	3   RNN                                 0x0000000103593b40 -[RNNMath sumMatrix:anotherMatrix:] + 448
	4   RNN                                 0x00000001035954cd -[RNNNet outputWithInputs:recurrentOutputs:] + 205
	5   RNN                                 0x000000010358ca28 __37-[RNN(Training) forwardWithFeatures:]_block_invoke.47 + 120
	6   CoreFoundation                      0x0000000104a01652 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 114
	7   CoreFoundation                      0x0000000104a014e2 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 194
	8   RNN                                 0x000000010358c511 -[RNN(Training) forwardWithFeatures:] + 721
	9   RNN                                 0x000000010358cdeb -[RNN(Training) trainingWithPattern:] + 187
	10  RNN                                 0x000000010358ea12 __30-[RNN(Training) startTraining]_block_invoke + 114
	11  CoreFoundation                      0x0000000104a01652 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 114
	12  CoreFoundation                      0x0000000104a014e2 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 194
	13  RNN                                 0x000000010358e5ae -[RNN(Training) startTraining] + 478
	14  RNN                                 0x0000000103590521 -[RNN trainingWithCompletion:] + 113
	15  RNN                                 0x0000000103590674 -[RNN trainingWithIteration:completion:] + 132
@Kalvar
Copy link
Owner

Kalvar commented Jan 7, 2018 via email

@emilianbold
Copy link
Author

Looks to me like the code expects that the number of cells in the hidden layer must be smaller than the number of cells in the input layer. While I assumed I could increase that number to, perhaps, get better results.

In your iOS-RNN sample file, if I replace this line with [rnn createHiddenLayerNetsForCount:40] I also get the same crash:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 36 beyond bounds [0 .. 35]'

I need to tweak some parameters and I assumed that besides convergenceError, learningRate, maxIteration, randomMax and randomMin I could also tweak the number in createHiddenLayerNetsForCount. Is this incorrect?

My code is here: https://github.com/emilianbold/glucosio-ios/blob/recurrent-neural-network/glucosio/Classes/Controller/Editors/GLUCReadingEditorViewController.m#L257

For simple data (straight line) the network does train, but not for the (semi-random?) test data I'm using. It might be a case of garbage-in garbage-out.

The series 'looks' simple and the training and predictions are way off:

line

@Kalvar
Copy link
Owner

Kalvar commented Jan 9, 2018

Please check the condition of forloop: for(int i = chunkSize; i < vals.count; i++){}, it won't be working on first time that i=7 and valus.count is 7 too. Hence, the patterns will be empty, then crashed.

@emilianbold
Copy link
Author

Please note I'm able to crash your own example from https://github.com/Kalvar/ios-RNN/tree/master/ios-RNN by just changing [rnn createHiddenLayerNetsForCount:18] to [rnn createHiddenLayerNetsForCount:40] in ViewController.m.

So, I sense there's something deeper here.

Indeed, there's a small bug (the shame...) when chunkSize == number of train items, but the test data has alway been higher, so I didn't run into that.

@Kalvar
Copy link
Owner

Kalvar commented Jan 9, 2018

Okay, got your question, I'm checking now.

@Kalvar
Copy link
Owner

Kalvar commented Jan 9, 2018

It is a bug yes, I will fix it.

@Kalvar
Copy link
Owner

Kalvar commented Jan 9, 2018

Fixed createHiddenLayerNetsForCount crash bug. (Updated RNN version to 1.1)

@emilianbold
Copy link
Author

This fixes the createHiddenLayerNetsForCount bug for me (and for ios-RNN).

I'm going to close this issue.

I still don't see good convergence for my time series data. Would appreciate any hints you have for time series prediction using your library. I'm thinking about implementing a LSTM myself...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants