Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .idea/dictionaries/dmi3y.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

456 changes: 337 additions & 119 deletions .idea/workspace.xml

Large diffs are not rendered by default.

File renamed without changes.
Binary file added docs/img/get_features_flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/get_prediction_flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Mon Sep 09 10:39:48 EEST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6-all.zip
7 changes: 4 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ Predict what users want to open and take appropriate actions
1. `RemoteKernel`, sends data to a API, depending on type of an API receives suggested action or receives model
1. Set threshold after which Behaiv can start suggesting
1. Register each view that can be tracked and opened by implementing interfaces
1. `Actionable` is a type of view that can be opened by *Behaiv*
1. `Routable` is a type of View that only cannot be opened but only route into next Views
1. `Conditionable` is a type of View which will perform additional actions before proceeding
1. `InitiableNode` is a type of view that can initiate capturing of features
1. `ActionableNode` is a type of view that can be opened by *Behaiv*, as well as capture labels
1. `RoutableNode` is a type of View that only cannot be opened but only route into next Views
1. `ConditionableNode` is a type of View which will perform additional actions before proceeding
1. Provide external factors sich as GPS, Wifi/Bluetooth and headphons info.
1. Use `GeoProvider` for adding GPS feature into prediction
1. Use `NetworkProvider` for adding Wifi, Bluetooth and Network features into prediction
Expand Down
25 changes: 23 additions & 2 deletions src/main/java/de/dmi3y/behaiv/Behaiv.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,29 @@
*/
package de.dmi3y.behaiv;

import de.dmi3y.behaiv.kernel.Kernel;

