Whoa. That is scary. But despite what others have said in this thread, you would NOT want to run in this situation. If this guy was intent on harming you, running would be the second worst thing you could have done. The worst thing you could do in this situation would be to turn around and say something like "shit man, back off!". The trick is you do NOT want to let them know that you're aware of their presence and intentions. That'll only make them panic and strike faster 'cuz they're pumped with adrenaline. In order to survive this situation, you have to do something much scarier than just run. You have to wait till they're about 1.5-2 feet away from you. By that time you'll know they're after you and they intend to cause harm. But at that same time, that's your last and only opportunity to defend yourself.
Unless the guy is totally crazy (which most people that commit these crimes aren't), he's gonna be nervous as hell 'cuz he's about to commit a crime. He's pumped full of adrenaline which makes his responses faster, but he's also not thinking clearly. You've gotta be faster than he is in this situation. Just turn around as fast as you can and grab the wrist that has the knife and HOLD ON for dear life 'cuz if he gets that free you're practically dead already. He'll most likely yell or make some other sort of distracting loud noise, but you can't let that make you lose your focus. You've got to grab onto the knife with your other hand and try to get it from him. If you can't get it within 1-2 seconds, punch him and try again. If you still can't get it, punch him till he collapses. By that time he probably won't be able to hold onto the knife anymore and you'll have it. Now what you do next is up to you. Personally I'd push his fatigued form over and stab him a couple of times in non-vital areas (shoulder, arms, etc.) 'cuz you don't want to kill the guy. Of course you could just keep punching him, but that doesn't nearly cause as much pain as stabbing and the more pain he's in, the easier it is to get away.
Of course if he's on some sort of drugs that take pain away you're gonna have to either kill him or knock him out. I'd try not to kill him personally but if he's super crazy and fighting back like hell just stab him where it'll cause the most damage. But the #1 thing to remember is that you shouldn't try to run till he's incapacitated! If he can still pursue, you'll most likely not win the second round.
The worst thing that can happen is to attack an innocent guy, but you won't get in much trouble for it. It was his own damned fault. You don't walk up to a single woman in the middle of the night with a knife in your hand!