项目作者: hghhgh

项目描述 :
Decision Making or Support library for Javascript
高级语言: JavaScript
项目地址: git://github.com/hghhgh/dm4js.git
创建时间: 2017-11-16T11:00:53Z
项目社区:https://github.com/hghhgh/dm4js

开源协议:

下载


dm4js

This library is a library for customer to make better decision.

  • Currently the linear scalarization multi objective optimization is added to the library. This technique score chices based on pre-defined wiegth vector and the minimize a linear function and select the lowest score. Each value can be select to be maximize or minize.

    • The chooseLinear(.,.) function first normalize the choices vector and then select the best.
      To know how algorithm find best choice use this link.
  • and Bayesian inference for diagnosis

Adding library

npm library > here

  1. npm i --save dm4js

Dependency

Currently there is only one dependecy for optimization algoritm. The library is ‘genetic-js’ witch can be find here.
To install dependency use command below :

  1. npm install genetic-js

Usage example

See test file for more examples !.

A simple usage of ‘chooseLinear’ is as below :

  1. let dmjs = require('dm4js');
  2. let model = [
  3. {
  4. label: 'price',
  5. weight: .5,
  6. shouldbe: 'min',
  7. type: 'numerical'
  8. },
  9. {
  10. label: 'capacity',
  11. weight: .4,
  12. shouldbe: 'max',
  13. type: 'numerical'
  14. },
  15. {
  16. label: 'lifetime',
  17. weight: .6,
  18. shouldbe: 'max',
  19. type: 'numerical'
  20. },
  21. {
  22. label: 'flashtype',
  23. weight: .3,
  24. shouldbe: 'max',
  25. type: 'ordered',
  26. categories: ['', 'TLC', '3D NAND', 'MLC', 'SLC'] // latest is the best
  27. }
  28. ];
  29. let choices = [
  30. [361000, 240, 1000000, 'TLC'], // SSD Panther AS330
  31. [425000, 240, 1750000, 'MLC'], // SSD San Disk SSD PLUS
  32. [300000, 240, 1500000, 'TLC'], // SSD Pioneer APS-SL2
  33. [395000, 240, 2000000, '3D NAND'] // SSD Adata SU650
  34. ];
  35. let bestChoice = dmjs.chooseLinear(model, choices).BestIndex;

bestChoice is 2 which means SSD Pioneer APS-SL2 is the best.

Extracting a Model

We use genetic algorithm to find desired model. The genetic algorithm is a global optimizer that means if there is a solution it can find it, and the result model is global optimum if the algorithm runs enough iterations.
To find a model that fits on an ordered choices is as below :

  1. let model = [
  2. {
  3. label: 'price',
  4. // weight: .5,
  5. weight: .0,
  6. shouldbe: 'min',
  7. type: 'numerical'
  8. },
  9. {
  10. label: 'capacity',
  11. // weight: .4,
  12. weight: .0,
  13. shouldbe: 'max',
  14. type: 'numerical'
  15. },
  16. {
  17. label: 'lifetime',
  18. // weight: .6,
  19. weight: .0,
  20. shouldbe: 'max',
  21. type: 'numerical'
  22. },
  23. {
  24. label: 'flashtype',
  25. // weight: .3,
  26. weight: .0,
  27. shouldbe: 'max',
  28. type: 'ordered',
  29. categories: ['', 'TLC', '3D NAND', 'MLC', 'SLC'] // latest is the best
  30. }
  31. ];
  32. let choices = [
  33. [300000, 240, 1500000, 'TLC'], // SSD Pioneer APS-SL2
  34. [425000, 240, 1750000, 'MLC'], // SSD San Disk SSD PLUS
  35. [395000, 240, 2000000, '3D NAND'], // SSD Adata SU650
  36. [361000, 240, 1000000, 'TLC'], // SSD Panther AS330
  37. ];
  38. let themodel = dm4js.findLinearModelWeights(model, choices, 1000);

This function map our oppinion in prioritising products, it means that if we create a list of our faivorit products and this list will be ordered from best to worst, in fact we have an oppinion in our mind that make us to create these list. This oppinion can be modeled linearly as a weights of a linear model. The function : findLinearModelWeights can find this model.

Other Functions

There are more functions in the library as below :

  1. /*
  2. Note : The diffrence of this function with 'findLinearModelWeights' is that this function find a model such that
  3. the score of choices in ordered list be as largest as possible. But it take long time to converge, although may not
  4. be efficient
  5. */
  6. findLinearModelWeights(ZeroWeightModel, OrderedBestChoices, iteration)

My steps to Publish

code => test => publish => revise code => test => publish new version …