Overview.tsx 7.54 KB
Newer Older
Lijiao's avatar
Lijiao committed
1
import * as React from 'react';
2
import { Row, Col } from 'antd';
3
4
import { EXPERIMENT, TRIALS } from '../static/datamodel';
import { Trial } from '../static/model/trial';
Lijiao's avatar
Lijiao committed
5
6
7
8
9
10
import SuccessTable from './overview/SuccessTable';
import Title1 from './overview/Title1';
import Progressed from './overview/Progress';
import Accuracy from './overview/Accuracy';
import SearchSpace from './overview/SearchSpace';
import BasicInfo from './overview/BasicInfo';
11
import TrialInfo from './overview/TrialProfile';
Lijiao's avatar
Lijiao committed
12
13
14
15
16
17
18

require('../static/style/overview.scss');
require('../static/style/logPath.scss');
require('../static/style/accuracy.css');
require('../static/style/table.scss');
require('../static/style/overviewTitle.scss');

19
20
21
interface OverviewProps {
    experimentUpdateBroadcast: number;
    trialsUpdateBroadcast: number;
Lijiao's avatar
Lijiao committed
22
23
}

24
25
26
interface OverviewState {
    trialConcurrency: number;
    metricGraphMode: 'max' | 'min';
27
28
29
30
}

class Overview extends React.Component<OverviewProps, OverviewState> {
    constructor(props: OverviewProps) {
Lijiao's avatar
Lijiao committed
31
32
        super(props);
        this.state = {
33
34
            trialConcurrency: EXPERIMENT.trialConcurrency,
            metricGraphMode: (EXPERIMENT.optimizeMode === 'minimize' ? 'min' : 'max'),
Lijiao's avatar
Lijiao committed
35
36
37
        };
    }

38
39
40
    clickMaxTop = (event: React.SyntheticEvent<EventTarget>) => {
        event.stopPropagation();
        // #999 panel active bgcolor; #b3b3b3 as usual
41
        this.setState({ metricGraphMode: 'max' });
42
43
44
45
    }

