Multiplication of gradient

In the gradient descent intro we have:

def upd():
    global a_guess, b_guess
    
    # make a prediction using the current weights
    y_pred = lin(a_guess, b_guess, x)
    
    # calculate the derivate of the loss
    dydb = 2 * (y_pred - y)
    dyda = x*dydb
    
    # update our weights by moving in direction of steepest descent
    a_guess -= lr*dyda.mean()
    b_guess -= lr*dydb.mean()
  1. But I don’t understand fully dyda, why does partial derivative with respect to a multiply x by dydb? We aren’t calcuating full derivative and I don’t think this is case of chain rule.

  2. In the case of more than 2 dimensions, would we still be using .mean() to decide greatest descent?

For the first question. You have that the partial derivative of the difference between label and output of the model wrt b is 2*(y_pred-y), or equivalently 2*(b + a x - y). If you take the partial derivative wrt a, you get 2* x*(b + a x - y), which is indeed x * dy/db.

1 Like
  1. When you take the derivate of your cost function according to b, you have \frac{\partial{L}}{\partial{b}} = 2 \times (y_{pred} - y). And according to a, you have \frac{\partial{L}}{\partial{a}} = 2 \times x \times (y_{pred} - y)

  2. Usually, I saw dydb and dyda computed with a dot product, with something like dyda = (2/n_samples)* np.dot(x.T, (y_pred - y)) and dybd = (2/n_samples)*np.dot(np.ones((1,n_samples)), (y_pred-y))
    So they infer from the shape of your parameters. If you do this dot product, you can generalize to more parameters, without using the mean().

1 Like

Re 2: How is # of samples relevant at all here ? Why is it coming into picture?

The 1/n_samples is there to replicate the results of the lesson (I assume the loss function is more Mean Squared Error than Sum of Squared Error then). And the n_sample sized vector in the dydb is to get the correct shape of biases (if you look closely in the lin() function, even if b is an integer, it is summed to all 30 a*x values, it is called broadcasting)

1 Like

Thanks for update and quick reply. I’ll be sure to keep an eye on this thread. Looking for the same info.

MyCCPay Login

Exercise - Create a flow for sending emails when a new item is created in Power Automate

This exercise is written to use the Cronus sample company from the US version of Business Central. You might need to make adjustments to the steps if you use the sample company from your country or region.

Scenario

You are the Sales Manager at CRONUS. You want to improve the information workflow about new items created in Dynamics 365 Business Central. You want to get a notification, every time someone at CROUNS creates a new item with FURNITURE as the item category code.

Since you want to be notified by email and you are not a developer, you decide to make this automation with a flow in Power Automate.

Tasks

  1. Start Power Automate.
  2. Create the trigger based on Business Central data.
  3. Collect data from Business Central.
  4. Make the condition.
  5. Create an action based on the condition.
  6. Save the flow.

Steps

  1. Start Power Automate.
  2. Open in your browser.
  3. Click +Create in the left menu.
  4. Select the Automated flow tile.
  5. Create the trigger based on Business Central data.
  6. In the Flow name box, enter Email notification for new furniture.
  7. In the Choose your flow’s trigger enter business central.
  8. Scroll down and view the triggers and select the When a record is created (Business Central) trigger.
  9. Select the Create button.
  10. Enter the following information about the trigger.
    1. In the Environment name box, enter PRODUCTION.
    2. In the Company name box, select the CRONUS company from the list.
    3. In the Table name box, select items.
  11. Select +New step.
  12. Collect data from Business Central.
  13. In the Choose an action window, in the Search connectors and actions box, type business central.
  14. Select the Business Central connection. Select the Get record (Business Central) action.
  15. In the Environment name box, enter PRODUCTION.
  16. In the Company name box, select the CRONUS company from the list.
  17. In the Table name box, select items.
  18. In the Row id box, select the Row Id token from Dynamic content.
  19. Make the condition.
  20. In the Choose an action window, select Control.
  21. Select the Condition action.
  22. In the first Choose a value box, select the itemCategoryCode token from Dynamic content.
  23. Keep the is equal to option.
  24. In the second Choose a value box, enter a value of FURNITURE.
  25. Create an action based on the condition.
  26. In the left condition window If yes (with green bar), select Add an action.
  27. In the Choose an action window, in the Search connectors and actions box, type office 365 outlook.
  28. Select the Office 365 Outlook connection.
  29. Select the Send an email action.
  30. In the To box, enter your email address.
  31. In the Subject box, enter New furniture released.
  32. In the Body box, enter the following:
    1. Add the text New furniture.
    2. Add the token Number from Dynamic content.
    3. Add the text -.
    4. Add the token displayName from Dynamic content.
    5. Add the text with the unit price.
    6. Add the token unitPrice from Dynamic content.
    7. Add the text has just released.
  33. Save the flow.
  34. Select the Save command.

visual studio net training courses malaysia