public class Behaiv {
public boolean someLibraryMethod() {
return true;

private Kernel kernel;

private Behaiv() {

}

public synchronized static Behaiv with(Kernel kernel) {
Behaiv behaiv = new Behaiv();
behaiv.setKernel(kernel);
return behaiv;

}

public Behaiv setKernel(Kernel kernel){
this.kernel = kernel;
return this;
}

public Behaiv setBehaivNode() {
return this;
}
}
25 changes: 25 additions & 0 deletions src/main/java/de/dmi3y/behaiv/kernel/DummyKernel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package de.dmi3y.behaiv.kernel;

import org.apache.commons.math3.util.Pair;

import java.util.ArrayList;
import java.util.Comparator;

public class DummyKernel extends Kernel {

@Override
public String predictOne(ArrayList<Double> features) {

return this.data.stream().map(featuresIter -> {
Double result = 0.0;
for (int i = 0; i < featuresIter.getFirst().size(); i++) {
if (featuresIter.getFirst().get(i).equals(features.get(i))) {
result += (1.0 / features.size());
}
}
featuresIter.getFirst().add(result);
return featuresIter;
}).max(Comparator.comparingDouble(one -> one.getFirst().get(one.getFirst().size() - 1))).map(it -> it.getSecond()).orElse(null);
}

}
29 changes: 29 additions & 0 deletions src/main/java/de/dmi3y/behaiv/kernel/Kernel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package de.dmi3y.behaiv.kernel;

import org.apache.commons.math3.util.Pair;

import java.util.ArrayList;

public abstract class Kernel {

private Long treshold = 10L;

protected ArrayList<Pair<ArrayList<Double>, String>> data;

public void fit(ArrayList<Pair<ArrayList<Double>, String>> data) {
this.data = data;
}

public void setTreshold(Long treshold) {
this.treshold = treshold;
}

public boolean readyToPredict() {
return data.size() > treshold;
}

public void update(ArrayList<Pair<ArrayList<Double>, String>> data) {
}

public abstract String predictOne(ArrayList<Double> features);
}
8 changes: 8 additions & 0 deletions src/main/java/de/dmi3y/behaiv/node/ActionableNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.dmi3y.behaiv.node;

import de.dmi3y.behaiv.Behaiv;

public interface ActionableNode {
void register(Behaiv behaiv);
void captureResult(Behaiv behaiv);
}
4 changes: 4 additions & 0 deletions src/main/java/de/dmi3y/behaiv/node/BehaivNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package de.dmi3y.behaiv.node;

public interface BehaivNode {
}
120 changes: 120 additions & 0 deletions src/test/java/de/dmi3y/behaiv/kernel/DummyKernelTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package de.dmi3y.behaiv.kernel;

import org.apache.commons.math3.util.Pair;
import org.junit.Test;

import java.util.ArrayList;

import static org.junit.Assert.*;

public class DummyKernelTest {

public static Double[] HOME = {1.1, 1.2};
public static Double[] GYM = {2.1, 2.2};
public static Double[] JOG = {3.1, 3.2};
public static Double[] WORK = {5.1, 5.2};


@Test
public void predictOne() {
ArrayList<Double> list = new ArrayList<>();
ArrayList<Pair<ArrayList<Double>, String>> data = new ArrayList<>();


list.add(5 * 60 + 00.0);
list.add(HOME[0]);
list.add(HOME[1]);
list.add(0.0);
data.add(new Pair<>(list,"SELFIMPROVEMENT_SCREEN"));
list = new ArrayList<>();
list.add(5 * 60 + 10.0);
list.add(HOME[0]);
list.add(HOME[1]);
list.add(0.0);
data.add(new Pair<>(list,"SELFIMPROVEMENT_SCREEN"));
list = new ArrayList<>();
list.add(6 * 60 + 10.0);
list.add(GYM[0]);
list.add(GYM[1]);
list.add(1.0);
data.add(new Pair<>(list,"SPORT_SCREEN"));
list = new ArrayList<>();
list.add(7 * 60 + 30.0);
list.add(HOME[0]);
list.add(HOME[1]);
list.add(1.0);
data.add(new Pair<>(list,"SELFIMPROVEMENT_SCREEN"));
list = new ArrayList<>();
list.add(8 * 60 + 30.0);
list.add(WORK[0]);
list.add(WORK[1]);
list.add(0.0);
data.add(new Pair<>(list,"WORK_SCREEN"));
list = new ArrayList<>();
list.add(10 * 60 + 30.0);
list.add(WORK[0]);
list.add(WORK[1]);
list.add(1.0);
data.add(new Pair<>(list,"WORK_SCREEN"));
list = new ArrayList<>();
list.add(11 * 60 + 30.0);
list.add(WORK[0]);
list.add(WORK[1]);
list.add(1.0);
data.add(new Pair<>(list,"WORK_SCREEN"));
list = new ArrayList<>();
list.add(16 * 60 + 30.0);
list.add(WORK[0]);
list.add(WORK[1]);
list.add(0.0);
data.add(new Pair<>(list,"WORK_SCREEN"));
list = new ArrayList<>();
list.add(17 * 60 + 10.0);
list.add(WORK[0]);
list.add(WORK[1]);
list.add(0.0);
data.add(new Pair<>(list,"WORK_SCREEN"));
list = new ArrayList<>();
list.add(18 * 60 + 50.0);
list.add(WORK[0]);
list.add(WORK[1]);
list.add(0.0);
data.add(new Pair<>(list,"WORK_SCREEN"));
list = new ArrayList<>();
list.add(19 * 60 + 5.0);
list.add(JOG[0]);
list.add(JOG[1]);
list.add(1.0);
data.add(new Pair<>(list,"SPORT_SCREEN"));
list = new ArrayList<>();
list.add(19 * 60 + 10.0);
list.add(JOG[0]);
list.add(JOG[1]);
list.add(1.0);
data.add(new Pair<>(list,"SPORT_SCREEN"));
list = new ArrayList<>();
list.add(19 * 60 + 25.0);
list.add(JOG[0]);
list.add(JOG[1]);
list.add(1.0);
data.add(new Pair<>(list,"SPORT_SCREEN"));
list = new ArrayList<>();
list.add(21 * 60 + 00.0);
list.add(HOME[0]);
list.add(HOME[1]);
list.add(0.0);
data.add(new Pair<>(list,"ADD_SCREEN"));
list = new ArrayList<>();
DummyKernel dummyKernel = new DummyKernel();
dummyKernel.fit(data);
ArrayList<Double> predictList = new ArrayList<>();
predictList.add(10 * 60 + 30.0);
predictList.add(WORK[0]);
predictList.add(WORK[1]);
predictList.add(1.0);

dummyKernel.update(null);
String prediction = dummyKernel.predictOne(predictList);
assertEquals("WORK_SCREEN", prediction);
}
}