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
Which band has an average of $3.58 per hour of parking?
Minchanka [31]
C it would be c because that has more and the others have less
6 0
2 years ago
A __________ is an added note showing additional or more specific information.
xxMikexx [17]

Answer:

awnsers should be added to know to show additional

8 0
3 years ago
Write a program that removes all spaces from the given input. You may assume that the input string will not exceed 50 characters
GrogVix [38]

Answer:

Program that removes all spaces from the given input

Explanation:

// An efficient Java program to remove all spaces  

// from a string  

class GFG  

{  

 

// Function to remove all spaces  

// from a given string  

static int removeSpaces(char []str)  

{  

   // To keep track of non-space character count  

   int count = 0;  

 

   // Traverse the given string.  

   // If current character  

   // is not space, then place  

   // it at index 'count++'  

   for (int i = 0; i<str.length; i++)  

       if (str[i] != ' ')  

           str[count++] = str[i]; // here count is  

                                   // incremented  

         

   return count;  

}  

 

// Driver code  

public static void main(String[] args)  

{  

   char str[] = "g eeks for ge eeks ".toCharArray();  

   int i = removeSpaces(str);  

   System.out.println(String.valueOf(str).subSequence(0, i));  

}  

}  

5 0
4 years ago
Read 2 more answers
Give me some examples of fragile structures.
Anvisha [2.4K]

Answer:

i don't know if this help tell me if i am wrong

Explanation:

Gravity is the force that pulls all elements of matter together. Matter refers to things you can physically touch. The more matter there is, the greater the amount of gravity or force. This means that the Earth or other planets have a great deal of pull and that everything on Earth is pulled back to Earth.

Some examples of the force of gravity include:

The force that holds the gases in the sun.

The force that causes a ball you throw in the air to come down again.

The force that causes a car to coast downhill even when you aren't stepping on the gas.

The force that causes a glass you drop to fall to the floor.

3 0
3 years ago
What is (10 to the power of three) times (3 to the power of 10)? will give brainliest
VLD [36.1K]

59,049,000 is the answer.

7 0
3 years ago
Other questions:
  • What is the major drawback to use whiskers as a dispersed agents in composites? a)- High price b)- Large length to diameter rati
    7·1 answer
  • Water evaporating from a pond does so as if it were diffusing across an air film 0.15 cm thick. The diffusion coefficient of wat
    8·1 answer
  • The uniform crate has a mass of 50 kg and rests on the cart having an inclined surface. Determine the smallest acceleration that
    10·1 answer
  • Add my sc please?.<br><br> kindacracked
    12·2 answers
  • Which is an alloy made up of iron and carbon and has high compressive and tensile strength?
    6·1 answer
  • If you have a hole diameter of 0.250 with a tolerance of ±0.005, what are the limits of the hole size?
    13·1 answer
  • What major financial flop led to the end of the Sega Dreamcast and ultimately caused Sega to stop making game consoles altogethe
    15·1 answer
  • Cho biết tác dụng chung của các hệ giằng khung ngang nhà công nghiệp nhẹ 1 tầng 1 nhịp.
    13·1 answer
  • Test if a number grade is an A (greater than or equal to 90). If so, print "Great!". Hint: Grades may be decimals. Sample Run En
    15·1 answer
  • Technician A says the compressor is the dividing line of the refrigeration system, low- to high-side. Technician B says the expa
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!