Difference between revisions of "Cholera MapReduce Application"

From CSE231 Wiki
Jump to navigation Jump to search
Line 42: Line 42:
 
We have anticipated two basic approaches to this problem (with a variation^2 on one of the approaches). You may choose to implement an integer-based or a double-based CholeraApp. If you take a different approach than one we have anticipated, that is fine.  Get it checked out by an instructor.
 
We have anticipated two basic approaches to this problem (with a variation^2 on one of the approaches). You may choose to implement an integer-based or a double-based CholeraApp. If you take a different approach than one we have anticipated, that is fine.  Get it checked out by an instructor.
  
==CholeraUtils==
+
==CholeraOutbreak==
  
===createApp===
+
{{CodeToImplement|CholeraOutbreak|produceEvidence|mapreduce.apps.cholera.exercise}}
return a new CholeraApp. Depending on which approach you plan to implement, it will be either <code>IntegerCholeraApp()</code> or <code>DoubleCholeraApp()</code>
 
  
==IntegerCholeraApp or DoubleCholeraApp==
+
===valueRepresentation===
{{CodeToImplement|IntegerCholeraApp or DoubleCholeraApp|getValueRepresentation<br>createMapper<br>createCollector|mapreduce.apps.cholera.exercise}}
+
{{Sequential|public static ValueRepresentation valueRepresentation()}}
  
===getValueRepresentation===
+
You have been provided with this implementation which should be sufficient:
{{Sequential|public static ValueRepresentation getValueRepresentation()}}
+
<syntaxhighlight lang="java">
 +
public static ValueRepresentation valueRepresentation() {
 +
    return ValueRepresentation.AUTO_DETECT;
 +
}
 +
</syntaxhighlight>
  
return one of the three values of the [https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html enum] <code>ValueRepresentation</code> to aid the visualization and testing. You can access the specific enum constant by typing <code> ValueRepresentation. </code> .
+
===thresholdIfApplicable===
 +
{{Sequential|public static Optional<Double> thresholdIfApplicable()}}
  
<nowiki>public enum ValueRepresentation {
+
For the vast majority of students, a threshold value will not be applicable to their solution and thus this method need not to be changed:
HIGH_NUMBERS_SUSPECT, LOW_NUMBERS_SUSPECT, LOW_NUMBERS_SUSPECT_SQUARED
 
}</nowiki>
 
  
===createMapper===
+
<syntaxhighlight lang="java">
{{Sequential|public static Mapper<CholeraDeath, WaterPump, Number> createMapper()}}
+
public static Optional<Double> thresholdIfApplicable() {
 +
final boolean IS_THRESHOLD_APPLICABLE = true;
 +
if (IS_THRESHOLD_APPLICABLE) {
 +
throw new NotYetImplementedException();
 +
} else {
 +
return Optional.empty();
 +
}
 +
}
 +
</syntaxhighlight>
  
We have implemented WaterPump as an enum. You can access all the enum constants of any enum [https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html via its values() method]. For example:
+
However, if your solution has a threshold value which would be necessary for visualization and testing, return it here via Optional.of(threshold).
  
<nowiki>for (WaterPump pump : WaterPump.values()) {
+
Again, you need not concern yourself with this method if you are going with a threshold-less strategy.
}</nowiki>
 
 
 
