Commit e93bdce74792012b7125e1eaaa340c415c6025c5

Authored by Benjamin Renard
1 parent 00a63bd4
Exists in mlplasmas and in 1 other branch cu2022

Add args & hyperparameters fields in MachineLearning UI

js/app/models/MLModelObject.js
... ... @@ -20,6 +20,9 @@ Ext.define('amdaModel.MLModelObject', {
20 20 fields : [
21 21 {name: 'name', type: 'string'},
22 22 {name: 'description', type: 'string'},
23   - {name: 'output', type: 'auto'}
  23 + {name: 'output', type: 'auto'},
  24 + {name: 'args', type: 'auto'},
  25 + {name: 'hyperparameters', type: 'auto'},
  26 + {name: 'defaults', type: 'auto'},
24 27 ]
25 28 });
... ...
js/app/models/MachineLearningRun.js
... ... @@ -24,10 +24,12 @@ Ext.define('amdaModel.MachineLearningRun', {
24 24 {name: 'mode', type: 'string'},
25 25 {name: 'start', type : 'date', defaultValue : new Date()},
26 26 {name: 'stop', type : 'date', defaultValue : new Date()},
27   - {name: 'output', type: 'auto', defaultValue : null}
  27 + {name: 'output', type: 'auto', defaultValue : null},
  28 + {name: 'args', type: 'auto', defaultValue : null},
  29 + {name: 'hyperparameters', type: 'auto', defaultValue : null},
28 30 ],
29 31  
30   - propertiesToCopy : 'id,name,moduleId,start,stop,output',
  32 + propertiesToCopy : 'id,name,moduleId,start,stop,output,args,hyperparameters',
31 33  
32 34 getJsonValues : function(){
33 35 var myValues = new Object();
... ... @@ -36,8 +38,15 @@ Ext.define('amdaModel.MachineLearningRun', {
36 38 myValues.mode = this.get('mode');
37 39 myValues.startDate = this.get('start');
38 40 myValues.stopDate = this.get('stop');
39   - myValues.params = {'parameter': 'imf'};
40 41 myValues.output = this.get('output');
  42 + myValues.args = {}
  43 + if (this.get('args')) {
  44 + myValues.args = this.get('args');
  45 + }
  46 + myValues.hyperparameters = {};
  47 + if (this.get('hyperparameters')) {
  48 + myValues.hyperparameters = this.get('hyperparameters');
  49 + }
41 50 return myValues;
42 51 }
43 52  
... ...
js/app/views/MachineLearningUI.js
... ... @@ -52,17 +52,69 @@ Ext.define('amdaUI.MachineLearningUI', {
52 52 },
53 53  
54 54 createPredictionUI: function() {
  55 + var me = this;
55 56 this.predictionUI = Ext.create('Ext.form.Panel', {
56 57 items: [
57 58 {
58   - xtype: 'datefield', name: 'start', fieldLabel: 'Start Time',
  59 + xtype: 'datefield', id: 'prediction-start', name: 'start', fieldLabel: 'Start Time',
59 60 format: 'Y-m-d\\TH:i:s'
60 61 },
61 62 {
62   - xtype: 'datefield', name: 'stop', fieldLabel: 'Stop Time',
  63 + xtype: 'datefield', id: 'prediction-stop', name: 'stop', fieldLabel: 'Stop Time',
63 64 format: 'Y-m-d\\TH:i:s'
64   - }
65   - ]
  65 + },
  66 + {
  67 + xtype: 'fieldset', id: 'prediction-args', title: 'Input arguments', hidden: true
  68 + },
  69 + {
  70 + xtype: 'fieldset', id: 'prediction-hyperparameters', title: 'Hyper parameters', hidden: true, enable: false
  71 + },
  72 + ],
  73 + setModel: function(modelinfo) {
  74 + var defaultValues = modelinfo.get('defaults');
  75 + if (!defaultValues) defaultValues = {};
  76 +
  77 + if (defaultValues['start'])
  78 + me.predictionUI.queryById('prediction-start').setValue(defaultValues['start']);
  79 +
  80 + if (defaultValues['stop'])
  81 + me.predictionUI.queryById('prediction-stop').setValue(defaultValues['stop']);
  82 +
  83 + var args = modelinfo.get('args');
  84 + if (!args) args = [];
  85 + me.predictionUI.queryById('prediction-args').setVisible(args.length > 0);
  86 + me.predictionUI.queryById('prediction-args').removeAll();
  87 + Ext.Array.each(args, function(arg) {
  88 + if (arg == 'start' || arg == 'stop') {
  89 + return;
  90 + }
  91 + var field = me.predictionUI.queryById('prediction-args').add({
  92 + xtype: 'textfield',
  93 + fieldLabel: arg,
  94 + name: arg,
  95 + allowBlank: false
  96 + });
  97 + if (defaultValues[arg]) {
  98 + field.setValue(defaultValues[arg]);
  99 + }
  100 + });
  101 +
  102 + var hyperparameters = modelinfo.get('hyperparameters');
  103 + if (!hyperparameters) hyperparameters = [];
  104 + me.predictionUI.queryById('prediction-hyperparameters').setVisible(hyperparameters.length > 0);
  105 + me.predictionUI.queryById('prediction-hyperparameters').removeAll();
  106 + Ext.Array.each(hyperparameters, function(hyperparam) {
  107 + var field = me.predictionUI.queryById('prediction-hyperparameters').add({
  108 + xtype: 'textfield',
  109 + fieldLabel: hyperparam,
  110 + name: hyperparam,
  111 + allowBlank: false
  112 + });
  113 + if (defaultValues[hyperparam]) {
  114 + field.setValue(defaultValues[hyperparam]);
  115 + }
  116 + });
  117 + }
66 118 });
67 119 return this.predictionUI;
68 120 },
... ... @@ -70,7 +122,10 @@ Ext.define('amdaUI.MachineLearningUI', {
70 122 createFittingUI: function() {
71 123 this.fittingUI = Ext.create('Ext.form.Panel', {
72 124 items: [
73   - ]
  125 + ],
  126 + setModel: function(modelinfo) {
  127 +
  128 + }
74 129 });
75 130 return this.fittingUI;
76 131 },
... ... @@ -99,7 +154,6 @@ Ext.define('amdaUI.MachineLearningUI', {
99 154 this.createPredictionUI()
100 155 ],
101 156 bbar: [
102   - '->',
103 157 {xtype: 'button', text: 'Run Prediction', handler: this.runPredictionRequest, scope: me}
104 158 ]
105 159 },
... ... @@ -117,14 +171,11 @@ Ext.define('amdaUI.MachineLearningUI', {
117 171 setModel: function(modelinfo) {
118 172 me.runModelObj.set('moduleId', modelinfo.get('id'));
119 173 me.runModelObj.set('output', modelinfo.get('output'));
  174 + var defaultValues = modelinfo.get('defaults');
  175 + if (!defaultValues) defaultValues = {};
  176 +
120 177 this.items.each(function(item) {
121   - Ext.Object.each(me.runModelObj.getData(), function(key, value) {
122   - if (key != 'mode') {
123   - var field = item.items.getAt(0).getForm().findField(key);
124   - if (field)
125   - field.setValue(value);
126   - }
127   - });
  178 + item.items.getAt(0).setModel(modelinfo);
128 179 });
129 180 }
130 181 }
... ... @@ -147,17 +198,35 @@ Ext.define('amdaUI.MachineLearningUI', {
147 198 },
148 199  
149 200 runRequest: function(mode) {
  201 + var currentUI = null;
150 202 switch (mode) {
151 203 case 'fitting':
152   - //this.fittingUI.getForm().updateRecord(this.runModelObj);
  204 + currentUI = this.fittingUI;
153 205 myDesktopApp.errorMsg('Not available in this version');
154 206 return;
155   - //break;
156 207 case 'prediction':
157   - this.predictionUI.getForm().updateRecord(this.runModelObj);
  208 + currentUI = this.predictionUI;
158 209 break;
159 210 }
  211 + currentUI.getForm().updateRecord(this.runModelObj);
160 212 this.runModelObj.set('mode', mode);
  213 +
  214 + var args = {};
  215 + if (currentUI.queryById(mode+'-args').isVisible()) {
  216 + currentUI.queryById(mode+'-args').items.each(function (item) {
  217 + args[item.name] = item.getValue();
  218 + });
  219 + }
  220 + this.runModelObj.set('args', args);
  221 +
  222 + var hyperparameters = {};
  223 + if (currentUI.queryById(mode+'-hyperparameters').isVisible()) {
  224 + currentUI.queryById(mode+'-hyperparameters').items.each(function (item) {
  225 + hyperparameters[item.name] = item.getValue();
  226 + });
  227 + }
  228 + this.runModelObj.set('hyperparameters', hyperparameters);
  229 +
161 230 loadMask.show(false);
162 231 var me = this;
163 232 AmdaAction.runMLModel(this.runModelObj.getJsonValues(), function (result, e) {
... ...