how to use @every in FOR loop

36 views
Skip to first unread message

morteza eskandarian

unread,
May 15, 2019, 10:12:13 AM5/15/19
to ANNarchy
hi. is there any way to use @every in FOR loop ?
this is my code :
for epoch_number in range(number_of_epoch):
# load network data
# load('train_save.data')
# if Non_MFCC:
# random.shuffle(inputs_name)
# else:
# random.shuffle(real_input_name)

# train network for this epoch
reset()

@every(period=time_for_each_input)
def set_input(n):
# noise = np.random.normal(0, 1, number_of_input_neuron)
if Non_MFCC:

# shuffling the original inputs name list

# read file name for train data
file_name = inputs_name[n]
# file_name = 'train_data/' + file_name
file_data = open(file_name, 'r')

# save order of file and label of file for SVM
input_order.append(file_name)
label_list.append(int(file_name[-5:-4])) # 11:12

# ready the file for reading
big_list = []
for i in range(frame_number):
temp_list = list(file_data.readline())

while ' ' in temp_list:
temp_list.remove(' ')
while '\n' in temp_list:
temp_list.remove('\n')
while '\r' in temp_list:
temp_list.remove('\r')
big_list.extend(list(map(int, temp_list)))
input_data = np.array(big_list)
else:
real_file_name = real_input_name[n]
# real_data = 'TRAIN_data/' + real_file_name
label_list.append(int(real_file_name[-5:-4])) # 11:12

(sample_rate, MFCC_signal) = wav.read(real_file_name)
mfcc_feat = mfcc(signal=MFCC_signal, samplerate=sample_rate, winlen=0.025, winstep=0.01, numcep=13,
nfilt=26, nfft=512, lowfreq=0, highfreq=None, preemph=0.97, ceplifter=22,
appendEnergy=True)
input_data = np.array(mfcc_feat).flatten()

if len(input_data) < number_of_input_neuron:
input_data = np.concatenate((input_data, np.zeros([number_of_input_neuron - len(input_data)])))

input_data = input_data.reshape([number_of_input_neuron, 1])

# maximum_length.append(np.array(MFCC_feat).flatten().size)
input_train_svm.append(np.array(input_data).flatten())

for repeat in range(num_of_repeat):
# pop.i_offset = [30.0] * number_of_input_neuron
# step()
pop_real_input.i_offset = input_data
step()
# pop.i_offset = [0.0] * number_of_input_neuron
pop_real_input.i_offset = np.zeros_like(input_data)
print(n)

simulate(number_of_input * time_for_each_input)


i use @every in order to repeat network in each epoch, but i get this error

TypeError: '<' not supported between instances of 'every' and 'every'

For the first run in FOR loop @every works fine, but for next run sends me the error that mentioned above

Julien Vitay

unread,
May 15, 2019, 2:39:02 PM5/15/19
to ANNarchy
The bug is fixed in the master branch.

But the problem with callbacks added inside the for loop is that they are not deleted. The first epoch, one callback is called at each desired step, the second epoch two callbacks, etc. In your case they seem to do the same, but this could lead to problems, for example if each callback increments some variables.

I added a method `clear_all_callbacks()` that can be called at the beginning of each epoch to clear the active callbacks (beware: they are gone forever).

One hint: callbacks only work when calling simulate(). Your calls to step() at the end of the callback will not affect the periodicity of the callback (t=0 is at the beginning of simulate() ). 

morteza eskandarian

unread,
May 18, 2019, 9:59:52 AM5/18/19
to ANNarchy
I have a question that are the debugged functions exist in the last version of annarchy.  
I have updated all packages and called the function clear_all_callbacks() but it doesn't work and returns the NameError: name 'clear_all_callbacks' is not defined error. I wanted to know is there any other way to use the a simulation function like @every in a for loop? 

Julien Vitay

unread,
May 18, 2019, 11:00:30 AM5/18/19
to morteza eskandarian, ANNarchy
Did you reinstall with pip or from source? The new method is not on pip yet.

--
You received this message because you are subscribed to the Google Groups "ANNarchy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to annarchy+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/annarchy/17edd02f-fdc9-4836-985b-82f1597d8221%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

morteza eskandarian

unread,
May 20, 2019, 1:16:28 AM5/20/19
to ANNarchy
I update annarchy In pycharm. As you know pip command has used for updating and reinstalling in pycharm. If I want install annarchy with git, is there necessary I remove annarchy in pip befor it and install that with git? Or is there possible I install and use annarchy with git when annarchy has installed with pip.
To unsubscribe from this group and stop receiving emails from it, send an email to anna...@googlegroups.com.

Julien Vitay

unread,
May 20, 2019, 2:08:43 AM5/20/19
to morteza eskandarian, ANNarchy
yes, you first need to remove the ANNarchy version installed with pip, before installing from source (or with pip install git+https://bitbucket.org/annarchy/annarchy.git if you really want to use pip), as they may be installed in different paths.

To unsubscribe from this group and stop receiving emails from it, send an email to annarchy+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/annarchy/1436f42f-c3ea-46a6-bbca-cd95495fa042%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
Professur Künstliche Intelligenz 
Fakultät für Informatik 

Technische Universität Chemnitz
Straße der Nationen 62 | R. 1/348 (neu: A12.348) 
09111 Chemnitz Germany


Reply all
Reply to author
Forward
0 new messages