When analyzing data, such as the output of the rolling average method from the previous problem, it is sometimes useful to identify where the (local) maximum valucs arc located. We'll call these max- imal values peaks in the data. More formally, if we have a sequence of numbers do, d1, d2, ..., dn-1, the peaks are identified as follows:

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Need help with this Java problem: Note: Please only use these classes/methods to solve the problem: Math, String, StringBuilder, Double (or anyprimitive wrapper class), any helper class you create yourself

// 1 peak in the data
double []
= {1.1, 2.2, 3.1, 4.2, 2.3};
double ] [] peaksi = A1Q2.peaks (data1, 0.0001);
== { {4.2}, {3.0} }
datal
// assert: peaks1
// 2 peaks in the data
= {1.1, 2.2, 1.1, 2.2, 3.3};
A1Q2. peaks (data2, 0.00001);
== { {2.2, 3.3}, (1.0, 4.0} }
double []
data2
double [) 0 peaka2
// assert: peaks2
// NO peaks int the data
double [] data3 = {0.3, 1.1, 2.2, 2.2, 2.2, 1.1, 0.2};
double[] [] peaks3 = A1Q2.peaks (data3, 0.00001);
// assert: peaka3
{ 0, 0 }
=3D
Note that we are not considering what might be described as plateaus in the data. A plateau occurs
when a local maximum value is repeated one or more times consecutively (the dataset data3 from
above has a plateau with value 2.2 that spans index values 2-4, inclusive).
Transcribed Image Text:// 1 peak in the data double [] = {1.1, 2.2, 3.1, 4.2, 2.3}; double ] [] peaksi = A1Q2.peaks (data1, 0.0001); == { {4.2}, {3.0} } datal // assert: peaks1 // 2 peaks in the data = {1.1, 2.2, 1.1, 2.2, 3.3}; A1Q2. peaks (data2, 0.00001); == { {2.2, 3.3}, (1.0, 4.0} } double [] data2 double [) 0 peaka2 // assert: peaks2 // NO peaks int the data double [] data3 = {0.3, 1.1, 2.2, 2.2, 2.2, 1.1, 0.2}; double[] [] peaks3 = A1Q2.peaks (data3, 0.00001); // assert: peaka3 { 0, 0 } =3D Note that we are not considering what might be described as plateaus in the data. A plateau occurs when a local maximum value is repeated one or more times consecutively (the dataset data3 from above has a plateau with value 2.2 that spans index values 2-4, inclusive).
When analyzing data, such as the output of the rolling average method from the previous problem, it
is sometimes useful to identify where the (local) maximum valucs are located. We'll call these max-
imal values peaks in the data. More formally, if we have a sequence of numbers do, d1, d2, ..., dn-1,
the peaks are identified as follows:
1. do is a peak if do > dı,
2. dn-1 is a peak if d,-2 < d,-1,
3. for any 1<i<n- 2, d; is a peak if d;-1 < d; and d; > di+1
In the provided A1Q2.java file, you will complete the peaks () method which finds all peak
values (and their positions) in a given array of numbers.
public static double[] [] peaks (double [] data, double epsilon)
The input parameter data stores the data that we are looking for peaks in and epsilon is uscd
as a tolerance value for floating point mumber equality. Because of the representational crror of
floating point mumbers, we should never try to check if two floating point mımbers are the samc.
Instcad, we consider two floating point numbers to be the same mumber if they are close enough to
cach other. In particular, two numbers r and y are considered equal if and only if |r – y| < epsilon.
While not necessary, it is highly recommended that you create and use a static helper function (in
the same A1Q2 class) to determine if two floating point numbers are considered equal for a given
epsilon. You must not use equals (), compareTo () or compare () from the Double class for this.
The method returns an array containing exactly two (2) arrays of doubles. The first array holds
all the peak values and the second array holds the index positions of those pcaks. For example,
Transcribed Image Text:When analyzing data, such as the output of the rolling average method from the previous problem, it is sometimes useful to identify where the (local) maximum valucs are located. We'll call these max- imal values peaks in the data. More formally, if we have a sequence of numbers do, d1, d2, ..., dn-1, the peaks are identified as follows: 1. do is a peak if do > dı, 2. dn-1 is a peak if d,-2 < d,-1, 3. for any 1<i<n- 2, d; is a peak if d;-1 < d; and d; > di+1 In the provided A1Q2.java file, you will complete the peaks () method which finds all peak values (and their positions) in a given array of numbers. public static double[] [] peaks (double [] data, double epsilon) The input parameter data stores the data that we are looking for peaks in and epsilon is uscd as a tolerance value for floating point mumber equality. Because of the representational crror of floating point mumbers, we should never try to check if two floating point mımbers are the samc. Instcad, we consider two floating point numbers to be the same mumber if they are close enough to cach other. In particular, two numbers r and y are considered equal if and only if |r – y| < epsilon. While not necessary, it is highly recommended that you create and use a static helper function (in the same A1Q2 class) to determine if two floating point numbers are considered equal for a given epsilon. You must not use equals (), compareTo () or compare () from the Double class for this. The method returns an array containing exactly two (2) arrays of doubles. The first array holds all the peak values and the second array holds the index positions of those pcaks. For example,
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY