Giter Site home page Giter Site logo

pberlandier / model-duality Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 66 KB

This code sample shows how using the dual version of an intuitive model can yield expressivity and performance benefits.

Java 100.00%
object-model business-rules modeling odm xom

model-duality's Introduction

Using a dual model for expressivity and performance

This repo shows how using a dual view on an object model can improve the expressivity and performance of business decisions defined with business rules.

The example implemented is loosely based on worker compensation / benefits calculation: a worker is associated with a time period that captures different characteristics for each day in that period, such as whether the day is a site holiday or the worker has worked on that specific day. A simple object model for the rules can rely on a class that represents a Day with one attribute for each characteristic and create a Day instance for each day in the time period.

The issue with such a design is that it leads to:

  • Quasi-linear degradation of the runtime performance as the number of days in the considered time period is increasing.

  • Lower expressivity as most of the operations performed by the rules are about computing aggregated values on the time period.

This is when taking a dual point of view on the model is useful. In our example, instead of using a list of day instances that are characterized by a set of properties, we can choose to use a set of properties that are characterized by the set of days to which they apply. This idea is illustrated by the figure below:

  • The red outline shows the simple model, where the days are entities with properties such as site holiday or worked and a decision service execution involves potentially thousands of instances of day entities.

  • The green outline is the dual model, where property objects capture the property values for each day. Here, there’s only a handful of property objects to manage.

Once the dual view is adopted, an optimized implementation can be selected. In our example, the collection of boolean values for a property can be efficiently represented using a Java Bitset. Such an implementation is compact in memory and allows to perform batch logical operations on properties.

For categorical (non-boolean) properties, we can keep a bit-set implementation by using technique such as one-hot encoding, commonly used for machine learning models.

The projects in this repo are based on ODM 8.10.4.

model-duality's People

Contributors

pberlandier avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.