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
What is the average linear (seepage) velocity of water in an aquifer with a hydraulic conductivity of 6.9 x 10-4 m/s and porosit
jeka94

Answer:

a. 0.28

Explanation:

Given that

porosity =30%

hydraulic gradient = 0.0014

hydraulic conductivity = 6.9 x 10⁻4 m/s

We know that average linear velocity given as

v=\dfrac{K}{n_e}\dfrac{dh}{dl}

v=\dfrac{6.9\times 10^{-4}}{0.3}\times0.0014\ m/s

v=3.22\times 10^{-6}\ m/s

The velocity in m/d      ( 1 m/s =86400 m/d)

v= 0.27 m/d

So the nearest answer is 'a'.

a. 0.28

4 0
3 years ago
What's better than a trophy truck and an ultra 4
Annette [7]

Answer:

A ultra 4. that would be amazing to have that.

5 0
3 years ago
Read 2 more answers
Act as food engineers or biomedical engineers and write a short paragraph explaining why they need to know about mixtures and so
drek231 [11]

Answer:

We use our knowledge of mixtures and solutions when we are designing new synthetic materials. This is especially the case in the biomedical field, where we have to deal with compatibility issues when placing materials made outside the human body into the body.We also design ways to help separate mixtures and solutions in industrial, commercial and environmental processes.

Hope this helps

5 0
3 years ago
Identify the type of social responsibility discussed in the case with regard to
Schach [20]

Answer:

the types of social responsibility are as follows

1)Environmental Responsibility

2)Ethical Responsibility

3)Philanthropic Responsibility

4)Economic Responsibility

Social responsibility is an obligation every person has to do to uphold a balance among the economy as well as the environment. Social responsibility refers to maintain the balance between the environment and the budget.

It affects not only corporate governments but also everybody whose activity impacts the climate.

The Social responsibility towards the environment are as follows

1)Defend the environment, create balanced use of natural ingredients, and take important steps to stop pollution from the several processes adopted by the industries.

2)Encourage the viable use of raw resources and natural materials. Introduce strategies for continuously enlightening our environmental duty.

Introduce rules for continuous development in their ecological performance.

Obey with the law in force on conservational protection, and with other willingly recognized promises.

3)To encourage, by on-the-job practice, the participation of all our workers, independently and based on the team, in environmental safety problems.

4)To unite with the liable Agencies as well as Governmental Authorities.

To proceed with environmental protection courses.

5)To talk and report on our eco-friendly management struggles.

Implement and sustain the necessities of a Chain of Custody.

6)Stop trade and acquisition of illegally obtained wood.

7)Apply and continue a due industry system to avoid the acquisition and sale of criminally harvested timber and its products.

6 0
2 years ago
Design an op amp circuit to average the input of six sensors used to measure temperature in restaurant griddles for a large fast
Marina CMI [18]

Answer:

See the attached file for the design.

Explanation:

Find attached for the explanation.

3 0
4 years ago
Other questions:
  • Describe the similarities and differences between circuits with resistors combined in series and circuits with resistors combine
    9·1 answer
  • A turbine operates at steady state, and experiences a heat loss. 1.1 kg/s of water flows through the system. The inlet is mainta
    6·1 answer
  • Show that a chirped Gaussian pulse is compressed initially inside a single-mode fiber when ftC < 0. Derive expressions for th
    12·1 answer
  • What impact does modulus elasticity have on the structural behavior of a mechanical design?
    14·1 answer
  • Please help ASAP!!
    11·1 answer
  • Joinn my zo om lets play some blookets<br> 98867 708157<br> 9dPQPW
    14·1 answer
  • How are you today First to awnser is brainlyest.
    6·1 answer
  • Plzzzzz help ASAP 50 points for the answer
    7·1 answer
  • A train consists of a 50 Mg engine and three cars, each having a mass of 30 Mg . If it takes 75 s for the train to increase its
    8·1 answer
  • Jamal is demonstrating howto build a game in scratch to several of his friends. for the purpose of his demonstration, he wants t
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!