# An algorithm for endurance (question)

An algorithm for endurance (question)
0

#1

Hello freeCodeCampers! I have an algorithmic question relating to the world of endurance sports. Suppose you have these constraints:

• a limited amount of time to train per week (say 6-8 hours)
• A fixed distance and a time limit to train for (eg 112 miles 180km in a maximum of 10.5 hours ) on a bike
And the biggest factor of all is the catch 22
-if you are slow, it takes longer to train but if you are fast, you have “leftover” training time.
examples:
If I ride 14mph. It will take me 8 hours to complete the event.
but if I ride 20mph, it will only take me 5.5 hours to complete it. The slowest speed someone could complete the course in is about 10.5 mph.

I’m hunting for some algorithms to help generate training patterns based on my current bike speed/fitness, but don’t quite know what I’m looking for. Linear or some kind of AI?

What kind of algorithm am I looking to implement here?

#2

I’ve trained for marathons and have seen a lot of “20 week plans” on how to get ready, how many miles each week, what types of runs on which days, etc. It sounds like you need to do a lot of research and look at many of those kinds of plans (but for cycling) and see if you can infer some principles and rules of thumb. I know for the marathon training there were lots of rules of thumbs about training milestones for distance and speed depending on the distance and speed you wanted to race. I’m sure someone has done something similar for cycling. You need to do a lot of research. Someone may even have a spread sheet already done up that you would just need to translate to a web page.

#3

Thanks for the input. I don’t want to sound too boastful, but I have been coaching for over a decade and trained many for boston qualifiers, sub 3 hour marathons and kona world championships as well as training people for their first 5ks.

I’m not asking about how to make a training plan specifically, I’m asking about how to translate my intuition about training into an algorithm that’s going on in my head so I can create plans quickly for many different skill levels. I hope the distinction makes sense.

If I could describe it better I could probably make the problem easier but there are so many factors to consider I’m trying to simplify it. It’s not as easy as substituting X miles every weekend since the athletes pace impacts how long they will be training, and their experience impacts what intensities and pace changes they can handle.

Does that help?

#4

My suggestion is since you seem to have key knowledge in the area, you should document each step you would take to manually create such a training plan with the information you have. Once you can document all the manual steps, then you have a basic algorithm from which you write your code. Until you can break it down into basic steps, no one without your coaching experience is going to be able to help you more than likely. If you can come up with a solution, then you probably could create an app (\$\$\$) that athletes might use.

#5

I would start writing out some various plans and then try to fit a formulas to them there is a whole science of fitting formulas to data sets. And with a little research you may find that someone has already done it. Or look through training plans. As the target distance increases, how does the training distance? Does the length of time increase needed to train increase, etc? Just start putting numbers on the page and see what you come up with.

#6

I’ve tried many variations in that and the result ends up feeling lifeless, but maybe I’ll take another shot now that I’m further along in my coding skills.

Now I would like some great tips on learning jazz guitar!

#7

Right, but what I’m talking about is developing the formula, which is separate from coding. It won’t matter how good you are at coding if you aren’t sure what you want to code.

#8

I knew what you were referring to , and you’re right ,coding isn’t the right thing, i used that as an idea placeholder.

I have taken some courses in machine learning and it seems like this could be a good (simple?) project for it, but it could also be I am making it too complicated.

Creating a linear progression form “here” to “there” is really easy, even with in between shorter training events. But like I said those plans feel pretty stale to me. I know a good plan when I make one (which is usually after the athlete has completed his/her event with good results). And I have a ton saved, I’m just struggling with organizing all the data I do have and looking for any additional ideas that could help.

OK…how about some video of you playing jazz ??

#9

What is the output you’re hoping to get from this algorithm? I don’t know anything about endurance training.

#10

Well, if you’re getting into “machine learning” then that’s probably above the pay grade of a forum like this - devoted to web development, not artificial intelligence that can look at training regimes, outcomes, and generate algorithms to create ideal training plans. I’m sure there are guys that can do that, but that probably involves math and coding above our level, like “Money Ball” version of distance cycling training.

“But like I said those plans feel pretty stale to me” So, you want a human feel but want it made by a machine?

And who is your customer here? Presumably most of the people that would google your web page for a training planner are going to be hobbyists, so maybe more generic plans would be better anyway, that they can fit around their schedules. Lists, like “5 weeks before race - begin taper, do two medium distance days with x:xx pace and one long day at x:xx pace.” This would all be generated by the user input of distance of race distance and target finish time. You could generate a list of 10-15 week training ramp up and taper.

Start easy. Like the old saying goes, The perfect is the enemy of the good. As a musician, I see this all the time with new composers - they are paralyzed by fear that it won’t be perfect or that they could have made it better. Just start somewhere. You can always add to it later. If you modularize everything into functions, then it should be easy to upgrade. But start somewhere. Start small. Start imperfect. Fail fast and move on or improve.

Since you asked, there are some old clips of me playing on my old web site, kevinsmithguitar.com

#11

Thanks Kevin, that’s all great advice. I am always hoping that someone is lurking here that has a deeper background in comp sci and just came here for the “web dev” education.

I’ve just started to “study” improvisation on guitar and let me tell you…most of the time it’s UGLY but putting in the time to make mistakes and just keep moving forward, and i’ve already seen improvements…my partner even said that it “took him places” last night when I was playing last night.

Thanks for the links, your playing sounds great! Someday I hope I can sound half as good

#12

the output i want is a full training plan for multiple weeks with individual workouts specified, like what Kevin described just above in the last post.

#13

“I’ve just started to “study” improvisation on guitar and let me tell you…most of the time it’s UGLY but putting in the time to make mistakes and just keep moving forward, and i’ve already seen improvements…”

That’s the key. Just put in the time. I always tell my students that if you want to play good solos, you’ve got to play a lot of bad ones first. I always say, “You can’t learn to swim without swallowing a lot of pool water.” You can read all the books on swimming you can find, study all the theory, etc. But until you get in there and struggle for a bit, you’re never going to learn it. Theory can be a good thing, a great thing even, but it’s in the struggling to do that the real learning happens.