answer.
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
Radioactive wastes are temporarily stored in a spherical container, the center of which is buried a distance of 10 m below the e
puteri [66]

Given:

outer radius, R' = 10 m

inner diameter, d = 2 m

inner radius, R = \frac{d}{2} = 1 m

surface temperature, T' = 20^{\circ}C

Thermal conductivity of soil, K = 0.52 W/mK

Solution:

To calculate the thermal temperature of conductor, T, we know amount of heat, Q is given by :

Q =  \frac{T - T'}{\frac{R' - R}{4\pi KRR'}}

500 =  (T - 20)\frac{4\pi \times0.52\times 1\times 10}{10 - 1}

T = 68.86 +20 = 88.865^{\circ}C  

Therefore, outside surface temperature is 88.865^{\circ}C  

4 0
2 years ago
A certain printer requires that all of the following conditions be satisfied before it will send a HIGH to la microprocessor ack
Elza [17]

Answer:

D) AND gate.

Explanation:

Given that:

A certain printer requires that all of the following conditions be satisfied before it will send a HIGH to la microprocessor acknowledging that it is ready to print

These conditions are:

1. The printer's electronic circuits must be energized.

2. Paper must be loaded and ready to advance.

3. The printer must be "on line" with the microprocessor.

Now; if these conditions are met  the logic gate produces a HIGH output indicating readiness to print.

The objective here is to determine the basic logic gate used in this circuit.

Now;

For NOR gate;

NOR gate gives HIGH only when all the inputs are low. but the question states it that "a HIGH is generated and applied to a 3-input logic gate". This already falsify NOR gate to be the right answer.

For NOT gate.

NOT gate operates with only one input and one output device but here; we are dealing with 3-input logic gate.

Similarly, OR gate gives output as a high if any one of the input signals is high but we need "a HIGH that is generated and applied to a 3-input logic gate".

Finally, AND gate output is HIGH only when all the input signal is HIGH and vice versa, i.e AND gate output is LOW only when all the input signal is LOW. So AND gate satisfies the given criteria that; all the three conditions must be true for the final signal to be HIGH.

3 0
2 years ago
Universal Containers has a junction object called "Job Production Facility". With 2 master-detail relationships to the Job and P
alexdok [17]

Answer:

C. The user will not be able to see the junction object records or the field values.

Explanation:

For the profile of the user to give access permission such as create and read to the job without granting access permission to the production facility object, the value of the field or records of the junction object will not be seen by the user. This is one of the necessary criteria or principle for the universal container with a junction object.

3 0
2 years ago
A single crystal of a metal that has the FCC crystal structure is oriented such that a tensile stress is applied parallel to the
morpeh [17]

The magnitude of applied stress in the direction of 101 is 12.25 MPA and in the direction of 011, it is not defined.                                          

<u>Explanation</u>:        

<u>Given</u>:

tensile stress is applied parallel to the [100] direction

Shear stress is 0.5 MPA.

<u>To calculate</u>:

The magnitude of applied stress in the direction of [101] and [011].

<u>Formula</u>:

zcr=σ cosФ cosλ

<u>Solution</u>:

For in the direction of 101

cosλ = (1)(1)+(0)(0)+(0)(1)/√(1)(2)

cos λ = 1/√2

The magnitude of stress in the direction of 101 is 12.25 MPA

In the direction of 011

We have an angle between 100 and 011

cosλ = (1)(0)+(0)(-1)+(0)(1)/√(1)(2)

cosλ  = 0

Therefore the magnitude of stress to cause a slip in the direction of 011 is not defined.                                                                                                                                                                      

                                                                                   

                                                                                                                                                   

                                                                                                                                                             

5 0
2 years ago
A steel rotating-beam test specimen has an ultimate strength Sut of 1600 MPa. Estimate the life (N) of the specimen if it is tes
ziro4ka [17]

Answer:

the life (N) of the specimen is 46400 cycles

Explanation:

given data

ultimate strength Su = 1600 MPa

stress amplitude σa = 900 MPa

to find out

life (N) of the specimen

solution

we first calculate the endurance limit of specimen Se i.e

Se = 0.5× Su   .............1

Se = 0.5 × 1600

Se = 800 Mpa

and we know

Se for steel is 700 Mpa for Su ≥ 1400 Mpa

so we take endurance limit Se is = 700 Mpa

and strength of friction f  = 0.77 for 232 ksi

because for Se 0.5 Su at 10^{6} cycle = (1600 × 0.145 ksi ) = 232

so here coefficient value (a) will be

a = \frac{(f*Su)^2}{Se}    

a = \frac{(0.77*1600)^2}{700}  

a = 2168.3 Mpa

so

coefficient value (b) will be

a = -\frac{1}{3}log\frac{(f*Su)}{Se}

b =  -\frac{1}{3}log\frac{(0.77*1600)}{700}

b = -0.0818

so no of cycle N is

N =  (\frac{ \sigma a}{a})^{1/b}

put here value

N =  (\frac{ 900}{2168.3})^{1/-0.0818}

N = 46400

the life (N) of the specimen is 46400 cycles

5 0
2 years ago
Other questions:
  • generally compound curves are not filtered recommended for A. Road B. water way C. underground road D. rail way​
    12·1 answer
  • You are working in a lab where RC circuits are used to delay the initiation of a process. One particular experiment involves an
    13·1 answer
  • Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per li
    15·1 answer
  • The basic barometer can be used to measure the height of a building. If the barometric readings at the top and the bottom of a b
    15·1 answer
  • Prompt the user to enter five numbers, being five people's weights. Store the numbers in an array of doubles. Output the array's
    11·2 answers
  • Argon contained in a closed, rigid tank, initially at 33.7°C, 2.1 bar, and a volume of 4.2 m3, is heated to a final pressure of
    12·1 answer
  • In this module you learned about searching, sorting and algorithms in C++ and how to implement these elements in your C++ progra
    6·1 answer
  • An equation used to evaluate vacuum filtration is Q = ΔpA2 α(VRw + ARf) , Where Q ≐ L3/T is the filtrate volume flow rate, Δp ≐
    13·1 answer
  • Complete the following sentence.
    5·1 answer
  • Mr. Ray deposited $200,000 in the Old and Third National Bank. If the bank pays 8% interest, how much will he have in the accoun
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!