I wholly agree with Szulc and Guni.
I for one have come to a strong belief that the very first thing you gotta have to start from to write any piece of music is INSPIRATION. There is yet another way to compose - just come up with an interesting harmony - say take a fancy chord progression with lots of alterations, modulations, substitutions etc, impose a wave-shaped melody line upon our pervertible background and wait for what comes out. Is this music that comes close from your heart? Never! As I'm professional programmer I once gave birth to a software intended for automating this process. Guess what I said when I listened to this "masterpiece". Nothing polite nor ear-friendly
What one needs to write music is inspiration or at least a strong urge to create something beautiful (or maybe ugly and revolting).
Let math and music co-exit not interchange. Anyways, if anyone succeeds in creating mathimatical model (neural network or something else) wrapping up music creation proccess I will be the first to contribute to the development of this project

Listen to your soul!
Very best regards and loads of inspiration to all of you!
Zatz