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
As the impurity concentration in solid solution of a metal is increased, the tensile strength:________.a) decreasesb) increasesc
valkas [14]

Answer:

Increases

Explanation:

By inhibiting the motion of dislocations by impurities in a solid solutions, is a strengthening mechanism. In solid solutions it is atomic level strengthening resulting from resistance to dislocation motion. Hence, the strength of the alloys can differ with respect to the precipitate's property. Example, the precipitate is stronger (ability to an obstacle to the dislocation motion) than the matrix and it shows an improvement of strength.

5 0
3 years ago
What does an aeronautical engineer design
Colt1911 [192]

Answer:

they work with aircraft, designing aircrafts.

Explanation:

3 0
3 years ago
What happens to the duty cycle for a GMAW Gun when 75Ar/25COzgas
skad [1K]

So what happens is the host will not kill the y no se que hacer para no one can see it in

6 0
3 years ago
Harmonic excitation of motion is represent as
Gennadij [26K]

Harmonic excitation refers to a sinusoidal external force of a certain frequency applied to a system. ... Resonance occurs when the external excitation has the same frequency as the natural frequency of the system. It leads to large displacements and can cause a system to exceed its elastic range and fail structurally.

6 0
3 years ago
Problem Statement: Air flows at a rate of 0.1 kg/s through a device as shown below. The pressure and temperature of the air at l
Tema [17]

Answer:

The answer is "+9.05 kw"

Explanation:

In the given question some information is missing which can be given in the following attachment.

The solution to this question can be defined as follows:

let assume that flow is from 1 to 2 then

Q= 1kw

m=0.1 kg/s

From the steady flow energy equation is:

m\{n_1+ \frac{v^2_1}{z}+ gz_1 \}+Q= m \{h_2+ \frac{v^2_2}{2}+ gz_2\}+w\\\\\ change \ energy\\\\0.1[1.005 \times 800]-1= 0.01[1.005\times 700]+w\\\\w= +9.05 \ kw\\\\

If the sign of the work performed is positive, it means the work is done on the surrounding so, that the expected direction of the flow is right.

8 0
3 years ago
Other questions:
  • (a) Determine the dose (in mg/kg-day) for a bioaccumulative chemical with BCF = 103 that is found in water at a concentration of
    11·1 answer
  • Who knows about welding ??
    7·1 answer
  • What happens when a larger force is applied?
    9·1 answer
  • Why does an aeroplane smoke in the air​
    14·1 answer
  • Please Help !!
    5·1 answer
  • How much memory can a 32 -bit processor support ?
    13·1 answer
  • Which battery produces more volts per cell, maintenance type or maintenance free ?
    6·1 answer
  • In order to be a Mechanical Engineer, you need to:
    5·2 answers
  • Me ayudas plis noce ​
    14·1 answer
  • What major problems could you encounter in complex intersections?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!