Skip to content

Conversation

@pnavaro
Copy link
Contributor

@pnavaro pnavaro commented Dec 23, 2021

Remove numpy.repeat calls and use numpy.newaxis instead.

Bonjour Pierre, j'ai remarqué qu'il y avait un mauvais usage des fonctions numpy.repeat et numpy.newaxis

La différence de performance n'est pas significative car la valeur de k reste petite. Si k est plus grand cela peut être pénalisant.

k, n = 5, 4
A = np.random.random((k,n))
B = np.random.random(n)
print(A - np.repeat(B[np.newaxis],k,0))
array([[ 0.12257881, -0.6828793 ,  0.33842712,  0.11159255],
       [-0.14958673, -0.18297544, -0.08235108, -0.46120042],
       [ 0.16231505, -0.03759013, -0.41242646, -0.62449231],
       [ 0.23559006, -0.41247123,  0.18543247, -0.39231891],
       [-0.26883017, -0.22686467, -0.46624038, -0.06988904]])
print(A - B[np.newaxis,:]  )
array([[ 0.12257881, -0.6828793 ,  0.33842712,  0.11159255],
       [-0.14958673, -0.18297544, -0.08235108, -0.46120042],
       [ 0.16231505, -0.03759013, -0.41242646, -0.62449231],
       [ 0.23559006, -0.41247123,  0.18543247, -0.39231891],
       [-0.26883017, -0.22686467, -0.46624038, -0.06988904]])

Bonnes fêtes. Pierre.

Remove numpy.repeat calls and use numpy.newaxis instead
Suppress the warning for matplotlib in the notebook
@pnavaro
Copy link
Contributor Author

pnavaro commented Dec 23, 2021

  • J'ai corrigé le warning qui apparaissait dans le notebook.
  • J'ai remplacé les boucles dans le model forecasting par des vectorisations apply_along_axis. Normalement c'est plus rapide mais pas beaucoup finalement.

@pnavaro
Copy link
Contributor Author

pnavaro commented Dec 23, 2021

J'ai modifié des générations aléatoires en utilisant la classe RandomState . Maintenant la simulation est reproductible. Pour modifier les tirages il y a une variable optionnelle seed dans plusieurs fonctions.

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

Successfully merging this pull request may close these issues.

1 participant