labeling-window.component.ts 2.99 KB
Newer Older
1
import { Component, OnInit } from '@angular/core';
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
2
import {StateService} from '../state.service';
3
4
5
6
7
8
9

@Component({
  selector: 'app-labeling-window',
  templateUrl: './labeling-window.component.html',
  styleUrls: ['./labeling-window.component.css']
})
export class LabelingWindowComponent implements OnInit {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
10
  public topk: number[];
11
12
  public subplots = [];
  public labels: boolean[] = [];
13
  private k = 12;
14

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
15
  constructor(private state: StateService) { }
16
17

  ngOnInit(): void {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
18
    this.state.onNewTable.subscribe(() => this.showSamples());
19
20
  }

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
21
22
23
24
  async train() {
    this.state.labels = Object.assign({}, this.state.labels, this.labels);
    await this.state.getQueryWindow(this.state.labels);
    await this.state.update();
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
25
26
  }

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
27
28
29
  async updateQuery() {
    this.state.labels = Object.assign({}, this.state.labels, this.labels);
    await this.state.getQueryWindow(this.state.labels);
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  }

  public labelCorrect(index: number) {
    this.labels[index] = true;
  }

  public labelUndefined(index: number) {
    if (this.labels[index] !== undefined) {
      delete this.labels[index];
    }
  }

  public labelIncorrect(index: number) {
    this.labels[index] = false;
  }

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
46
  async showSamples() {
47
48
49
    this.topk = this.state.lshData.candidates
      .filter((candidate) => this.state.labels[candidate] !== true)
      .slice(0, this.k);
50
    this.subplots = [];
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
    const values: number[][][] = await this.state.getWindow(this.topk);
    for (const idx in this.topk) {
      const window = values[idx].slice(0, 1);
      const data = [];
      window.forEach((channel: number[], index: number) => {
        data.push({
          x: [...Array(channel.length).keys()],
          y: channel,
          type: 'line',
          xaxis: 'x',
          yaxis: `y${index + 2}`,
        });
      });
      const subplots = [];
      window.forEach((channel: number[], index: number) => {
        subplots.push([`xy${index + 2}`]);
      });
      const plot = {
        index: this.topk[idx],
        data: data,
        layout: {
          grid: {
            rows: 1, //this.state.queryWindow.length,
            columns: 1,
            subplots: subplots,
          },
          showlegend: false,
          title: `Index: ${this.topk[idx].toString()}`,
          hovermode: 'closest',
          autosize: true,
          margin: {
            l: 30,
            r: 30,
            t: 30,
            b: 0,
            pad: 4
          },
          height: 100,
          width: 300,
          titlefont: {
            size: 9
          },
          xaxis: {
            showgrid: false,
            zeroline: false,
            showticklabels: false,
          },
          yaxis: {
            zeroline: false,
            showticklabels: false,
101
102
          }
        }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
103
104
105
106
107
108
109
110
111
      };
      window.forEach((channel: number[], index: number) => {
        plot.layout[`yaxis${index + 2}`] = {
          zeroline: false,
          showticklabels: false,
        };
      });
      this.subplots.push(plot);
    }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
112
113
  }

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
114
115
  public get show() {
    return !!this.state.lshData;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
116
  }
117
}