Intro to Scipy Optimization: Minimize Method

Sdílet
Vložit
  • čas přidán 2. 08. 2024
  • In this video, I'll show you the bare minimum code you need to solve optimization problems using the scipy.optimize.minimize method.
    Install: pip3 install scipy
    Download Code: github.com/wynand1004/Project...
    scipy Link: docs.scipy.org/doc/scipy/refe...
    scipy.optimize.minimize Link: docs.scipy.org/doc/scipy/refe...
    LibreText Optimization Problem 4.7.1: math.libretexts.org/Bookshelv...
    NEED HELP?
    🆘 Watch this first and then let me know in the comments below: • Help Me Help You
    ❤️❤️ SHOW SOME LOVE AND SUPPORT THE CHANNEL ❤️❤️
    Click Join and Become a Channel Member Today!
    Channel members can get preferential comment replies, early access to new content, members only live streams, and access to my private Discord.
    ❤️ / @tokyoedtech
    Amazon Affiliate Links
    💻 My Laptop (Asus Zenbook 13): amzn.to/2H3DLbF
    🎙My New Microphone (Blue Yeti Pro): amzn.to/2HmjOgN
    🎙My Old Microphone (Blue Snowball): amzn.to/3j8magh
    🎶My USB Interface (Focusrite Scarlett Solo): amzn.to/3kqyo5m
    Other Affiliate Links
    ⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing. www.kite.com/get-kite/?...
    LINKS
    🗄️ GITHUB: github.com/wynand1004
    💬 Follow me on Twitter: / tokyoedtech
    📜 Subscribe to my Newsletter: eepurl.com/dKgM8k
    📝 Check out my Blog: christianthompson.com
    ⬇️ Download Geany Editor: www.geany.org
    LEARN MORE PYTHON
    ➡️Space Invaders: • Python Game Programmin...
    ➡️Snake Game: • Python Game Programmin...
    ➡️Pong: • Python Game Programmin...
    ➡️Space War: • Python Game Programmin...
    ➡️Intro to Python (for Java Coders): • Intro to Python for Ja...
    ➡️Space Arena - The Ultimate Python Turtle Graphics Game Tutorial: • Ultimate Python Turtle...
    LEARN MORE JAVA
    ➡️Basic Java for Beginners: • Basic Java 1&2: Commen...
    ➡️Intro to AP Computer Science A: • AP Computer Science Un...
    #Python #scipy #Optimize #Minimize
  • Věda a technologie

