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]
3 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]3 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
ANSWER FAST PLEASE!!! WILL MARK BRAINLIEST!!!!!!
Phoenix [80]

Answer:

Phuong works on a research project and creates a report for her boss.

5 0
3 years ago
Read 2 more answers
A segment of four-lane freeway (two lanes in each direction) has a 3% upgrade that is 1500 ft long followed by a 1000-ft 4% upgr
Dennis_Churaev [7]

Answer:

The level of service of of compound grade freeway is LOSB.

Explanation:

Find the provided attachments for explanation

3 0
4 years ago
The welding method that requires the operator to observe and only make corrections is
SVEN [57.7K]
Automatic manual semiautomatic
3 0
3 years ago
Read 2 more answers
Type the correct answer in the box. Spell all words correctly. Mike is constructing a project in which he uses a motor. How can
tankabanditka [31]
If it is. DC, direct current reverse the polarity of power leads on the motor.

If it is a 3 phase ac alternating current, reverse any of the two of three leads.

Disconnect power before attempting.
6 0
3 years ago
A circular hoop sits in a stream of water, oriented perpendicular to the current. If the area of the hoop is doubled, the flux (
natka813 [3]

Answer:

The flux (volume of water per unit time) through the hoop will also double.

Explanation:

The flux = volume of water per unit time = flow rate of water through the hoop.

The Flow rate of water through the hoop is proportional to the area of the hoop, and the velocity of the water through the hoop.

This means that

Flow rate = AV

where A is the area of the hoop

V is the velocity of the water through the hoop

This flow rate = volume of water per unit time = Δv/Δt =Q

From all the above statements, we can say

Q = AV

From the equation, if we double the area, and the velocity of the stream of water through the hoop does not change, then, the volume of water per unit time will also double or we can say increases by a factor of 2

3 0
4 years ago
Other questions:
  • 1. Create a class called Name that represents a person's name. The class should have fields named firstName representing the per
    8·2 answers
  • Plz answer all of these questions!
    15·1 answer
  • You are an engineer at company XYZ, and you are dealing with the need to determine the maximum load you can apply to a set of bo
    13·1 answer
  • Can a real refrigerator have higher COP than the COP of the Carnot refrigerator?
    7·2 answers
  • Assess the capabilities of a hydroelectric power plant from the following field data: Estimated water flow rate, 40 m3/s River i
    9·1 answer
  • A four-cylinder, four-stroke internal combustion engine operates at 2800 RPM. The processes within each cylinder are modeled as
    5·1 answer
  • Mention verious medium level and higher level human resources related to engineering​
    6·1 answer
  • Which organisms are consumers in this food chain? List all that apply. *
    5·1 answer
  • How to plot 0.45 gradation chart for sieve analysis ?
    12·1 answer
  • Select four items that an industrial engineer must obtain in order to practice in the field.
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!