"src/git@developer.sourcefind.cn:OpenDAS/nni.git" did not exist on "6bc12de061a371145a25e16b51d61f837b9e2a12"
Commit 330e1e18 authored by Lijiao's avatar Lijiao Committed by liuzhe-lz
Browse files

Support netst search space (#1535)

parent 7be3c5c2
...@@ -128,13 +128,22 @@ class Para extends React.Component<ParaProps, ParaState> { ...@@ -128,13 +128,22 @@ class Para extends React.Component<ParaProps, ParaState> {
hyperParaPic = (source: Array<TableObj>, searchSpace: string) => { hyperParaPic = (source: Array<TableObj>, searchSpace: string) => {
// filter succeed trials [{}, {}, {}] // filter succeed trials [{}, {}, {}]
const dataSource: Array<TableObj> = source.filter(filterByStatus); const origin = source.filter(filterByStatus);
const dataSource: Array<TableObj> = JSON.parse(JSON.stringify(origin));
const lenOfDataSource: number = dataSource.length; const lenOfDataSource: number = dataSource.length;
const accPara: Array<number> = []; const accPara: Array<number> = [];
// specific value array // specific value array
const eachTrialParams: Array<string> = []; const eachTrialParams: Array<string> = [];
// experiment interface search space obj // experiment interface search space obj
const searchRange = searchSpace !== undefined ? JSON.parse(searchSpace) : ''; const searchRange = searchSpace !== undefined ? JSON.parse(searchSpace) : '';
// nest search space
let isNested: boolean = false;
Object.keys(searchRange).map(item => {
if (typeof searchRange[item]._value[0] === 'object') {
isNested = true;
return;
}
});
const dimName = Object.keys(searchRange); const dimName = Object.keys(searchRange);
if (this._isMounted === true) { if (this._isMounted === true) {
this.setState(() => ({ dimName: dimName })); this.setState(() => ({ dimName: dimName }));
...@@ -143,79 +152,131 @@ class Para extends React.Component<ParaProps, ParaState> { ...@@ -143,79 +152,131 @@ class Para extends React.Component<ParaProps, ParaState> {
const parallelAxis: Array<Dimobj> = []; const parallelAxis: Array<Dimobj> = [];
// search space range and specific value [only number] // search space range and specific value [only number]
let i = 0; let i = 0;
for (i; i < dimName.length; i++) { if (isNested === false) {
const searchKey = searchRange[dimName[i]]; for (i; i < dimName.length; i++) {
switch (searchKey._type) { const searchKey = searchRange[dimName[i]];
case 'uniform': switch (searchKey._type) {
case 'quniform': case 'uniform':
parallelAxis.push({ case 'quniform':
dim: i,
name: dimName[i],
max: searchKey._value[1],
min: searchKey._value[0]
});
break;
case 'randint':
parallelAxis.push({
dim: i,
name: dimName[i],
min: searchKey._value[0],
max: searchKey._value[1],
});
break;
case 'choice':
const data: Array<string> = [];
for (let j = 0; j < searchKey._value.length; j++) {
data.push(searchKey._value[j].toString());
}
parallelAxis.push({
dim: i,
name: dimName[i],
type: 'category',
data: data,
boundaryGap: true,
axisLine: {
lineStyle: {
type: 'dotted', // axis type,solid,dashed,dotted
width: 1
}
},
axisTick: {
show: true,
interval: 0,
alignWithLabel: true,
},
axisLabel: {
show: true,
interval: 0,
// rotate: 30
},
});
break;
// support log distribute
case 'loguniform':
if (lenOfDataSource > 1) {
parallelAxis.push({ parallelAxis.push({
dim: i, dim: i,
name: dimName[i], name: dimName[i],
type: 'log', max: searchKey._value[1],
min: searchKey._value[0]
}); });
} else { break;
case 'randint':
parallelAxis.push({
dim: i,
name: dimName[i],
min: searchKey._value[0],
max: searchKey._value[1],
});
break;
case 'choice':
const data: Array<string> = [];
for (let j = 0; j < searchKey._value.length; j++) {
data.push(searchKey._value[j].toString());
}
parallelAxis.push({
dim: i,
name: dimName[i],
type: 'category',
data: data,
boundaryGap: true,
axisLine: {
lineStyle: {
type: 'dotted', // axis type,solid,dashed,dotted
width: 1
}
},
axisTick: {
show: true,
interval: 0,
alignWithLabel: true,
},
axisLabel: {
show: true,
interval: 0,
// rotate: 30
},
});
break;
// support log distribute
case 'loguniform':
if (lenOfDataSource > 1) {
parallelAxis.push({
dim: i,
name: dimName[i],
type: 'log',
});
} else {
parallelAxis.push({
dim: i,
name: dimName[i]
});
}
break;
default:
parallelAxis.push({ parallelAxis.push({
dim: i, dim: i,
name: dimName[i] name: dimName[i]
}); });
} }
break; }
} else {
default: for (i; i < dimName.length; i++) {
parallelAxis.push({ const searchKey = searchRange[dimName[i]];
dim: i, switch (searchKey._type) {
name: dimName[i] case 'choice':
}); const data: Array<string> = [];
let j = 0;
for (j; j < searchKey._value.length; j++) {
const item = searchKey._value[j];
Object.keys(item).map(key => {
if (key !== '_name' && key !== '_type') {
Object.keys(item[key]).map(index => {
if (index !== '_type') {
const realChoice = item[key][index];
Object.keys(realChoice).map(m => {
data.push(`${item._name}_${realChoice[m]}`);
});
}
});
}
});
}
data.push('null');
parallelAxis.push({
dim: i,
name: dimName[i],
type: 'category',
data: data,
boundaryGap: true,
axisLine: {
lineStyle: {
type: 'dotted', // axis type,solid dashed dotted
width: 1
}
},
axisTick: {
show: true,
interval: 0,
alignWithLabel: true,
},
axisLabel: {
show: true,
interval: 0,
// rotate: 30
},
});
break;
default:
parallelAxis.push({
dim: i,
name: dimName[i]
});
}
} }
} }
parallelAxis.push({ parallelAxis.push({
...@@ -283,6 +344,23 @@ class Para extends React.Component<ParaProps, ParaState> { ...@@ -283,6 +344,23 @@ class Para extends React.Component<ParaProps, ParaState> {
} }
} }
}); });
// nested search space, deal data
if (isNested !== false) {
eachTrialParams.forEach(element => {
Object.keys(element).forEach(key => {
let item = element[key];
if (typeof item === 'object') {
Object.keys(item).forEach(index => {
if (index !== '_name') {
element[key] = `${item._name}_${item[index]}`;
} else {
element[key] = 'null';
}
});
}
});
});
}
if (this._isMounted) { if (this._isMounted) {
// if not return final result // if not return final result
const maxVal = accPara.length === 0 ? 1 : Math.max(...accPara); const maxVal = accPara.length === 0 ? 1 : Math.max(...accPara);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment