Commit b09bb719 authored by Yuncong Yu's avatar Yuncong Yu
Browse files

Add comments, rename some functions.

parent 778969bb
......@@ -25,14 +25,14 @@ This will create a conda environment named *pseudo*. Now activate the environmen
### Step 2: Prepare backend - creating the LSH package
The LSH algorithm is maintained locally for now, so you'll have to create it manually. The file that you need to setup this package is located in the Flaskserver folder (this is more efficient when debugging, as for every change you have to rebuild the package). So the package can be created by running the following code:
`cd Flaskserver\libs`
`cd backend\libs`
`python3 setup.py build_ext --inplace && python3 setup.py install`
`cd ..`
**NOTE 1**: So as a reminder, don't forget to run the 2nd line everytime you change something in the c++ code.
### Step 3: Prepare frontend - install Node packages
The cloned Angular repository cannot be used directly. You have to install the node packages via
`cd AngularApp/prototypes`
`cd frontend`
`npm install`
### Step 4: Running PSEUDo
......
......@@ -136,9 +136,9 @@ def initialize():
distances: 3d array [k][l][i],
average_candidates: 1d array [i],
average_distances: 1d array [i],
tables: [{
tables: {
bucket: 1d array
}],
}[],
average_table: {
bucket: 1d array
},
......
import { Injectable } from '@angular/core';
export interface RawData {
// This interface is called RawDate by Dylan
export interface Channel {
index: string[];
values: number[];
name?: string;
}
export interface LshData {
candidates: number[][][];
distances: number[][][];
average_candidates: number[];
average_distances: number[];
export interface LshData { // LSH results
candidates: number[][][]; // [l][k][t]
distances: number[][][]; // [l][k][t]
average_candidates: number[]; // [t]
average_distances: number[]; // [t]
tables: {[bucket: string]: number[]}[];
average_table: {[bucket: string]: number[]};
samples: number[];
hash_functions: number[][];
hash_functions: number[][]; // [?][d]
prototype: {
average: number[][];
min: number[][];
max: number[][];
average: number[][]; // [d][t]
min: number[][]; // [d][t]
max: number[][]; // [d][t]
};
parameters?: number[];
}
......@@ -29,7 +30,7 @@ export interface TableInfoData {
min: number[][];
max: number[][];
}[];
distances: number[][];
distances: number[][]; // [x][x]
}
export interface Parameters {
......@@ -41,9 +42,9 @@ export interface Parameters {
export interface State {
lshData: LshData;
queryWindow: number[][];
weights: number[];
labels: any;
queryWindow: number[][]; // [d][t]
weights: number[]; // [d]
labels: any; // [?]
}
export interface StateNode {
......@@ -66,7 +67,7 @@ export class ApiService {
/**
* Read input data. The format is a list of channels, where each channel is an object of type RawData
*/
async readFile(): Promise<RawData[]> {
async loadData(): Promise<Channel[]> {
const response = await fetch('http://127.0.0.1:5000/load-data');
return await response.json();
}
......@@ -85,22 +86,6 @@ export class ApiService {
body: JSON.stringify(postData)
});
}
/**
* Get weights which will be applied to the LSH hash functions
*/
async getWeights(query: number[][], labels: {[index: number]: boolean}, weights: number[], hash_functions: number[][]): Promise<number[]> {
const response = await fetch('http://127.0.0.1:5000/weights', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: new Blob( [ JSON.stringify({query, labels, weights, hash_functions}) ], { type: 'text/plain' } )
});
return await response.json();
}
/**
* Do the first iteration of LSH and return important information
*/
......@@ -146,6 +131,22 @@ export class ApiService {
return await response.json();
}
/**
* Get weights which will be applied to the LSH hash functions
*/
async getWeights(query: number[][], labels: {[index: number]: boolean}, weights: number[], hash_functions: number[][]): Promise<number[]> {
const response = await fetch('http://127.0.0.1:5000/weights', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: new Blob( [ JSON.stringify({query, labels, weights, hash_functions}) ], { type: 'text/plain' } )
});
return await response.json();
}
/**
* Get query window based on windows labeled correct
*/
......
......@@ -83,14 +83,15 @@ mat-tab-group {
}
.channel_header {
height: 18px;
background-color: #14639e /*lightblue*/;
/*height: 20px;*/
background-color: #14639e /*IAV blue*/ /*lightblue*/;
border-bottom: 1px solid lightgray;
color: white;
text-align: center;
vertical-align: middle;
font-weight: bold;
padding: 2px;
/*padding: 2px;*/
padding: 10px;
}
app-overview-window {
......
......@@ -114,7 +114,7 @@ path {
text-align: center;
vertical-align: middle;
font-weight: bold;
padding: 2px;
padding: 10px;
}
.container {
......
import { EventEmitter, Injectable } from '@angular/core';
import { ApiService, LshData, Parameters, RawData, State, StateNode, TableInfoData } from './api.service';
import { ApiService, Channel, LshData, Parameters, State, StateNode, TableInfoData } from './api.service';
@Injectable({
providedIn: 'root'
......@@ -14,12 +15,12 @@ export class StateService {
*/
public currStateIndex = 0;
public maxStateIndex = 0;
public states: {[idx: number]: StateNode} = {};
private _rawData: RawData[];
public states: { [idx: number]: StateNode } = {};
private _rawData: Channel[];
private _lshData: LshData;
private _queryWindow: number[][];
private _weights: number[];
private _labels = {};
private _queryWindow: number[][]; // [d][t]
private _weights: number[]; // [d]
private _labels: {[idx: number]: boolean} = {};
private _lshParameters: number[];
private _selection: number[];
public computedTime = 0;
......@@ -75,7 +76,7 @@ export class StateService {
* This function retrieves the raw data
*/
async getRawData(): Promise<void> {
this.rawData = await this.api.readFile();
this.rawData = await this.api.loadData();
console.log('Printing raw data:');
console.log(this.rawData);
}
......@@ -89,7 +90,6 @@ export class StateService {
}
/**
* This function performs the first iteration of LSH
*/
......@@ -129,7 +129,7 @@ export class StateService {
/**
* This function retrieves the query
*/
async getQueryWindow(windowIndex: number | {[index: number]: boolean}, querySize, startIndex): Promise<number[][]> {
async getQueryWindow(windowIndex: number | { [index: number]: boolean }, querySize, startIndex): Promise<number[][]> {
this.loadingText = 'Generating windows';
this.queryWindow = await this.api.getQueryWindow(windowIndex, querySize, startIndex);
this.loadingText = '';
......@@ -174,12 +174,12 @@ export class StateService {
/**
* These are all setters and getters
*/
public set rawData(v: RawData[]) {
public set rawData(v: Channel[]) {
this._rawData = v;
this.onNewData.emit();
}
public get rawData(): RawData []{
public get rawData(): Channel [] {
return this._rawData;
}
......
......@@ -10,7 +10,7 @@
.subplot {
margin: 20px;
height: max-content;
border: 2px solid lightblue;
border: 2px solid #14639e /*lightblue*/;
border-radius: 25px;
padding: 20px;
}
......
......@@ -95,6 +95,7 @@ double dtw(float* A, float* B, double *cb, int m, int r, double best_so_far) {
}
/// Sorting function for the 2nd element of two vectors
// sort by second ascending
bool sortbysecasc(const pair<int,double> &a,
const pair<int,double> &b)
{
......@@ -102,6 +103,7 @@ bool sortbysecasc(const pair<int,double> &a,
}
/// Sorting function for the 2nd element of two vectors
// Sort by second descending
bool sortbysecdesc(const pair<int,double> &a,
const pair<int,double> &b)
{
......@@ -126,14 +128,14 @@ int lsh(float *** D, int M, int T, int Dim, float ** Q, int L, int K, double r,
srand(time(NULL));
int S = 2; //3
double delta = r * 0.75; //0.07 => 20.000
int threshold = T * 0.22; //0.8 => 18/67
double delta = r * 0.75; //0.07 => 20.000 maximum allowed false negative rate
int threshold = T * 0.22; //0.8 => 18/67 minimum number of project collisions for a hash collision
/// Create hash functions
float value;
for (int l=0;l<L;l++)
for (int l=0;l<L;l++) // compound hash functions H_G
{
for (int k=0;k<K;k++)
for (int k=0;k<K;k++) // hash functions H
{
for (int d=0;d<Dim;d++)
{
......
Supports Markdown
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