Skip to content

Commit 22dc1df

Browse files
committed
US119832: Adding locomotive regression sample analytics.
1 parent bcf08e9 commit 22dc1df

File tree

40 files changed

+147260
-6
lines changed

40 files changed

+147260
-6
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
.project
88
**/org.eclipse.jdt.core.prefs
99
**/org.eclipse.core.resources.prefs
10-
**/org.eclipse.m2e.core.prefs
10+
**/org.eclipse.m2e.core.prefs
11+
javabuilder.jar

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ A collection of samples for use with [Predix Analytics](https://www.predix.io/do
44

55
## Sample Analytics
66

7-
These are the sample analytics written for Predix Analytics:
7+
These are sample analytics written for use with the Predix Analytics platform:
88

99
- **[demo-adder](analytics/demo-adder):** A simple analytic that takes 2 numbers as input and returns their sum. It has been implemented in Java, Matlab (r2011b), and Python.
1010
- **[demo-timeseries-adder](analytics/demo-timeseries-adder-java):** Takes 2 arrays of timeseries data and returns a timeseries array that contains the sums at each timestamp. Currently available in Java.
11+
- **[demo-RTM-loco](analytics/demo-RTM-loco):** A reference analytic that is used to calculate locomotive efficiency using a linear regression model. It has been implemented in Java, Matlab (r2011b), and Python.
1112

1213
For more information on developing analytics for use with Predix Analytics, see [Analytic Development](https://www.predix.io/docs/#Qd2kPYb7) on Predix IO.
1314

analytics/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Sample Analytics
2+
3+
These are sample analytics written for use with the [Predix Analytics](https://www.predix.io/docs/#EG3xVdLg) platform:
4+
5+
- **[demo-adder](demo-adder):** A simple analytic that takes 2 numbers as input and returns their sum. It has been implemented in Java, Matlab (r2011b), and Python.
6+
- **[demo-timeseries-adder](demo-timeseries-adder-java):** Takes 2 arrays of timeseries data and returns a timeseries array that contains the sums at each timestamp. Currently available in Java.
7+
- **[demo-RTM-loco](demo-RTM-loco):** A reference analytic that is used to calculate locomotive efficiency using a linear regression model. It has been implemented in Java, Matlab (r2011b), and Python.
8+
9+
For more information on developing analytics for use with Predix Analytics, see [Analytic Development](https://www.predix.io/docs/#Qd2kPYb7) on Predix IO.

analytics/demo-RTM-loco/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#Locomotive Efficiency Analytic
2+
3+
3 implementations of a sample analytic for the Predix Analytics platform.
4+
5+
In this problem, the goal is to model the instantaneous operational efficiency of a diesel locomotive based on some controllable and non-controllable factors. The total amount of useful work performed by a locomotive is typically measured in Revenue Ton Miles (RTM) which is calculated by multiplying the weight in tons of freight by the number of miles transported. Therefore, we will express operational efficiency of a diesel locomotive in Revenue Ton Miles (RTM) per gallon of fuel. There are several factors that contribute to the operational efficiency of a locomotive, such as, wind speed, locomotive speed, grade (slope) of track, locomotive design etc. However, to keep things simple, we will assume that under certain conditions, the instantaneous values of operational efficiency for a single locomotive become a function of locomotive speed and wind speed only. This is known as a regression problem. Owing to its simplicity, we will use Ordinary Least Squares Linear Regression (LR).
6+
7+
The dataset that we have at our disposal to model the problem consists of 1200 data points and each data point consists of three measurements -- Locomotive Speed, Wind Speed and RTM per gallon. For the current problem, we have a strong reason to believe that the operational efficiency (measured by RTM/gal) is also strongly dependent on the square of locomotive speed. Hence, our analytic will add the Locomotive Speed Squared as an additional feature for regression.
8+
9+
- **[demo-RTM-loco-java](demo-RTM-loco-java):** A Java implementation of the locomotive efficiency analytic
10+
- **[demo-RTM-loco-matlab-r2011b](demo-RTM-loco-matlab-r2011b):** A Matlab (r2011b) implementation of the locomotive efficiency analytic
11+
- **[demo-RTM-loco-py](demo-RTM-loco-py):** A Python implementation of the locomotive efficiency analytic
12+
13+
14+
## Analytic template
15+
This analytic takes in test and training data sets. The analytic returns the predicted RTM values for the test dataset and the R-squared measure the of the linear regression model. This structure is outlined in this [analytic template](demo-RTM-loco-template.json).
16+
17+
## Input format
18+
19+
The datasets must include the instantaneous values of the locomotive speed, wind speed, and the efficiency metric of the diesel locomotive, namely Revenue Ton Miles (RTM) per gallon. The expected JSON input data format, which includes training and test datasets, is as follows:
20+
21+
```
22+
{
23+
"train": {
24+
"loco_speed": <list of values of length N1>,
25+
"wind_speed": <list of values of length N1>,
26+
"RTM": <list of values of length N1>
27+
},
28+
"test": {
29+
"loco_speed": <list of values of length N2>,
30+
"wind_speed": <list of values of length N2>,
31+
"RTM": <list of values of length N2>
32+
}
33+
}
34+
```
35+
36+
See **[sampleInput.json](sampleInput.json)** for an example input file.
37+
38+
## Output format
39+
40+
Output includes the predicted values of RTM for the test dataset, and the R-squared measure of the linear regression model used to make the predictions:
41+
42+
```
43+
{
44+
"Prediction": [
45+
370.0659,
46+
366.4111,
47+
...
48+
366.0072,
49+
361.3121
50+
],
51+
"R2": [
52+
0.97671
53+
]
54+
}
55+
```
56+
57+
See **[sampleOutput.json](sampleOutput.json)** for an example output file.
58+
59+
### Additional Information
60+
We are oversimplifying the problem of creating analytics that model instantaneous operational efficiency of a diesel locomotive. The purpose of this sample analytic is to get you started on building and deploying your analytic in Predix Analytics Services.
61+
62+
For more information on developing analytics for use with the Predix Analytics platform, please visit the **[Analytic Development](https://www.predix.io/docs#Qd2kPYb7)** section of the Predix Analytics Services documentation on predix.io.
63+
64+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#Locomotive Efficiency Analytic in Java
2+
3+
In this problem, the goal is to model the instantaneous operational efficiency of a diesel locomotive based on some controllable and non-controllable factors. The total amount of useful work performed by a locomotive is typically measured in Revenue Ton Miles (RTM) which is calculated by multiplying the weight in tons of freight by the number of miles transported. Therefore, we will express operational efficiency of a diesel locomotive in Revenue Ton Miles (RTM) per gallon of fuel. There are several factors that contribute to the operational efficiency of a locomotive, such as, wind speed, locomotive speed, grade (slope) of track, locomotive design etc. However, to keep things simple, we will assume that under certain conditions, the instantaneous values of operational efficiency for a single locomotive become a function of locomotive speed and wind speed only. This is known as a regression problem. Owing to its simplicity, we will use Ordinary Least Squares Linear Regression (LR).
4+
5+
The dataset that we have at our disposal to model the problem consists of 1200 data points and each data point consists of three measurements -- Locomotive Speed, Wind Speed and RTM per gallon. For the current problem, we have a strong reason to believe that the operational efficiency (measured by RTM/gal) is also strongly dependent on the square of locomotive speed. Hence, our analytic will add the Locomotive Speed Squared as an additional feature for regression.
6+
7+
## Compiled binaries
8+
Refer to the [Releases](https://github.com/PredixDev/predix-analytics-sample/releases) page for compiled binaries you can upload directly to Predix Analytics.
9+
10+
## Pre-requisites
11+
To build and run this analytic, you will need to have the following:
12+
13+
- JDK 1.7+
14+
- Maven 3+
15+
16+
## Building, deploying and running the analytic
17+
1. From the demo-RTM-loco-java directory, run the `mvn clean install` command to build and perform the component test.
18+
2. Create an analytic in Analytics Catalog with the name "Demo RTM Java" and the version "v1".
19+
3. Upload the jar file demo-RTM-loco-java-1.0.0-SNAPSHOT.jar from the demo-RTM-loco-java/target directory and attach it to the created analytic entry.
20+
4. Deploy and test the analytic on Predix Analytics platform.
21+
22+
## Analytic template
23+
This analytic takes in test and training data sets. The analytic returns the predicted RTM values for the test dataset and the R-squared measure the of the linear regression model. This structure is outlined in this [analytic template](../demo-RTM-loco-template.json).
24+
25+
## Input format
26+
27+
The datasets must include the instantaneous values of the locomotive speed, wind speed, and the efficiency metric of the diesel locomotive, namely Revenue Ton Miles (RTM) per gallon. The expected JSON input data format, which includes training and test datasets, is as follows:
28+
29+
```
30+
{
31+
"train": {
32+
"loco_speed": <list of values of length N1>,
33+
"wind_speed": <list of values of length N1>,
34+
"RTM": <list of values of length N1>
35+
},
36+
"test": {
37+
"loco_speed": <list of values of length N2>,
38+
"wind_speed": <list of values of length N2>,
39+
"RTM": <list of values of length N2>
40+
}
41+
}
42+
```
43+
44+
See **[sampleInput.json](../sampleInput.json)** for an example input file.
45+
46+
## Output format
47+
48+
Output includes the predicted values of RTM for the test dataset, and the R-squared measure of the linear regression model used to make the predictions:
49+
50+
```
51+
{
52+
"Prediction": [
53+
370.0659,
54+
366.4111,
55+
...
56+
366.0072,
57+
361.3121
58+
],
59+
"R2": [
60+
0.97671
61+
]
62+
}
63+
```
64+
65+
See **[sampleOutput.json](../sampleOutput.json)** for an example output file.
66+
67+
## Deploying the analytic to the Predix Cloud
68+
When you upload the jar file as an 'Executable' artifact the platform wraps the executable as a web service exposing the analytic via a URI derived from the analytic name.
69+
Requests made to this generated URI will be passed to the entry point method.
70+
71+
### Additional Information
72+
We are oversimplifying the problem of creating analytics that model instantaneous operational efficiency of a diesel locomotive. The purpose of this sample analytic is to get you started on building and deploying your analytic in Predix Analytics Services.
73+
74+
For more information on developing analytics for use with the Predix Analytics platform, please visit the **[Analytic Development](https://www.predix.io/docs#Qd2kPYb7)** section of the Predix Analytics Services documentation on predix.io.
75+
76+
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>com.ge.predix.insight</groupId>
7+
<artifactId>demo-RTM-loco-java</artifactId>
8+
<name>Demo adder analytic implementation</name>
9+
<packaging>jar</packaging>
10+
<description>Implementation of java demo analytic service</description>
11+
<version>1.0.0-SNAPSHOT</version>
12+
13+
<dependencies>
14+
15+
<dependency>
16+
<groupId>org.slf4j</groupId>
17+
<artifactId>slf4j-api</artifactId>
18+
<version>1.6.6</version>
19+
<scope>provided</scope>
20+
</dependency>
21+
<dependency>
22+
<groupId>com.fasterxml.jackson.core</groupId>
23+
<artifactId>jackson-core</artifactId>
24+
<version>2.4.1</version>
25+
<scope>provided</scope>
26+
</dependency>
27+
<dependency>
28+
<groupId>com.fasterxml.jackson.core</groupId>
29+
<artifactId>jackson-databind</artifactId>
30+
<version>2.4.1</version>
31+
<scope>provided</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>junit</groupId>
35+
<artifactId>junit</artifactId>
36+
<version>4.8.1</version>
37+
<scope>test</scope>
38+
</dependency>
39+
<dependency>
40+
<groupId>commons-io</groupId>
41+
<artifactId>commons-io</artifactId>
42+
<version>2.4</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.apache.commons</groupId>
46+
<artifactId>commons-math3</artifactId>
47+
<version>3.0</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.jvnet.jaxb2_commons</groupId>
51+
<artifactId>jaxb2-basics</artifactId>
52+
<version>0.6.4</version>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.jvnet.jaxb2_commons</groupId>
56+
<artifactId>jaxb2-basics-runtime</artifactId>
57+
<version>0.6.4</version>
58+
</dependency>
59+
</dependencies>
60+
61+
<build>
62+
<plugins>
63+
<plugin>
64+
<groupId>org.apache.maven.plugins</groupId>
65+
<artifactId>maven-compiler-plugin</artifactId>
66+
<configuration>
67+
<source>1.7</source>
68+
<target>1.7</target>
69+
</configuration>
70+
</plugin>
71+
<plugin>
72+
<groupId>org.apache.maven.plugins</groupId>
73+
<artifactId>maven-dependency-plugin</artifactId>
74+
<version>2.1</version>
75+
<executions>
76+
<execution>
77+
<id>copy-dependencies</id>
78+
<phase>prepare-package</phase>
79+
<goals>
80+
<goal>copy-dependencies</goal>
81+
</goals>
82+
<configuration>
83+
<outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
84+
<overWriteReleases>false</overWriteReleases>
85+
<overWriteSnapshots>false</overWriteSnapshots>
86+
<overWriteIfNewer>true</overWriteIfNewer>
87+
</configuration>
88+
</execution>
89+
</executions>
90+
</plugin>
91+
</plugins>
92+
</build>
93+
94+
</project>
95+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2015 - 2016 General Electric Company. All rights reserved.
3+
*
4+
* The copyright to the computer software herein is the property of
5+
* General Electric Company. The software may be used and/or copied only
6+
* with the written permission of General Electric Company or in accordance
7+
* with the terms and conditions stipulated in the agreement/contract
8+
* under which the software has been supplied.
9+
*/
10+
11+
package com.ge.predix.analytics.customdto;
12+
13+
public class LocoRegressionRequest {
14+
15+
protected WindLocoRTMValues test;
16+
protected WindLocoRTMValues train;
17+
18+
public WindLocoRTMValues getTest() {
19+
return test;
20+
}
21+
22+
public void setTest(WindLocoRTMValues test) {
23+
this.test = test;
24+
}
25+
26+
public WindLocoRTMValues getTrain() {
27+
return train;
28+
}
29+
30+
public void setTrain(WindLocoRTMValues train) {
31+
this.train = train;
32+
}
33+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2015 - 2016 General Electric Company. All rights reserved.
3+
*
4+
* The copyright to the computer software herein is the property of
5+
* General Electric Company. The software may be used and/or copied only
6+
* with the written permission of General Electric Company or in accordance
7+
* with the terms and conditions stipulated in the agreement/contract
8+
* under which the software has been supplied.
9+
*/
10+
11+
package com.ge.predix.analytics.customdto;
12+
13+
import java.util.Arrays;
14+
15+
import com.fasterxml.jackson.annotation.JsonProperty;
16+
17+
public class LocoRegressionResponse {
18+
19+
@JsonProperty(value = "R2")
20+
protected double[] r2;
21+
22+
@JsonProperty(value = "Prediction")
23+
protected double[] prediction;
24+
25+
@Override public boolean equals(Object o) {
26+
if (this == o)
27+
return true;
28+
if (o == null || getClass() != o.getClass())
29+
return false;
30+
31+
LocoRegressionResponse that = (LocoRegressionResponse) o;
32+
33+
if (!Arrays.equals(r2, that.r2))
34+
return false;
35+
return Arrays.equals(prediction, that.prediction);
36+
37+
}
38+
39+
@Override public int hashCode() {
40+
int result = Arrays.hashCode(r2);
41+
result = 31 * result + Arrays.hashCode(prediction);
42+
return result;
43+
}
44+
45+
@Override public String toString() {
46+
return "LocoRegressionResponse{" +
47+
"r2=" + Arrays.toString(r2) +
48+
", prediction=" + Arrays.toString(prediction) +
49+
'}';
50+
}
51+
52+
public double[] getR2() {
53+
return r2;
54+
}
55+
56+
public void setR2(double[] r2) {
57+
this.r2 = r2;
58+
}
59+
60+
public double[] getPrediction() {
61+
return prediction;
62+
}
63+
64+
public void setPrediction(double[] prediction) {
65+
this.prediction = prediction;
66+
}
67+
}

0 commit comments

Comments
 (0)