Komentáře • 60

  • @lencone
    @lencone Před 2 lety +1

    Thanks man, it was very comprehensive

  • @user-su1up4in6w
    @user-su1up4in6w Před 3 lety

    Many thanks!

  • @avanishparmessur5032
    @avanishparmessur5032 Před 11 měsíci +1

    thanks, this is pretty detailed

    • @TokyoEdTech
      @TokyoEdTech  Před 11 měsíci

      You're welcome - hope it comes in handy!

  • @EgmatXelugo
    @EgmatXelugo Před 2 lety +1

    THANK YOU !!!

    • @TokyoEdTech
      @TokyoEdTech  Před 2 lety

      You're welcome! I had to learn this for class - they just expected us to figure it out. Glad I could help.

  • @prashanths4455
    @prashanths4455 Před 2 lety +3

    thanks a lot man

  • @codingmadeeasy3126
    @codingmadeeasy3126 Před 3 lety +1

    You can also use manim the python library to visualise math and graphs. Also I think in f(x) you will have to integrate it with -infinite to positive infinite to make the calculation with more precision. Although I can be wrong since I am rusty with my integration skills..

    • @TokyoEdTech
      @TokyoEdTech  Před 3 lety +1

      I can't speak to the manim library but it sounds useful. EDIT: We need to take the derivative and solve for 0 to find the minimum. However, the scipy library is used for machine learning and it figures out the values using its own methods.

  • @rohitbuddabathina9225
    @rohitbuddabathina9225 Před 2 měsíci +1

    Very well explained. Thanks bro🤗

    • @TokyoEdTech
      @TokyoEdTech  Před 2 měsíci +1

      Cheers!

    • @rohitbuddabathina9225
      @rohitbuddabathina9225 Před 2 měsíci

      @@TokyoEdTech Hey, Is this video a part of any playlist? Do you have more videos on optimization?

    • @TokyoEdTech
      @TokyoEdTech  Před měsícem

      @@rohitbuddabathina9225 Sorry, this is the only one.

  • @excursion5246
    @excursion5246 Před rokem +1

    Thanks

  • @NtotheGMC
    @NtotheGMC Před 2 lety

    Hey is there a way to make it so that the values only use integers for x? For example with the fence: say you can only build 1 meter fence blocks.

    • @TokyoEdTech
      @TokyoEdTech  Před 2 lety

      Interesting question! I found this on StackOverflow: stackoverflow.com/a/47316508

  • @0alcoholism2
    @0alcoholism2 Před 3 lety

    Hey, love the video, just have one question. If I am returning multiple variables in a function that I want to minimize, how do I do that ?

    • @TokyoEdTech
      @TokyoEdTech  Před 3 lety +1

      I'm not sure how you'd go about that - there's probably a way, but I haven't tried it. This is really all I know about the subject. Sorry!

    • @0alcoholism2
      @0alcoholism2 Před 3 lety +1

      @@TokyoEdTech dont worry about it lol, I did find a work around tho. If I want to maximise one variable and minimize the other, I just set a separate variable which is the division of the maximised variable and the minimized one. then I maximize that new variable. I also include a print statement in the function to see the values of the 2 variables. To maximise or minimise 2 variables, I just add them and then do the same process.

    • @TokyoEdTech
      @TokyoEdTech  Před 3 lety +1

      Clever!

  • @RachelDance
    @RachelDance Před 3 lety

    Hi - I have a function with 6 inputs, 4 of which I want it to change values for optimisation (call them a,b,c,d), and the other two I need it to ignore, one of them is a simple scalar (t=0.01 say so i could set a bound of (0.01,0.01) to force it to have that value), but the other (X) is a huge list (its the y values of an xy plot, there are 100,000 values) so i cant simply set bounds for it like (1,1), as its an array. The function uses X and t, but I only want to change the a,b,c,d in maximising. How can i set this up so that it can ignore X and t? Its like, I only want to pass it guess values for *some* of the variables, but if I dont provide them all it will fall over right? Any help appreciated :D

    • @TokyoEdTech
      @TokyoEdTech  Před 3 lety

      That's a tough one - not 100% sure. Pretty much all I know is what I put in the video. The only thing you can try is to use lists for the variables that change and tuples for the ones that don't. Just a guess though. Good luck!

  • @mahtabyaghouti5446
    @mahtabyaghouti5446 Před rokem +1

    Hey, thank you! BTW do you know what is the name of the optimization method?

    • @TokyoEdTech
      @TokyoEdTech  Před rokem

      You're welcome. Sorry, not sure -it's probably in the documentation somewhere.

  • @kitchencrumb4031
    @kitchencrumb4031 Před 3 lety

    How/Can I use this library to make a 1/Y^2 line fitting?

    • @TokyoEdTech
      @TokyoEdTech  Před 3 lety

      I'm not really sure what you mean - I think what optimize does is finds the lowest result of an equation.

  • @trueresolute
    @trueresolute Před 3 lety

    hi, how can u minimize x**2 using Conjugate gradient method using above method?

    • @TokyoEdTech
      @TokyoEdTech  Před 3 lety

      I'm not sure how to set the method. The formula is easy, but check the docs for more info on choosing the method.

  • @miyirbek6821
    @miyirbek6821 Před 3 lety

    Hi Bro. I hope you are ok. Could make a video , which draws quadratic functions parabola.

    • @TokyoEdTech
      @TokyoEdTech  Před 3 lety +1

      Hi Mix. Sorry, I'm not 100% sure how to do that one myself - I'd use the matplotlib library. I have a video about it on my channel.

  • @superkb172
    @superkb172 Před 3 lety

    Good job, oh question, have you done a pacman remake?

    • @TokyoEdTech
      @TokyoEdTech  Před 3 lety

      Thanks. No Pacman yet, but one of my students modified my maze game tutorial into Pacman so that might be a good place to start.

    • @superkb172
      @superkb172 Před 3 lety

      @@TokyoEdTech interesting 🤔

  • @SaintcantfeintIIOKII
    @SaintcantfeintIIOKII Před 8 měsíci

    how do i remove the message" optimization successfull " mssg , i check on overstack and it told me to do disp="False"...but im thinking im doing it wrong...could someone help

    • @TokyoEdTech
      @TokyoEdTech  Před 8 měsíci

      Can you share all of your code and I'll take a look?

    • @SaintcantfeintIIOKII
      @SaintcantfeintIIOKII Před 8 měsíci +1

      @@TokyoEdTech nm i solved it ty

    • @TokyoEdTech
      @TokyoEdTech  Před 8 měsíci

      @@SaintcantfeintIIOKII Good to hear. What was the solution?

  • @mishka5169
    @mishka5169 Před 3 lety +1

    👍🏼👍🏼👍🏼

  • @yuyuan4593
    @yuyuan4593 Před 2 lety

    why minimize returns initial value sometime?

    • @TokyoEdTech
      @TokyoEdTech  Před 2 lety

      Not sure - maybe the initial value also happens to be the initial value?

  • @furkanyanmaz5190
    @furkanyanmaz5190 Před 3 lety

    Can you make a video about PyQt5?

    • @TokyoEdTech
      @TokyoEdTech  Před 3 lety

      I'm curious about that too, but I haven't tried it yet. Sorry.

  • @ewnetuabebe5059
    @ewnetuabebe5059 Před 2 lety

    What a bout newton method and steepest method for optimization

    • @TokyoEdTech
      @TokyoEdTech  Před 2 lety

      Not sure - check the documentation. There's lots in there!

  • @godzilla9289
    @godzilla9289 Před 2 lety

    what if you have three constraints? How to put them in the result?
    result = spo.minimize(f,xy_start, constraints = con1+con2+con3 ??????). or what?
    could you help me with that?

  • @raj345to
    @raj345to Před 5 měsíci

    you were maximizing area in the second problem but used minima

    • @TokyoEdTech
      @TokyoEdTech  Před 5 měsíci

      Yep. This is explained here: czcams.com/video/G0yP_TM-oag/video.htmlsi=f-_XBLyx_tZNaMeN&t=1111

  • @user-zj7cr2pg7c
    @user-zj7cr2pg7c Před 10 měsíci

    watched 2023.9.9