If you need inspirations on how to implement a Mapper, revisit past assignments such as [https://classes.engineering.wustl.edu/cse231/core/index.php?title=Int_Sum_MapReduce_Apps_Studio#Card_Mapper CardMapper and WordCountMapper], which implements the Mapper<E, K, V> interface. Or you can directly tunnel into the Mapper<E, K, V> interface to see what method you need to implement.
 
 
 
===createReducer===
 
Depending on your approach, you may be able to reuse one of your existing Reducers.  Otherwise, implement one to go with your Mapper.
 
 
 
{{Sequential|public static Reducer<? extends Number, ?, ? extends Number> createReducer()}}
 
 
 
note: if you decide to build your own Reducer, the following will likely be a fine charateristics method
 
 
 
<nowiki> @Override
 
public Set<Characteristics> characteristics() {
 
return EnumSet.noneOf(Characteristics.class);
 
}</nowiki>
 
 
 
===OPTIONAL getThresholdIfApplicable===
 
We have noted that some students have been going with a threshold approach.  In order to support this in the visualization and the test (and to minimize the chances of interfering with students who have already started) we have added a separate class file CholeraThreshold.  You need not concern yourself with this file if you are going with a threshold-less strategy.
 
 
 
{{CodeToImplement|CholeraApp|getThresholdIfApplicable|mapreduce.apps.cholera.studio}}
 
 
 
{{Sequential|public static double getThresholdIfApplicable()}}
 
 
 
Return the threshold if you are using one in your Mapper.  Otherwise return [https://docs.oracle.com/javase/8/docs/api/java/lang/Double.html#NaN Double.NaN].
 
 
 
<nowiki> public static double getThresholdIfApplicable() {
 
final boolean IS_THRESHOLD_APPLICABLE = false;
 
if (IS_THRESHOLD_APPLICABLE) {
 
throw new NotYetImplementedException();
 
} else {
 
return Double.NaN;
 
}
 
}</nowiki>
 
  
 
=Testing Your Solution=
 
=Testing Your Solution=

Revision as of 04:50, 5 March 2023

John Snow memorial and pub.jpg

Motivation

Epidemiology is the important study of "why certain people are getting ill."

We get a chance to make sense of the data in a relatively open-ended studio.

Background

Video: Extra History: The Broad Street Pump  

Imagine you are a physician in 1854 London in the midst of a cholera outbreak. Your theory that contaminated water is the cause meets resistance from the medical establishment which holds that it is spread via the air.

Imagine further that your friend Ada has taught you to program.

Code To Use

You will be asked to produce evidence from CholeraDeath locations and WaterPump locations. The CholeraDeath data is from this GIS Analysis and made available in Java in SohoCholeraOutbreak1854.getDeaths(). source: deaths.txt.

The WaterPump data is available via WaterPump.values()
source: pumps.txt.

class Location

double distanceTo( Location other )
double x()
double y()

class CholeraDeath

Location location()

enum WaterPump

Location location()

class SohoCholeraOutbreak1854

static CholeraDeath[] deaths()

Code To Implement

In order to provide a more open-ended assignment, we have abstracted out different aspects of the studio. In particular, getValueRepresentation() allows you to specify whether your CholeraApp sees high or low numbers as suspects. For example, if you return ValueRepresentation.HIGH_NUMBERS_SUSPECT, you are indicating that a higher number is more likely to indicate that the water pump is the source of the cholera outbreak. This will aid the #Visualization in presenting your findings.

We have anticipated two basic approaches to this problem (with a variation^2 on one of the approaches). You may choose to implement an integer-based or a double-based CholeraApp. If you take a different approach than one we have anticipated, that is fine. Get it checked out by an instructor.

CholeraOutbreak

class: CholeraOutbreak.java Java.png
methods: produceEvidence
package: mapreduce.apps.cholera.exercise
source folder: student/src/main/java

valueRepresentation

method: public static ValueRepresentation valueRepresentation() Sequential.svg (sequential implementation only)

You have been provided with this implementation which should be sufficient:

public static ValueRepresentation valueRepresentation() {
    return ValueRepresentation.AUTO_DETECT;
}

thresholdIfApplicable

method: public static Optional<Double> thresholdIfApplicable() Sequential.svg (sequential implementation only)

For the vast majority of students, a threshold value will not be applicable to their solution and thus this method need not to be changed:

public static Optional<Double> thresholdIfApplicable() {
	final boolean IS_THRESHOLD_APPLICABLE = true;
	if (IS_THRESHOLD_APPLICABLE) {
		throw new NotYetImplementedException();
	} else {
		return Optional.empty();
	}
}

However, if your solution has a threshold value which would be necessary for visualization and testing, return it here via Optional.of(threshold).

Again, you need not concern yourself with this method if you are going with a threshold-less strategy.

Testing Your Solution

Visualization

Original Map Drawn By John Snow:

Snow-cholera-map-1.jpg

Our Visualization App:

class: CholeraOutbreakVisualizationApp.java VIZ
package: mapreduce.apps.cholera.viz
source folder: student/src//java

CholeraOutbreak.png

Correctness

If you have chosen to go a different route than the ones we anticipated, do not worry about passing the test suite. Demo your work to an instructor in class and we can discuss its fitness.

class: CholeraStudioTestSuite.java Junit.png
package: mapreduce
source folder: testing/src/test/java