@qe-libs/rena-wasm 0.1.15 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,31 +21,53 @@ npm install @qe-libs/rena-wasm
21
21
 
22
22
  ## Quick Start
23
23
 
24
- ```js
24
+ On [qe-libs.org/npm/qe-libs-rena-wasm/](https://qe-libs.org/npm/qe-libs-rena-wasm/)
25
+ the examples marked `js run` have a **Run** button: they run in your browser,
26
+ on the WebAssembly build, against `demo/RS.csv` (rENA's `RS.data`, shipped in
27
+ this package without its `text` column). There, `console.log` prints under the
28
+ example, `demo.csv(url)` loads a CSV into row objects and `demo.plot(model, opts)`
29
+ draws the model with [`@qe-libs/qeviz`](https://qe-libs.org/npm/qe-libs-qeviz/);
30
+ `demo` exists only on that page.
31
+
32
+ ```js run
25
33
  import loadENA from '@qe-libs/rena-wasm';
26
34
 
27
- const ena = await loadENA();
35
+ const ena = await loadENA();
36
+ const rows = await demo.csv('@qe-libs/rena-wasm/demo/RS.csv');
28
37
 
29
38
  const model = ena.fit(rows, {
30
- codes: ['Data', 'Technical.Constraints', 'Performance.Parameters'],
31
- units: ['UserName', 'Condition'],
39
+ codes: ['Data', 'Technical.Constraints', 'Performance.Parameters',
40
+ 'Client.and.Consultant.Requests', 'Design.Reasoning', 'Collaboration'],
41
+ units: ['Condition', 'UserName'],
32
42
  conversations: ['Condition', 'GroupName'],
33
43
  window: 4,
34
44
  dims: 2,
35
45
  });
36
46
 
47
+ console.log(model.nUnits, 'units,', model.nConnections, 'connections');
48
+ console.log('axes:', model.rotation.columnNames, 'variance explained:', model.model.variance.slice(0, 2));
49
+ console.log('first unit:', model.model.unitLabels[0], model.centroid(model.model.unitLabels[0]));
50
+
51
+ // Colour by the first unit column (Condition); subtract the two conditions' mean networks
52
+ await demo.plot(model, { group: 0, edges: ['FirstGame', 'SecondGame'] });
53
+ ```
54
+
55
+ The fitted model:
56
+
57
+ ```js
37
58
  model.model.centroids // Float64Array nUnits × dims
38
59
  model.lineWeights // Float64Array nUnits × nConnections (normed)
39
60
  model.connectionCounts // Float64Array nUnits × nConnections (unit counts, before normalisation)
40
61
  model.rowConnectionCounts // Float64Array nRows × nConnections (each row's counts after binarize / weight; rows sum to connectionCounts)
62
+ model.points // Float64Array nUnits × dims (projected positions)
41
63
  model.rotation.nodes // Float64Array nCodes × dims
42
64
  model.connectionNames // ['Data & Technical.Constraints', ...]
43
- model.model.unitLabels // ['UserName1_ConditionA', ...]
65
+ model.model.unitLabels // ['FirstGame__steven z', ...] — unit column values joined with '__'
44
66
  model.rotation.columnNames // ['SVD1', 'SVD2']
45
67
 
46
68
  // Per-unit helpers
47
- model.centroid('Alice_A') // number[] length = dims
48
- model.network('Alice_A') // number[] length = nConnections
69
+ model.centroid('FirstGame__steven z') // number[] length = dims
70
+ model.network('FirstGame__steven z') // number[] length = nConnections
49
71
  ```
50
72
 
51
73
  ---
@@ -57,14 +79,33 @@ model.network('Alice_A') // number[] length = nConnections
57
79
  | SVD (default) | `'svd'` | — |
58
80
  | Means | `'mean'` | `groupA: [unitIdx, ...]`, `groupB: [unitIdx, ...]` |
59
81
 
60
- ```js
82
+ ```js run
61
83
  // Means rotation — groupA/groupB are unit indices (position in unitLabels)
84
+ import loadENA from '@qe-libs/rena-wasm';
85
+
86
+ const ena = await loadENA();
87
+ const rows = await demo.csv('@qe-libs/rena-wasm/demo/RS.csv');
88
+ const opts = {
89
+ codes: ['Data', 'Technical.Constraints', 'Performance.Parameters',
90
+ 'Client.and.Consultant.Requests', 'Design.Reasoning', 'Collaboration'],
91
+ units: ['Condition', 'UserName'],
92
+ conversations: ['Condition', 'GroupName'],
93
+ window: 4,
94
+ };
95
+
96
+ // Unit keys are the unit columns joined with '__': 'FirstGame__steven z'
97
+ const labels = ena.fit(rows, opts).model.unitLabels;
98
+ const idx = cond => labels.flatMap((u, i) => u.startsWith(cond + '__') ? [i] : []);
99
+
62
100
  const model = ena.fit(rows, {
63
- codes, units, conversations,
101
+ ...opts,
64
102
  rotation: 'mean',
65
- groupA: [0, 1, 2],
66
- groupB: [3, 4, 5],
103
+ groupA: idx('FirstGame'),
104
+ groupB: idx('SecondGame'),
67
105
  });
106
+ console.log('axes:', model.rotation.columnNames);
107
+
108
+ await demo.plot(model, { group: 0, edges: ['FirstGame', 'SecondGame'] });
68
109
  ```
69
110
 
70
111
  ---