    clickMinTop = (event: React.SyntheticEvent<EventTarget>) => {
        event.stopPropagation();
46
        this.setState({ metricGraphMode: 'min' });
47
48
    }

49
50
    changeConcurrency = (val: number) => {
        this.setState({ trialConcurrency: val });
51
52
    }

53
54
55
    render() {
        const { trialConcurrency, metricGraphMode } = this.state;
        const { experimentUpdateBroadcast } = this.props;
Lijiao's avatar
Lijiao committed
56

57
        const searchSpace = this.convertSearchSpace();
Lijiao's avatar
Lijiao committed
58

59
60
61
62
        const bestTrials = this.findBestTrials();
        const bestAccuracy = bestTrials.length > 0 ? bestTrials[0].accuracy! : NaN;
        const accuracyGraphData = this.generateAccuracyGraph(bestTrials);
        const noDataMessage = bestTrials.length > 0 ? '' : 'No data';
Lijiao's avatar
Lijiao committed
63

64
65
        const titleMaxbgcolor = (metricGraphMode === 'max' ? '#999' : '#b3b3b3');
        const titleMinbgcolor = (metricGraphMode === 'min' ? '#999' : '#b3b3b3');
Lijiao's avatar
Lijiao committed
66
67
68
69

        return (
            <div className="overview">
                {/* status and experiment block */}
Lijiao's avatar
Lijiao committed
70
                <Row>
71
                    <Title1 text="Experiment" icon="11.png" />
72
                    <BasicInfo experimentUpdateBroadcast={experimentUpdateBroadcast} />
Lijiao's avatar
Lijiao committed
73
74
75
                </Row>
                <Row className="overMessage">
                    {/* status graph */}
76
                    <Col span={9} className="prograph overviewBoder cc">
Lijiao's avatar
Lijiao committed
77
78
79
                        <Title1 text="Status" icon="5.png" />
                        <Progressed
                            bestAccuracy={bestAccuracy}
80
81
82
                            concurrency={trialConcurrency}
                            changeConcurrency={this.changeConcurrency}
                            experimentUpdateBroadcast={experimentUpdateBroadcast}
Lijiao's avatar
Lijiao committed
83
84
85
                        />
                    </Col>
                    {/* experiment parameters search space tuner assessor... */}
86
                    <Col span={7} className="overviewBoder cc">
Lijiao's avatar
Lijiao committed
87
                        <Title1 text="Search space" icon="10.png" />
Lijiao's avatar
Lijiao committed
88
89
90
91
                        <Row className="experiment">
                            <SearchSpace searchSpace={searchSpace} />
                        </Row>
                    </Col>
92
                    <Col span={8} className="overviewBoder cc">
93
                        <Title1 text="Profile" icon="4.png" />
Lijiao's avatar
Lijiao committed
94
95
96
                        <Row className="experiment">
                            {/* the scroll bar all the trial profile in the searchSpace div*/}
                            <div className="experiment searchSpace">
97
98
99
100
                                <TrialInfo
                                    experimentUpdateBroadcast={experimentUpdateBroadcast}
                                    concurrency={trialConcurrency}
                                />
Lijiao's avatar
Lijiao committed
101
102
103
104
105
                            </div>
                        </Row>
                    </Col>
                </Row>
                <Row className="overGraph">
106
107
                    <Row className="top10bg">
                        <Col span={4} className="top10Title">
Lijiao's avatar
Lijiao committed
108
                            <Title1 text="Top10  trials" icon="7.png" />
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
                        </Col>
                        <Col
                            span={2}
                            className="title"
                            onClick={this.clickMaxTop}
                        >
                            <Title1 text="Maximal" icon="max.png" bgcolor={titleMaxbgcolor} />
                        </Col>
                        <Col
                            span={2}
                            className="title minTitle"
                            onClick={this.clickMinTop}
                        >
                            <Title1 text="Minimal" icon="min.png" bgcolor={titleMinbgcolor} />
                        </Col>
                    </Row>
Lijiao's avatar
Lijiao committed
125
126
127
128
                    <Row>
                        <Col span={8} className="overviewBoder">
                            <Row className="accuracy">
                                <Accuracy
129
130
                                    accuracyData={accuracyGraphData}
                                    accNodata={noDataMessage}
Lijiao's avatar
Lijiao committed
131
132
133
134
135
                                    height={324}
                                />
                            </Row>
                        </Col>
                        <Col span={16} id="succeTable">
136
                            <SuccessTable trialIds={bestTrials.map(trial => trial.info.id)}/>
Lijiao's avatar
Lijiao committed
137
138
                        </Col>
                    </Row>
Lijiao's avatar
Lijiao committed
139
140
141
142
                </Row>
            </div>
        );
    }
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201

    private convertSearchSpace(): object {
        const searchSpace = Object.assign({}, EXPERIMENT.searchSpace);
        Object.keys(searchSpace).map(item => {
            const key = searchSpace[item]._type;
            let value = searchSpace[item]._value;
            switch (key) {
                case 'quniform':
                case 'qnormal':
                case 'qlognormal':
                    searchSpace[item]._value = [value[0], value[1]];
                    break;
                default:
            }
        });
        return searchSpace;
    }

    private findBestTrials(): Trial[] {
        let bestTrials = TRIALS.sort();
        if (this.state.metricGraphMode === 'max') {
            bestTrials.reverse().splice(10);
        } else {
            bestTrials.splice(10);
        }
        return bestTrials;
    }

    private generateAccuracyGraph(bestTrials: Trial[]): object {
        const xSequence = bestTrials.map(trial => trial.sequenceId);
        const ySequence = bestTrials.map(trial => trial.accuracy);

        return {
            // support max show 0.0000000
            grid: {
                left: 67,
                right: 40
            },
            tooltip: {
                trigger: 'item'
            },
            xAxis: {
                name: 'Trial',
                type: 'category',
                data: xSequence
            },
            yAxis: {
                name: 'Default metric',
                type: 'value',
                scale: true,
                data: ySequence
            },
            series: [{
                symbolSize: 6,
                type: 'scatter',
                data: ySequence
            }]
        };
    }
Lijiao's avatar
Lijiao committed
202
}
203

Lijiao's avatar
Lijiao committed
204
export default Overview;