Skip to content

dmi3coder/behaiv-java

Repository files navigation

Behaiv: User Behavior Prediction for everyone

Behaiv logo

Build Status Coverage Status Java version (Not Java?)

Wow, you've found Behaiv!

Behaiv is a high-level AI tool that helps users to navigate faster through the app, predict what users want to open and take appropriate actions. It was developed with a focus on simplicity of usage. Instead of overwhelming developers with burden of implementation, they only need to write few lines of code.

(Largely inspired by app suggestion in IOS.) Chat example

Getting started: 30 seconds of Behaiv

Main object in Behaiv is, in fact, Behaiv. This is the class that you'll access all the time. To init this class, use a static method Behaiv.with(id) where id is unique value that will be used to restore your data on restart. Behaiv itself is a semi-builder, you don't need to call .build() on it. In upcoming version you'll be able to add more providers any time.

Behaiv behaiv = new Behaiv.Builder("myId")
                .setProvider(new DayTimeProvider())
                // add more providers
                .setStorage(new SimpleStorage(storageDirectoryFile))
                .build();

Done, in order to start capturing user's behavior you need to call next methods:

  • behaiv.startCapturing(predict) in order to start capturing parameters for prediction, it takes optional variable to trigger prediction, if it's false, it won't predict. behaiv.startCapturing() will trigger providers to get all the data needed for prediction.
  • behaiv.registerLabel(label) to attach label or result of parameters. Without it data won't be saved.
  • behaiv.stopCapturing(discard) to save and train network if threshold is reached.
behaiv.startCapturing(true);

//user takes actions
behaiv.registerLabel("Lili_12345 chat")
behaiv.stopCapturing(false)

In order to use prediction, you need to subscribe for them. If behaiv.startCapturing(false) was used, you won't receive prediction

//call this before behaiv.startCapturing(true);
behaiv.subscribe().subscribe(predictionLabel -> {
            // snow prediction on ui
        });

That's all, everything else is handled by Behaiv

For more in-depth tutorial about Behaiv you can checkout:

How to use in Android?

  1. Add dependency as in gradle section
  2. Instantiate Behaiv.Builder object in Application with new Behaiv.Builder(id)
  3. If needed, change Kernel type with .setKernel(Kernel) on a Builder
    1. DummyKernel doesn't do any computations, only suggest most similar result by comparing count of steps(deprecated)
    2. LogisticRegressionKernel uses Logistic Regression to predict actions.
    3. RemoteKernel(not implemented yet), sends data to a API, depending on type of an API receives suggested action or receives model
  4. Provide external factors with Builder.setProvider()such as GPS, Wifi/Bluetooth and headphons info.
    1. Use DayTimeProvider to use time of a day as a features
    2. Use GpsProvider for adding GPS feature into prediction from behaiv-android
    3. Use NetworkProvider for adding Wifi, Bluetooth and Network features into prediction(TODO)
    4. Use HeadsetProvider to include headphones feature into predcition(TODO)
    5. There's more options like Weather and Firebase provides, see more at (TODO)
    6. Use SyntheticProvider to include custom self-made features into prediction (e.g)(TODO, can be implemented easily)
  5. Build Behaiv object by calling Builder.build()
  6. Set threshold after which Behaiv can start suggesting with .setThreshold(int)
  7. Subscribe to predictions in main view e.g MainActivity with behaiv.subscribe().subscribe(predictionLabel -> {})
    1. When prediction received, do a switch/when and show option for user to open
  8. When view is ready for usage by user, call behaiv.startCapturing(true) e.g in onViewCreated() or onCreate()
  9. Find objects to target(e.g chats with user) and when user clicks on target, execute behaiv.registerLabel(String)
  10. At the same time call behaiv.stopCapturing(false) if you're sure that it's correct action.

Model uses "Continuous learning" so it will be trained as long as more features will arrive. To see model in action you need to wait amount of examples reach threshold.

Installation

We use jitpack for now. Beware that in near future we can migrate to different maven repository. Add it in your root build.gradle at the end of repositories:

Latest tag is

Gradle

Step 1. Add the JitPack repository to your build file

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency

dependencies {
        implementation 'com.github.dmi3coder:behaiv-java:0.4.10-alpha'
}

Maven

Step 1. Add the JitPack repository to your build file

<repositories>
	<repository>
	    <id>jitpack.io</id>
	    <url>https://jitpack.io</url>
	</repository>
</repositories>

Step 2. Add the dependency

<dependency>
    <groupId>com.github.dmi3coder</groupId>
    <artifactId>behaiv-java</artifactId>
    <version>0.4.10-alpha</version>
</dependency>

Look at more information about build on Jitpack

Want to help?

Behaiv project is really open for help. If you want to help this project to shine, I firstly suggest you to contact me(Dmytro Chaban) by any convinient way e.g email. Second thing is to look at issues. Another way is to spread this project to your friends and contacts, it'll help bring more developers to this project. Reporting issues with project wont hurt also ;)

Looking for other languages?

Behaiv has different implementations(though many of them is in progress of development).

Project Language Version/Arriving date Developed by
behaiv-android(extension) Java dmi3coder
behaiv-swift Swift 2Q 2020 DonauTech & dmi3coder
behaiv-remote-kernel Python(Backend) Release DonauTech & dmi3coder
behaiv-js JavaScript 2Q 2020 DonauTech & dmi3coder