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
Choose the correct word or phrase to complete the sentence to explain human intervention in a machine system.
maksim [4K]

Answer:

Fully Automated

Periodic Maintenance Activities

6 0
3 years ago
What is the tolerance of number 4?
Kamila [148]

Answer:

Answer: ±0.02 units or 20±0.02 units or 19.98-20.02 units depending on how they prefer its written (typically the first or second one)

Explanation:

says on the sheet. Unless otherwise stated 0.XX = ±0.02 tolerance

(based on image sent in other post)

5 0
3 years ago
A rigid 10-L vessel initially contains a mixture of liquid and vapor water at 100 °C, with a quality factor of 0.123. The mixtur
masya89 [10]

Answer:

Q_{in} = 46.454\,kJ

Explanation:

The vessel is modelled after the First Law of Thermodynamics. Let suppose the inexistence of mass interaction at boundary between vessel and surroundings, changes in potential and kinectic energy are negligible and vessel is a rigid recipient.

Q_{in} = U_{2} - U_{1}

Properties of water at initial and final state are:

State 1 - (Liquid-Vapor Mixture)

P = 101.42\,kPa

T = 100\,^{\textdegree}C

\nu = 0.2066\,\frac{m^{3}}{kg}

u = 675.761\,\frac{kJ}{kg}

x = 0.123

State 2 - (Liquid-Vapor Mixture)

P = 476.16\,kPa

T = 150\,^{\textdegree}C

\nu = 0.2066\,\frac{m^{3}}{kg}

u = 1643.545\,\frac{kJ}{kg}

x = 0.525

The mass stored in the vessel is:

m = \frac{V}{\nu}

m = \frac{10\times 10^{-3}\,m^{3}}{0.2066\,\frac{m^{3}}{kg} }

m = 0.048\,kg

The heat transfer require to the process is:

Q_{in} = m\cdot (u_{2}-u_{1})

Q_{in} = (0.048\,kg)\cdot (1643.545\,\frac{kJ}{kg} - 675.761\,\frac{kJ}{kg} )

Q_{in} = 46.454\,kJ

3 0
3 years ago
How is an orthographic drawing similar to or different from an isometric drawing?
evablogger [386]
An isometrical drawing is a nearly 3d drawing showing the object's width and depth in a complete image, from each curved plane of the orthhographic view, the viewpoint is at a 45 degree angle. From an observations point of view, isometric differs, since all longitudes are true.
4 0
3 years ago
Read 2 more answers
What is the mode of operation of a ramp digital voltimeter​
liberstina [14]

Answer:

The operating principle of a ramp type digital voltmeter is to measure the time that a linear ramp voltage takes to change from level of input voltage to zero voltage (or vice versa).

7 0
1 year ago
Other questions:
  • Explain the differences between 1- Energy 2- Power 3- Work 4- Heat Your answer should explain the mathematica and physical meani
    5·1 answer
  • What does basic levels of competence involves??​
    13·2 answers
  • 2. One of the following systems is not typically used with floor
    5·1 answer
  • Burn in hell i watched your stupid video and i still could not get the answer
    14·1 answer
  • How long does it take electrons to get from a car battery to the starting motor? Assume the current is 300 A and the electrons t
    10·1 answer
  • Which power transfer system is most suitable for the food processing industry?
    13·1 answer
  • Who wanna learn C# for free tell me​
    10·1 answer
  • PLS :(((( HELP HELPPPP
    13·1 answer
  • true or false: the types of building materials that’s should be used in a project does not constitute a conditional for projects
    13·2 answers
  • What is the tolerance for number 4?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!