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
Most motor vehicle crashes in Florida in 2016 occurred on
vlada-n [284]
Most Motor Vehicle catches in Florida in 2016 occurred on Motorcycles. Another option could be roads.
4 0
3 years ago
Read 2 more answers
Express (118)10 and (-49)10 in 8-bit binary one’s complement form and then add the numbers. What would be the representation (-0
stealth61 [152]

Answer:

118_{10}= 0110111 2) -49_{10}=110001_{2} 3) 0_{10}=0:16 \Rightarrow 0_{10}=0_{16}

Explanation:

1) Expressing the Division as the summation of the quotient and the remainder

for

118, knowing it is originally a decimal form:

118:2=59  +(0), 59/2 =29 + 1, 29/2=14+1, 14/2=7+0, 7/2=3+1, 3/2=1+1, 1/2=0+1

118_{10}= 0110111

2) -49_{10}

Similarly, we'll start the process with the absolute value of -49 since we want the positive value of it. Then let's start the successive divisions till zero.

|-49|=49

49:2=24+1, 24:2=12+0,12:2=6+0,6:2=3+0,3:2=1+1,1:2=0+1

100011

-49_{10}=110001_{2}

3) (-0)_{10}

The first step on that is dividing by 16, and then dividing their quotient again by 16, so on and adding their remainders. Simply put:

(-0)_{10}=0:16=0 \Rightarrow (0)_{10}=0_{16} \:or\\(0)_{16}=0000000000000000

5 0
3 years ago
A body whose velocity is constant has a. positive acceleration b. negative acceleration g. zero acceleration d. all of the above
adoni [48]

Answer:

option (c) is the correct answer which is zero acceleration.

Explanation:

It is given in the question that the velocity is constant.

Now,

the options are provided in relation to the acceleration.

We know,

acceleration is rate of change of velocity per unit time i.e

acceleration = \frac{dV}{dt}

since, the change in velocity is given to be zero,

thus, dV/dt = 0

hence,  

acceleration = 0

therefore, option (c) is the correct answer which is zero acceleration.

4 0
3 years ago
Whats 47,000 resistance converted to kilo or mega ohms.
Julli [10]
  1. The conversion of 47,000 Ohms to kilo-ohms is equal to 47 kilo-ohms.
  2. The conversion of 47,000 Ohms to mega-ohms is equal to 0.047 kilo-ohms.

<h3>What is resistance?</h3>

Resistance can be defined as an opposition to the flow of current in an electric circuit. Also, the standard unit of measurement of the resistance of an electric component is Ohms, which can be converted to kilo-ohms or mega-ohms.

For Ohms to kilo-ohms, we have:

1 Ohms = 0.001 kilo-ohms

47,000 Ohms = X kilo-ohms

Cross-multiplying, we have:

X = 0.001 × 47000

X = 47 kilo-ohms.

For Ohms to mega-ohms, we have:

1,000,000 ohms = 1 mega-ohms

47,000 Ohms = X mega-ohms

Cross-multiplying, we have:

X1,000,000 = 47,000

X = 47,000/1,000,000

X = 0.047 kilo-ohms.

Read more resistance here: brainly.com/question/19582164

#SPJ1

7 0
1 year ago
To use wiring diagrams, an understanding of the symbols, abbreviations, and connector coding used in the diagrams
Komok [63]

Answer:

True

Explanation:

6 0
3 years ago
Other questions:
  • Two Carnot engines operate in series such that the heat rejected from one is the heat input to the other. The heat transfer from
    13·1 answer
  • Initially when 1000.00 mL of water at 10oC are poured into a glass cylinder, the height of the water column is 1000.00 mm. The w
    6·1 answer
  • 8–21 Heat in the amount of 100 kJ is transferred directly from a hot reservoir at 1200 K to a cold reservoir at 600 K. Calculate
    6·1 answer
  • At a festival, spherical balloons with a radius of 140.cm are to be inflated with hot air and released. The air at the festival
    10·1 answer
  • Suppose an assembly requires five components from five different vendors. To guarantee starting the assembly on time with 90 per
    14·1 answer
  • What is the connection between the air fuel ratio and an engine running rich/poor? please give clear examples and full sentances
    9·1 answer
  • The following displacement (cm), output (V) data have been recorded during a calibration of an LVDT. Displacement (cm), output (
    15·1 answer
  • 50 points
    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
  • Reason fo I.EE regulations in electrical installations​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!