2. Optimization Problems

Поділитися
Вставка
  • Опубліковано 30 вер 2024
  • MIT 6.0002 Introduction to Computational Thinking and Data Science, Fall 2016
    View the complete course: ocw.mit.edu/6-0...
    Instructor: John Guttag
    Prof. Guttag explains dynamic programming and shows some applications of the process.
    License: Creative Commons BY-NC-SA
    More information at ocw.mit.edu/terms
    More courses at ocw.mit.edu

КОМЕНТАРІ • 98

  • @ElVerdaderoAbejorro
    @ElVerdaderoAbejorro 7 років тому +46

    The part about the origin of the name "dynamic programming" was hilarious! \o/ Thank you, professor, for going the extra mile and researching that for us. =D

  • @aidenigelson9826
    @aidenigelson9826 3 роки тому +5

    Can someone please explain the recursive procedure in maxval? Especially in the withVal and withtoTake and the opposites of the two? How is it actually exploring the tree? When does it check between withVal and withoutVal

    • @velzer9340
      @velzer9340 2 роки тому +1

      13:35 - withVal and withoutVal appear only in case when it isn't obvious what branch should we choose. Line 69: let's see what is the best achievable result if item X is taken. We call our function with updated list toConsider (without item X) and avail (restriction) decreased by the cost of item X. Respectively, for withoutVal. Eventually, toConsider list will be empty, and the function will return (0, ()). That corresponds to a decision made in a leaf, there are no alternatives. Knowing that the program can determine what decision to make in the last series of nods above leaves. It gives results to the upper level and so on. My explanation is very messy, sorry.
      Line 75: compare consequences of taking and not taking (withVal and withoutVal) and return the best. The function returns the best possible value and a tuple of taken items for given items and a restriction.
      Please, ask questions if you have some.

    • @nataliee7872
      @nataliee7872 Рік тому

      @@velzer9340 Thanks for the explanation. Can you please also explain what is the point of variables with_to_take and without_to_take? I didn't quite understand what they represent.

  • @manojnirmal9294
    @manojnirmal9294 3 роки тому +5

    Wonderful lecture and I learned a lot. In the accompanying Python code the lists for values and calories are missing an element. They have 8 elements each while the names list has 9 (See 15:03).

    • @ArunKumar-yb2jn
      @ArunKumar-yb2jn 3 роки тому

      This was identified by many commentators in Lecture 1 as well. It's a mistake.

  • @ramind10001
    @ramind10001 5 років тому +24

    I believe Eric Grimson, Ana Bell and JohnGuttag are one of the best lecturers at MIT.

  • @leixun
    @leixun 4 роки тому +20

    *My takeaways:*
    1. Pros and Cons in greedy algorithm 1:05
    2. Brute force algorithm implementation using search tree 2:08
    - Brute force algorithm is not efficient to compute, but dynamic programming can help with it 23:30

    • @aidenigelson9826
      @aidenigelson9826 3 роки тому

      Can you please explain to me how the recursive procedure works in maxval? I don't fully understand withval and withoutval and the withtak and without take.

    • @amolizm
      @amolizm Рік тому

      bro is not enjoying the show

  • @jacobsonokoro2173
    @jacobsonokoro2173 4 роки тому +15

    One of the courses that I can say changed my life.

  • @JamesJon1187
    @JamesJon1187 3 роки тому +8

    I love how he always looks like he's possibly trying to suppress a laugh. What an awesome guy!!

  • @nickskiadas7338
    @nickskiadas7338 4 роки тому +3

    Is there any possible way to find an indicative solution to problem set 1?

  • @bjaniak102
    @bjaniak102 5 років тому +3

    Does anyone know where i can find solution to The 'Roll-over' optimization problem which was included at the end of the lecture's slides?

  • @ArunKumar-yb2jn
    @ArunKumar-yb2jn 3 роки тому +1

    Code explanations must be greedy.

  • @duanas6409
    @duanas6409 Рік тому +1

    In case you don't have the math background, the number of nodes is 2^(n+1)-1 (as @kev92 says) and you get it by using the geometric progression formula and adjusting the indexes en.wikipedia.org/wiki/Geometric_progression#Derivation

  • @anonviewerciv
    @anonviewerciv 4 роки тому +1

    Buzzwords = government funding. (25:00)
    31:31 Memoization.

  • @HibsMax
    @HibsMax 3 роки тому +1

    A little bit late to the party, but at 6:36 it seems like the calorie values are messed up. If we're using the same code as before, beer should be 154 instead of 145. Also, Beer+Pizza+Burger cannot be the same as Beer+Pizza, but they both have 766 calories. I think it should be: 766, 412*, 508, 154*, 612, 258, 354, 0 (* = wrong).
    The answer should be Beer and Burger.

  • @nassimhaddam7136
    @nassimhaddam7136 7 років тому +5

    where to find the assigned readings he talked about at the end of the lecture?

    • @Syncromatic
      @Syncromatic 7 років тому +2

      You can check the MIT OCW page for the course (in the description). The book is "Introduction to computation and programming using python:"

    • @nassimhaddam7136
      @nassimhaddam7136 7 років тому +1

      Thanks. I'll check it.

  • @kev9220
    @kev9220 5 років тому +3

    Min 9.17 shouldn't the number of nodes be when there are n items: 2^(n+1) - 1 ?

    • @DenCato
      @DenCato 5 років тому +5

      The -1 is correct but it is irrelevant in Big-O notation.
      Big-O looks at the expense of the algorithm when n gets larger and larger. If n jumps from 100 to 1000, that -1 is really insignificant.

    • @chickenicecream1942
      @chickenicecream1942 4 роки тому +1

      Conclusion: Don't look up answers on Wikipedia xD

  • @pauloflores637
    @pauloflores637 6 років тому +4

    Awesome! I've got really suprised with fast fibonacci's speed. Great job!

  • @monffy58
    @monffy58 7 років тому +23

    I watched this course after 6.006, I have to say Dr John's course is much easier to understand, this one has a lot of vivid examples. Maybe I'm not smart enough to follow 6.006 and 6.046 well, but this course is really detailed and good for most people to learn.

    • @MrRandompersondude1
      @MrRandompersondude1 7 років тому +14

      This is an introductory course, whereas in introduction to Algorithms, the word introduction is somewhat misleading because it is intended for students that have some pre-existing experience in CS.

  • @McAwesomeReaper
    @McAwesomeReaper Рік тому

    Why are there 9 names in the set, but only 8 values and calories? Don't like Cake?

  • @SinCityGT3
    @SinCityGT3 7 років тому +9

    Great lecture! Thank you for uploading these. I don't agree at all with using try/except though. The Professors reason was that it's fewer lines of code... but it's actually more. This is much easier to read and looks better...
    if n in memo:
    return memo[n]
    memo[n] = fib(n-1, memo) + fib(n-2, memo)
    return memo[n]

    • @akshay.m10
      @akshay.m10 7 років тому +3

      python programmers have a practice called "Its easier to ask forgiveness than permission" which means its easier to write try/except rather than writing C/C++ style if-else checks. So follow along

    • @SinCityGT3
      @SinCityGT3 7 років тому +1

      Thanks for pointing that out. I looked into it. For others following along, this is done because if you say, "if n in memo
      return memo[n]" the item has to be looked up twice in the dictionary.
      I'm hesitant to follow along blindly with their style though, they are using getters and setters.

    • @atlantis_expedition_member4747
      @atlantis_expedition_member4747 7 років тому +2

      I'm with you on this one. To me, the python practice "akshay m" referred to does not have anything to do with this. This to my eyes, is uglier than the if statement method.
      Also, looking up a dictionary is a constant operation isn't it?
      So no harm in doing it as much as I like.

    • @Elite7555
      @Elite7555 2 роки тому

      @@akshay.m10 The thing is, he commits two sins: he uses Exceptions as normal part of the control flow, and then he even returns from the `except` clause, both of which are terrible code smell, regardless of programming language. I am a great fan of these lectures, but this is a terrible way to teach coding. He should use the `dict.get()` method, which returns `None`. He may think his solution to be "cleaner", but it is also slower. Exceptions are expensive.

  • @pfever
    @pfever 5 років тому +5

    My favorite instructor for this course!

  • @nikitasid4947
    @nikitasid4947 5 років тому +2

    Correction (6 years after taking the course i have a correction!) regarding mutable arguments in the function's signature (31:44) - don't do that. Well known problem in Python, google for more info.

    • @sarthakbindal7660
      @sarthakbindal7660 5 років тому

      But the course was taught in Fall 2016 :p. Which course were you talking about ?..

    • @sithembelogabela1271
      @sithembelogabela1271 5 років тому +1

      @@sarthakbindal7660 probably same course different year.

    • @LaughingShinoo
      @LaughingShinoo 4 роки тому +1

      It’s not a “problem in Python”. It’s expected behavior, which happens to be unknown for most people. Also, in this specific example it doesn’t hurt, at most it’ll be faster across re-executions..

  • @Pasora
    @Pasora 3 роки тому +6

    At 33:02 on line 129 of the code, it should return n instead of 1 because if it returns 1 you will be calculating one step more than what you asked for. fib(5) should return 5 but the code will return you 8 which is fib(6).

    • @NazriB
      @NazriB 2 роки тому

      Lies again? Oil Petrol

  • @letitrot9547
    @letitrot9547 4 роки тому +3

    Thank you! I'm glad I can take this course

  • @stephenadams2397
    @stephenadams2397 4 роки тому +1

    A beer in the knapsack is worth 2 in the bush.

  • @alute5532
    @alute5532 Рік тому

    18:00
    "Every Node is a legal solution to the problem"
    But is it better than the Best? If yes it becomes new best why ?
    In search tree don't actually build a tree
    By this trick ( backtrack) to beep track of results
    Is it hopeless, no ans Rand Corp
    Dynamic programmingr
    Oxnard bellman
    Why it didn't mean anything
    Issue computation seem grow faster than results
    Fob 3 calculated in many places
    We can store it!
    Dictionary
    Memoization find optimal solution
    If that's possibl3, we have optimal substructure (when globally optimal solution can be found
    How combines optimal solutions with, to local sub problems
    Crucial note dynamic programming won't help us for sorting
    Braids optimal soution
    Q what about other overlapping sub-problems
    Is there a repetition? (solving same solution?)
    If no overlap exist (clean solution by dynamic programming is possible
    I.e. run on knapsack
    Note zero speed up (why?)
    If each node the problems are different (in knapsack, things to consider) knapsack is a set (duplicate solution is highly possible
    Check have same problem to solve more than once
    Why:
    Solve same problem despite making different decisions (paths)
    How
    Modify max val, to use a memo:
    To use a 1 add third argument
    1. Add a third argument :initially
    Empty dict
    Key memo: a tuple (items left, available weight)
    As items Left are in a list (heap or stack?)
    Represent it by how long it is (length)
    (by how long your list is)
    Computational complexity hcan be very subtle notion
    Run time fastMaxVal governed by
    Distinct pairs(available, to consider)
    Number value consider - small (bound by item's value )
    Value (weight available) is hard
    Bounded by number of distinct (weight sums)
    It's about combinations, ways I can add up the units (750 call it's either that or lower)
    Practical problems can be optimization ones
    Optimal solution is exponentially hard (quadratic equation type)
    Subproblem
    Solution always correct
    Right circumstances: Fast
    Dynamic always give a good result

  • @jinruifoo7087
    @jinruifoo7087 3 роки тому +1

    can anyone explain the withval and withtotake portion?

  • @mawkuri5496
    @mawkuri5496 2 місяці тому

    please upload new 6.100b 😅

  • @shobhamourya8396
    @shobhamourya8396 5 років тому +1

    @21:00 For reproducible random numbers seed(int) function is used in R

  • @masterchief1520
    @masterchief1520 5 років тому +3

    I also wanted audience reactions . XD

  • @kemalware4912
    @kemalware4912 Рік тому

    THIS IS FUCKIN GREAT. Thanks sir.

  • @ebateru
    @ebateru 3 роки тому +3

    Awesome lecture once again. I wonder what is it with these students at MIT? They don't laugh at all and there are some good jokes being thrown at them.

  • @MrSinalta
    @MrSinalta 3 роки тому

    Hi !
    Regarding the fast fib function , I don’t get how the dict memo is updated bottom to top as it is assigned new value only inside function . Is because of the fact dict is mutable ?

    • @Elite7555
      @Elite7555 2 роки тому

      It is. All objects are passed by reference.

  • @RyanScarbrough
    @RyanScarbrough Рік тому

    I fear no functions, but that maxVal recursive function, it scares me.

    • @RyanScarbrough
      @RyanScarbrough Рік тому

      3 days later and I finally understand the gist of it. xD

  • @carlosfonseca143
    @carlosfonseca143 7 років тому +1

    how is the value for each item determine?

  • @nathanielsabanski3882
    @nathanielsabanski3882 5 років тому +1

    lol exceptions for flow control.... performance hit

    • @aulonsal423
      @aulonsal423 4 роки тому +3

      Not a performance hit in python, I think.

    • @gmorf33
      @gmorf33 4 роки тому

      Try/except is the norm in python.

  • @pandasstory
    @pandasstory 6 років тому +1

    Amazing lecture, thanks!

  • @EOh-ew2qf
    @EOh-ew2qf 3 роки тому

    hehe his jokes are too cute and funny

  • @isbestlizard
    @isbestlizard 4 роки тому

    MEMOISATION! i know this because erik told me in 6.006!

    • @isbestlizard
      @isbestlizard 4 роки тому

      yessssssss i was right!

    • @isbestlizard
      @isbestlizard 4 роки тому

      hmm what if instead of storing an exact result for a memoisation you just added it as training data for a ML model and then once you had enough stuff 'memoised' started inferencing it to speed hmmm

  • @hdsmsmart
    @hdsmsmart 3 роки тому

    Thanks MIT OCW and Dr John Guttag !!!

  • @katiec5524
    @katiec5524 3 роки тому

    That "Kernal died" made me laugh

  • @notagain3732
    @notagain3732 2 роки тому

    Im glad i found this

  • @forheuristiclifeksh7836
    @forheuristiclifeksh7836 11 місяців тому

    44:34

  • @quocvu9847
    @quocvu9847 Рік тому

    34:33

  • @khumoyunakhmedov4562
    @khumoyunakhmedov4562 7 років тому +1

    good lecture

  • @akbarrauf2741
    @akbarrauf2741 7 років тому +1

    thanks,mit

  • @jeremyward9363
    @jeremyward9363 6 років тому +4

    camel case python .....

  • @javierurena3367
    @javierurena3367 3 роки тому +1

    Didn't know Flanders was so cultivated in the field of Computation and Data Science

  • @marco.nascimento
    @marco.nascimento 5 років тому

    Amazing lecture

  • @FelipeArayaable
    @FelipeArayaable 4 роки тому +1

    The code he wrote in the first place it is a bit inefficient anyways, for example the fib function could have been solved with a simple for loop and it would have been as fast as his Fastfib function, but less complicated, ignoring this, I love John Guttag, he explains beautifully and very clear.

    • @lcsjr70
      @lcsjr70 4 роки тому +2

      But the point was to explain dynamic programming

  • @ALiJ4LIFE
    @ALiJ4LIFE 4 роки тому

    40:45

  • @ДжонКонэр
    @ДжонКонэр Рік тому

    Great lecture! I hope that all Ukrainians, regardless of age, will be able to study at US universities. 🙌🥰

  • @abdulhamidyusuf2848
    @abdulhamidyusuf2848 5 років тому

    33:00 he waited a clap guys and you made him disappointed😅

  • @anonviewerciv
    @anonviewerciv 4 роки тому

    1:11 There's a movie the students probably haven't heard of.

  • @Steven-lh5dx
    @Steven-lh5dx 5 років тому

    清晰简介,优美的讲解,致敬

  • @lowhertzhighspl
    @lowhertzhighspl 7 років тому +1

    Getting to the root of the matter..
    - plays at 06:50 mark -
    The professor says something similar to, "I don't know why these are drawn upside down."
    With all due respect, maybe it's not the "tree" that's upside down, your interpretation is. Again, getting to the to the ROOT of the matter.
    Perception is not only interesting, it's everything. Just ask Einstein.

    • @mathematicalcoffee2750
      @mathematicalcoffee2750 7 років тому +1

      Brandon Lee Except trees actually do have a top and bottom if you go outside

  • @davidjames1684
    @davidjames1684 3 роки тому

    To do the same thing over and over is wasteful. Oh really? How about taking a dump, breathing, brushing your teeth, sleeping, having sex, eating....? Stupid statement. He treats his students like seals/sea lions... when they do/say something right, he throws them a "fish"/prize.

  • @davidjames1684
    @davidjames1684 3 роки тому

    How can he not know what 2 ^ 64 is? I am glad I don't have him as a teacher.