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]
2 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]2 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
. Bơm kiểu piston tác dụng đơn có áp suất p=0,64 Mpa và lưu lượng Q=3,5 l/s. Xác định tốc độ quay của trục bơm và công suất của
Viktor [21]

Answer:

not understand language

4 0
3 years ago
Determine the reactor volume (assume a CSTR activated sludge aerobic reactor at steady state) required to treat 5 MGD of domesti
12345 [234]

Answer:

1.0MG

Explanation:

to solve this problem we use this formula

S₀-S/t = ksx --- (1)

the values have been given as

concentration = S₀ = 250mg

effluent concentration = S= 10mg

value of K = 0.04L/day

x = 3000 mg

when we put these values into this equation,

250-10/t = 0.04x10x3000

240/t = 1200

we cross multiply from this stage

240 = 1200t

t = 240/1200

t = 0.2

remember the question says that 5MGD is required to be treated

so the volume would be

v = 0.2x5

= 1.0 MG

4 0
2 years ago
Both carpenters and building inspectors have been associated with the personality characteristics identified as realistic, conve
Inessa05 [86]

Answer:

Inspectors use inductive reasoning on the job.

Explanation:

I just took the test.

8 0
3 years ago
Calculate the wire pressure for a round copper bar with an original cross-sectional area of 12.56 mm2 to a 30% reduction of area
dybincka [34]

Answer:153.76 MPa

Explanation:

Initial Area\left ( A_0\right )=12.56 mm^2

Final Area\left ( A_f\right )=0.7\times 12.56 mm^2=8.792 mm^2

Die angle=30^{\circ}

\alpha =\frac{30}{2}=15^{\circ}

\mu =0.08

Yield stress\left ( \sigma _y \right )=350 MPa

B=\mu cot\left ( \aplha\right )=0.2985

\sigma _{pressure}=\sigma _y\left [\frac{1+B}{B}\right ]\left [ 1-\frac{A_f}{A_0}\right ]^B

\sigma _{pressure}=350\left [\frac{1+0.2985}{0.2985}\right ]\left [ 1-\frac{8.792}{12.56}\right ]^{0.2985}

\sigma _{pressure}=153.76 MPa

8 0
3 years ago
About what thickness of aluminum is needed to stop a beam of (a) 2.5-MeV electrons, (b) 2.5-MeV protons, and (c) 10-MeV alpha pa
Nana76 [90]

The thickness of aluminium needed to stop the beam electrons, protons and alpha particles at the given dfferent kinetic energies is 1.5 x 10⁻¹⁴ m.

<h3>Thickness of the aluminum</h3>

The thickness of the aluminum can be determined using from distance of closest approach of the particle.

K.E = \frac{2KZe^2}{r}

where;

  • Z is the atomic number of aluminium  = 13
  • e is charge
  • r is distance of closest approach = thickness of aluminium
  • k is Coulomb's constant = 9 x 10⁹ Nm²/C²
<h3>For 2.5 MeV electrons</h3>

r = \frac{2KZe^2}{K.E} \\\\r = \frac{2 \times 9\times 10^9 \times 13\times (1.6\times 10^{-19})^2}{2.5 \times 10^6 \times 1.6 \times 10^{-19}} \\\\r = 1.5 \times 10^{-14} \ m

<h3>For 2.5 MeV protons</h3>

Since the magnitude of charge of electron and proton is the same, at equal kinetic energy, the thickness will be same. r = 1.5 x 10⁻¹⁴ m.

<h3>For 10 MeV alpha-particles</h3>

Charge of alpah particle = 2e

r = \frac{2KZe^2}{K.E} \\\\r = \frac{2 \times 9\times 10^9 \times 13\times (2 \times 1.6\times 10^{-19})^2}{10 \times 10^6 \times 1.6 \times 10^{-19}} \\\\r = 1.5 \times 10^{-14} \ m

Thus, the thickness of aluminium needed to stop the beam electrons, protons and alpha particles at the given dfferent kinetic energies is 1.5 x 10⁻¹⁴ m.

Learn more about closest distance of approach here: brainly.com/question/6426420

7 0
2 years ago
Other questions:
  • Researchers compared protein intake among three groups of postmenopausal women: (1) women eating a standard American diet (STD),
    14·1 answer
  • Problem 3: Soil Classification using the AASHTO and USCS Systems
    10·1 answer
  • A certain metal has a resistivity of 1.68 × 10-8 Ω ∙ m. You have a long spool of wire made from this metal. If this wire has a d
    14·1 answer
  • Which of the following is a direct result of technological improvements in the music industry?
    9·2 answers
  • When could you use the engineering design process in your own life?
    9·1 answer
  • The MOST common injury causing absence from work is
    7·2 answers
  • An engine jack is used to lift a 265-lb engine 6'. How much work, in ft-lb, is performed?
    11·1 answer
  • Which of the following characteristics would not give animals an advantage in the ocean?
    13·1 answer
  • The majority of adults now own smartphones or tablets, and most of them say they use them in part to get the news. From 2004 to
    7·1 answer
  • Describe how you would control employee exposure to excessive noise in a mining environment
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!