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
Calculate the reactions at 4 ends (supports) of this bookshelf. Assume that the weight of each book is approximately 1 lb. The w
hoa [83]

Answer:

R = 4.75 lb  (↑)

Explanation:

Number of books = n = 19

Weight of each book = W = 1 lb

Length of the bookshelf = L = 40 inches

We can get the value of the distributed load as follows

q = n*W/L = 19*1 lb/ 40 inches = 0.475 lb/in

then the reactions at 4 ends (supports) of the bookshelf are

R = (q/2)/2 = 4.75 lb

We can see the bookshelf in the pic.

8 0
3 years ago
Windmills slow the air and cause it to fill a larger channel as it passes through the blades. Consider a circular windmill with
Scilla [17]

Answer:

DIAMETER  = 9.797 m

POWER = \dot W = 28.6 kW

Explanation:

Given data:

circular windmill diamter D1 = 8m

v1 = 12 m/s

wind speed = 8 m/s

we know that specific volume is given as

v =\frac{RT}{P}

  where v is specific volume of air

considering air pressure is 100 kPa and temperature 20 degree celcius

v =  \frac{0.287\times 293}{100}

v = 0.8409 m^3/ kg

from continuity equation

A_1 V_1 = A_2 V_2

\frac{\pi}{4}D_1^2 V_1 = \frac{\pi}{4}D_1^2 V_2

D_2 = D_1 \sqrt{\frac{V_1}{V_2}}

D_2 = 8 \times \sqrt{\frac{12}{8}}

D_2 = 9.797 m

mass flow rate is given as

\dot m = \frac{A_1 V_1}{v} = \frac{\pi 8^2\times 12}{4\times 0.8049}

\dot m = 717.309 kg/s

the power produced \dot W = \dot m \frac{ V_1^2 - V_2^2}{2} = 717.3009 [\frac{12^2 - 8^2}{2} \times \frac{1 kJ/kg}{1000 m^2/s^2}]

\dot W = 28.6 kW

8 0
3 years ago
If you get a flat in the front of your car, your car will:
juin [17]

Answer:

stop and might even crash

Explanation:

6 0
2 years ago
Steam enters an adiabatic turbine at 400◦C, 2 MPa pressure. The turbine has an isentropic efficiency of 0.9. The exit pressure i
pychu [463]

Answer:

Explanation:

Find attached the solution

8 0
3 years ago
The diameter of an extruder barrel = 85 mm and its length = 2.00 m. The screw rotates at 55 rev/min, its channel depth = 8.0 mm,
babunello [35]

Answer:

Qx = 9.109.10^5 \times 10^{-6} m³/s  

Explanation:

given data

diameter = 85 mm

length = 2 m

depth = 9mm

N = 60 rev/min

pressure p = 11 × 10^6 Pa

viscosity n = 100 Pas

angle = 18°

so  Qd will be

Qd = 0.5 × π² ×D²×dc × sinA × cosA   ..............1

put here value and we get

Qd = 0.5 × π² × ( 85 \times 10^{-3} )²× 9  \times 10^{-3}  × sin18 × cos18

Qd = 94.305 × 10^{-6} m³/s

and

Qb = p × π × D × dc³ × sin²A ÷  12  × n × L    ............2

Qb = 11 × 10^{6} × π × 85 \times 10^{-3}  × ( 9  \times 10^{-3} )³ × sin²18 ÷  12  × 100 × 2

Qb = 85.2 × 10^{-6} m³/s

so here

volume flow rate Qx = Qd - Qb   ..............3

Qx =  94.305 × 10^{-6}  - 85.2 × 10^{-6}  

Qx = 9.109.10^5 \times 10^{-6} m³/s  

8 0
3 years ago
Other questions:
  • Material with hardness of 220 Vickers is harder than material with a hardness of 180 Vickers. a)-True b)- False
    8·1 answer
  • 1 2 3 4 5 6 7 8 9 10
    14·1 answer
  • 6. PVC boxes are primarily used in new construction because it is simple to
    11·1 answer
  • Plot the following trig functions using subplots, choosing an appropriate layout for the number of functions displayed. The subp
    8·1 answer
  • Someone please help me with this I’m stuck on it ?!i don’t have a lot of time
    12·1 answer
  • The primary transformer voltage is 2.8 kV and the secondary is 230 V. The transformer is connected to a variable load (0 to 300
    8·1 answer
  • Select the correct answer.
    6·1 answer
  • Drag each label to the correct location on the table. Match to identify permanent and temporary structures.
    15·1 answer
  • What can be used to measure the alcohol content in gasoline? A. Graduated cylinder B. Electronic tester C. Scan tool D. Either a
    5·1 answer
  • By the end of the day, a 45 ft x 25 ft x 8 ft office has a carbon dioxide air level of 1,100 ppm. Determine the time in hours ne
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!