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
160 changes: 80 additions & 80 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless

# FuseBox cache
.fusebox/

lib
lib-esm

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless
# FuseBox cache
.fusebox/
lib
lib-esm
.DS_Store
34 changes: 15 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<img alt="NMReDATA" src="images/linear_assignment.svg">
</p>


This package is the implementation of Jonker-Volgenant shortest
augmenting path algorithm based on the publication [On implementing 2D rectangular assignment algorithms](https://doi.org/10.1109/TAES.2016.140952)

Expand All @@ -17,30 +16,28 @@ If the number of rows is <= the number of columns, then every row is assigned to

`$ npm i linear-sum-assignment`


## Usage

```js
import linearSumAssignment from 'linear-sum-assignment';
import { xCostMatrix } from 'ml-spectra-processing';

/**
* there is one more value in the experimental values, so one of
* them will be not assigned.
**/
const xValueExperimental = [1, 2, 3, 4, 5, 7];
const xValuePredicted = [3.1, 1.1, 1.9, 3.99, 5.2];
const experimental = [1, 2, 3, 4, 5, 7];
const predicted = [3.1, 1.1, 1.9, 3.99, 5.2];

/**
* We will compute a cost matrix where xValueExperimental are
* rows and xValuePredicted in columns.
* We will compute a cost matrix where experimental are
* rows and predicted in columns.
* In this case we will look for the closest peak for each experimental peak value.
**/
const diff = xValueExperimental.map((experimental) => {
return xValuePredicted.map((predicted) => {
return Math.abs(predicted - experimental);
});
});

const diff = xCostMatrix(experimental, predicted, {
fct: (a, b) => Math.abs(a - b),
});
const result = linearSumAssignment(diff, { maximaze: false });
console.log(result);
/**
Expand All @@ -57,16 +54,15 @@ console.log(result);
],
dualVariableForRows: Float64Array(6) [ 0, 0, 0, 0, 0, 0 ]
}
*/
*/
```

`rowAssignments` contains the index of the column assigned to each element in the rows (xValueExperimental). So the first element in xValueExperimental array is assigned to the second element of xValuePredicted.
`columnAssignments` contains the index of the row assigned to
each element in the columns. So the first element in
xValuePredicted is assigned to third element in
xValueExperimental.
`dualVariableForColumns` and `dualVariableForRows` are the Lagrange multipliers or dual variables.
`gain` the sum of the elements in the cost matrix.
`rowAssignments` contains the index of the column assigned to each element in the rows (experimental).

`columnAssignments` contains the index of the row assigned to each element in the columns. So the first element in predicted is assigned to third element in experimental.
`dualVariableForColumns` and `dualVariableForRows` are the Lagrange multipliers or dual variables.
`gain` the sum of the elements in the cost matrix.

## License

[MIT](./LICENSE)
Expand Down
Loading