1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
RUDIKE [14]
2 years ago
12

Finally you will implement the full Pegasos algorithm. You will be given the same feature matrix and labels array as you were gi

ven in Full Perceptron Algorithm. You will also be given T , the maximum number of times that you should iterate through the feature matrix before terminating the algorithm. Initialize θ and θ0 to zero. For each update, set η=1t√ where t is a counter for the number of updates performed so far (between 1 and nT inclusive). This function should return a tuple in which the first element is the final value of θ and the second element is the value of θ0 . Note: Please call get_order(feature_matrix.shape[0]), and use the ordering to iterate the feature matrix in each iteration. The ordering is specified due to grading purpose. In practice, people typically just randomly shuffle indices to do stochastic optimization. Available Functions: You have access to the NumPy python library as np and pegasos_single_step_update which you have already implemented.
Engineering
1 answer:
Diano4ka-milaya [45]2 years ago
6 0

Answer:

In[7] def pegasos(feature_matrix, labels, T, L):

   """

   .

   let learning rate = 1/sqrt(t),

   where t is a counter for the number of updates performed so far       (between 1   and nT inclusive).

Args:

       feature_matrix - A numpy matrix describing the given data. Each row

           represents a single data point.

       labels - A numpy array where the kth element of the array is the

           correct classification of the kth row of the feature matrix.

       T -  the maximum number of times that you should iterate through the feature matrix before terminating the algorithm.

       L - The lamba valueto update the pegasos

   Returns: Is defined as a  tuple in which the first element is the final value of θ and the second element is the value of θ0

   """

   (nsamples, nfeatures) = feature_matrix.shape

   theta = np.zeros(nfeatures)

   theta_0 = 0

   count = 0

   for t in range(T):

       for i in get_order(nsamples):

           count += 1

           eta = 1.0 / np.sqrt(count)

           (theta, theta_0) = pegasos_single_step_update(

               feature_matrix[i], labels[i], L, eta, theta, theta_0)

   return (theta, theta_0)

In[7] (np.array([1-1/np.sqrt(2), 1-1/np.sqrt(2)]), 1)

Out[7] (array([0.29289322, 0.29289322]), 1)

In[8] feature_matrix = np.array([[1, 1], [1, 1]])

   labels = np.array([1, 1])

   T = 1

   L = 1

   exp_res = (np.array([1-1/np.sqrt(2), 1-1/np.sqrt(2)]), 1)

   

   pegasos(feature_matrix, labels, T, L)

Out[8] (array([0.29289322, 0.29289322]), 1.0)

Explanation:

In[7] def pegasos(feature_matrix, labels, T, L):

   """

   .

   let learning rate = 1/sqrt(t),

   where t is a counter for the number of updates performed so far       (between 1   and nT inclusive).

Args:

       feature_matrix - A numpy matrix describing the given data. Each row

           represents a single data point.

       labels - A numpy array where the kth element of the array is the

           correct classification of the kth row of the feature matrix.

       T -  the maximum number of times that you should iterate through the feature matrix before terminating the algorithm.

       L - The lamba valueto update the pegasos

   Returns: Is defined as a  tuple in which the first element is the final value of θ and the second element is the value of θ0

   """

   (nsamples, nfeatures) = feature_matrix.shape

   theta = np.zeros(nfeatures)

   theta_0 = 0

   count = 0

   for t in range(T):

       for i in get_order(nsamples):

           count += 1

           eta = 1.0 / np.sqrt(count)

           (theta, theta_0) = pegasos_single_step_update(

               feature_matrix[i], labels[i], L, eta, theta, theta_0)

   return (theta, theta_0)

In[7] (np.array([1-1/np.sqrt(2), 1-1/np.sqrt(2)]), 1)

Out[7] (array([0.29289322, 0.29289322]), 1)

In[8] feature_matrix = np.array([[1, 1], [1, 1]])

   labels = np.array([1, 1])

   T = 1

   L = 1

   exp_res = (np.array([1-1/np.sqrt(2), 1-1/np.sqrt(2)]), 1)

   

   pegasos(feature_matrix, labels, T, L)

Out[8] (array([0.29289322, 0.29289322]), 1.0)

You might be interested in
Working with which of these systems requires a technician that has been certified in an EPA-approved course?
makvit [3.9K]

EPA Regulations provides a certified course for the technicians involved in the Air-conditioning system.

Answer: Option (b)

<u>Explanation:</u>

The EPA regulation has implemented an act called the "Clean Air Act" under the "section of 609".

This act provides some basic requirements for EPA Regulation such as follows;

  • Refrigerant: This unit must be approved by EPA Regulations before being implemented into the atmosphere.
  • Servicing: This system provides a certified course for technicians in service and also approve them with proper refrigerant equipment.
  • Reuse Refrigerants: The use of recycled refrigerants must be properly monitored before it comes in to serve.
6 0
3 years ago
Define the coefficient of determination and discuss the impact you would expect it to have on your engineering decision-making b
scoundrel [369]

Answer and Explanation:

The coefficient of determination also called "goodness of fit" or R-squared(R²) is used in statistical measurements to understand the relationship between two variables such that changes in one variable affects the other. The level of relationship or the degree to which one affects the other is measured by 0 to 1 whereby 0 means no relationship at all and 1 means one totally affects the other while figures in between such 0.40 would mean one variable affects 40% of the other variable.

In making a decision as an engineer while using the coefficient of determination, one would try to understand the relationship between variables under consideration and make decisions based on figures obtained from calculating coefficient of determination. In other words when there is a 0 coefficient then there is no relationship between variables and an engineer would make his decisions with this in mind and vice versa.

7 0
3 years ago
Explain why the following scenario fails to meet the definition of a project description.
s344n2d4d5 [400]

Answer:

The youth hockey training facility

Explanation:

7 0
3 years ago
Almost all collisions are due to driver error
blondinia [14]

Answer:

Where's the questaion?

4 0
2 years ago
A good rule of thumb in hazardous conditions is to _____.
Aloiza [94]

Answer:

C. Have your hazard lights on

Explanation:

Speeding up will cause an accident

Counter steering is not easy to do

Slowing down my result in you being rear ended

5 0
2 years ago
Read 2 more answers
Other questions:
  • A converging-diverging nozzle is designed to operate with an exit Mach number of 1.75 . The nozzle is supplied from an air reser
    15·1 answer
  • From the following numbered list of characteristics, decide which pertain to (a) precipitation hardening, and which are displaye
    12·1 answer
  • For a heat pump, COP&lt;1. a) True b) False
    11·1 answer
  • A closed system undergoes a process in which work is done on the system and the heat transfer Q occurs only at temperature Tb. F
    8·1 answer
  • Use the orange points (square symbol) to plot the initial short-run industry supply curve when there are 20 firms in the market.
    5·1 answer
  • 8.2.1: Function pass by reference: Transforming coordinates. Define a function CoordTransform() that transforms the function's f
    8·1 answer
  • The Acme tool is aligned to the work with: A. A square B. The eye C. An Acme tool gage D. A center gage
    14·1 answer
  • Ratio equivalent to 12 red beans to 5 total beans
    15·1 answer
  • Lars is a medical coder. He works for a hospital in Wisconsin but currently lives in Georgia. Lars does his work online and over
    13·1 answer
  • Most equipment is cooled by bringing cold air in the front and ducting the heat out of the back. What is the term for where the
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!