From 1bbc4ed9e3783b2363c71048c415b84803c26b6b Mon Sep 17 00:00:00 2001 From: TAMARA JERINIC Date: Tue, 10 May 2022 21:19:31 +0200 Subject: Filtriran izbor funkcija gubitka. --- frontend/src/app/_data/Model.ts | 21 +- frontend/src/app/_data/Predictor.ts | 2 +- .../_charts/line-chart/line-chart.component.ts | 2 +- .../_elements/form-model/form-model.component.html | 4 +- .../_elements/form-model/form-model.component.ts | 15 ++ .../src/app/experiment/experiment.component.html | 255 --------------------- .../src/app/experiment/experiment.component.ts | 222 ------------------ frontend/src/app/training/training.component.html | 46 ---- 8 files changed, 24 insertions(+), 543 deletions(-) delete mode 100644 frontend/src/app/experiment/experiment.component.html delete mode 100644 frontend/src/app/experiment/experiment.component.ts delete mode 100644 frontend/src/app/training/training.component.html diff --git a/frontend/src/app/_data/Model.ts b/frontend/src/app/_data/Model.ts index 526a8290..d1e89e84 100644 --- a/frontend/src/app/_data/Model.ts +++ b/frontend/src/app/_data/Model.ts @@ -13,7 +13,7 @@ export default class Model extends FolderFile { // Neural net training settings public type: ProblemType = ProblemType.Regression, public optimizer: Optimizer = Optimizer.Adam, - public lossFunction: LossFunction = LossFunction.MeanSquaredError, + public lossFunction: LossFunction = LossFunctionRegression[0], public inputNeurons: number = 1, public hiddenLayers: number = 1, public batchSize: BatchSize = BatchSize.O3, @@ -132,21 +132,10 @@ export enum LossFunction { MeanSquaredLogarithmicError = 'mean_squared_logarithmic_error', HuberLoss = 'Huber' } -export enum LossFunctionRegression { - MeanAbsoluteError = 'mean_absolute_error', - MeanSquaredError = 'mean_squared_error', - MeanSquaredLogarithmicError = 'mean_squared_logarithmic_error', -} -export enum LossFunctionBinaryClassification { - BinaryCrossEntropy = 'binary_crossentropy', - SquaredHingeLoss = 'squared_hinge_loss', - HingeLoss = 'hinge_loss', -} -export enum LossFunctionMultiClassification { - CategoricalCrossEntropy = 'categorical_crossentropy', - SparseCategoricalCrossEntropy = 'sparse_categorical_crossentropy', - KLDivergence = 'kullback_leibler_divergence', -} +export const LossFunctionRegression =[LossFunction.MeanAbsoluteError,LossFunction.MeanSquaredError,LossFunction.MeanSquaredLogarithmicError] +export const LossFunctionBinaryClassification=[LossFunction.BinaryCrossEntropy,LossFunction.SquaredHingeLoss,LossFunction.HingeLoss] + +export const LossFunctionMultiClassification=[LossFunction.CategoricalCrossEntropy,LossFunction.SparseCategoricalCrossEntropy,LossFunction.KLDivergence] export enum Optimizer { Adam = 'Adam', diff --git a/frontend/src/app/_data/Predictor.ts b/frontend/src/app/_data/Predictor.ts index c5cb2218..e15ae8f9 100644 --- a/frontend/src/app/_data/Predictor.ts +++ b/frontend/src/app/_data/Predictor.ts @@ -9,7 +9,7 @@ export default class Predictor { public accessibleByLink: boolean = false, public dateCreated: Date = new Date(), public uploaderId: string = '', - public finalMetrics: Metric[] = [] + //public finalMetrics: Metric[] = [] ) { } } diff --git a/frontend/src/app/_elements/_charts/line-chart/line-chart.component.ts b/frontend/src/app/_elements/_charts/line-chart/line-chart.component.ts index 9ead9232..0924801e 100644 --- a/frontend/src/app/_elements/_charts/line-chart/line-chart.component.ts +++ b/frontend/src/app/_elements/_charts/line-chart/line-chart.component.ts @@ -87,7 +87,7 @@ export class LineChartComponent implements AfterViewInit { // This more specific font property overrides the global property color:'white', font: { - size: 11 + size: 10 } } } diff --git a/frontend/src/app/_elements/form-model/form-model.component.html b/frontend/src/app/_elements/form-model/form-model.component.html index 8ec29a09..361e2545 100644 --- a/frontend/src/app/_elements/form-model/form-model.component.html +++ b/frontend/src/app/_elements/form-model/form-model.component.html @@ -11,7 +11,7 @@
Tip problema - + {{ optionName }} @@ -36,7 +36,7 @@ Funkcija troška - + {{ optionName }} diff --git a/frontend/src/app/_elements/form-model/form-model.component.ts b/frontend/src/app/_elements/form-model/form-model.component.ts index 71b374b0..82fa0e95 100644 --- a/frontend/src/app/_elements/form-model/form-model.component.ts +++ b/frontend/src/app/_elements/form-model/form-model.component.ts @@ -135,4 +135,19 @@ export class FormModelComponent implements AfterViewInit { updateTestSet(event: MatSliderChange) { this.testSetDistribution = event.value!; } + + filterLossFunction() { + if(this.newModel.type==ProblemType.Regression){ + this.lossFunction = LossFunctionRegression; + this.newModel.lossFunction=LossFunction.MeanSquaredError; + } + else if(this.newModel.type==ProblemType.BinaryClassification){ + this.lossFunction= LossFunctionBinaryClassification; + this.newModel.lossFunction=LossFunction.BinaryCrossEntropy; + } + else if(this.newModel.type==ProblemType.MultiClassification){ + this.lossFunction = LossFunctionMultiClassification; + this.newModel.lossFunction=LossFunction.SparseCategoricalCrossEntropy; + } + } } diff --git a/frontend/src/app/experiment/experiment.component.html b/frontend/src/app/experiment/experiment.component.html deleted file mode 100644 index 62236cce..00000000 --- a/frontend/src/app/experiment/experiment.component.html +++ /dev/null @@ -1,255 +0,0 @@ - -
-
- -
- Izvor podataka - arrow_forward - Preprocesiranje - arrow_forward - Dodaj eksperiment -
- - -
-
\ No newline at end of file diff --git a/frontend/src/app/experiment/experiment.component.ts b/frontend/src/app/experiment/experiment.component.ts deleted file mode 100644 index 2d0f6ec5..00000000 --- a/frontend/src/app/experiment/experiment.component.ts +++ /dev/null @@ -1,222 +0,0 @@ -import { Component, OnInit } from '@angular/core'; -import Experiment, { NullValReplacer, NullValueOptions, ReplaceWith, Encoding } from '../_data/Experiment'; -import Model,{ProblemType} from '../_data/Model'; -import Dataset, { ColumnInfo } from '../_data/Dataset'; -import { ModelsService } from '../_services/models.service'; -import Shared from '../Shared'; -import { ExperimentsService } from '../_services/experiments.service'; -import { ColumnEncoding } from '../_data/Experiment'; - -@Component({ - selector: 'app-experiment', - templateUrl: './experiment.component.html', - styleUrls: ['./experiment.component.css'] -}) -export class ExperimentComponent implements OnInit { - - experiment: Experiment = new Experiment(); - selectedModel?: Model; - selectedDataset?: Dataset; - trainingResult: any; // any za sad, promeni kasnije - - NullValueOptions = NullValueOptions; - ReplaceWith = ReplaceWith; - Encoding = Encoding; - ColumnEncoding = ColumnEncoding; - Object = Object; - ProblemType=ProblemType; - selectedColumnsInfoArray: ColumnInfo[] = []; - selectedNotNullColumnsArray: string[] = []; - - tempTestSetDistribution = 90; - - constructor(private modelsService: ModelsService, private experimentsService: ExperimentsService) { - } - - ngOnInit(): void { - } - - updateDataset(dataset: Dataset) { - this.selectedDataset = dataset; - this.selectedColumnsInfoArray = this.selectedDataset.columnInfo; - this.selectedNotNullColumnsArray = []; - this.experiment.outputColumn = this.selectedDataset.columnInfo[this.selectedDataset.columnInfo.length - 1].columnName; - - this.resetColumnEncodings(); - console.log(this.experiment.encodings); - } - - resetColumnEncodings() { - this.experiment.encodings = []; - for (let i = 0; i < this.selectedColumnsInfoArray.length; i++) { - this.experiment.encodings.push(new ColumnEncoding(this.selectedColumnsInfoArray[i].columnName, Encoding.Label)); - } - } - - getInputById(id: string): HTMLInputElement { - return document.getElementById(id) as HTMLInputElement; - } - - arrayColumn = (arr: any[][], n: number) => [...this.dropEmptyString(new Set(arr.map(x => x[n])))]; - - dropEmptyString(set: Set): Set { - if (set.has("")) - set.delete(""); - if (set.has(null)) - set.delete(null); - if (set.has(undefined)) - set.delete(undefined); - return set; - } - - emptyFillTextInput(colName: string) { - (document.getElementById("fillText_" + colName)).value = ""; - } - - checkFillColRadio(colName: string) { - (document.getElementById("fillCol_" + colName)).checked = true; - } - - checkedColumnsChanged(checkedColumnInfo: ColumnInfo, buttonType: number) { //0-input,1-output - let col = this.selectedColumnsInfoArray.find(x => x.columnName == checkedColumnInfo.columnName); - if (buttonType == 0) { //inputCol - if (col == undefined) - this.selectedColumnsInfoArray.push(checkedColumnInfo); - else - this.selectedColumnsInfoArray = this.selectedColumnsInfoArray.filter(x => x.columnName != checkedColumnInfo.columnName); - } - else { //outputCol - if (col == undefined) //ako je vec cekiran neki output, samo dodaj sad ovaj, a taj output postaje input i ostaje u nizu - this.selectedColumnsInfoArray.push(checkedColumnInfo); - } - //console.log(this.selectedColumnsInfoArray); - } - - replace(event: Event, column: ColumnInfo) { - let option = (event.target).value; - - const input = (document.getElementById("fillText_" + column.columnName)); - if (column.isNumber) { - switch (option) { - case ReplaceWith.Max: - input.value = "" + column.max; - break; - case ReplaceWith.Min: - input.value = "" + column.min; - break; - case ReplaceWith.Mean: - input.value = "" + column.mean; - break; - case ReplaceWith.Median: - input.value = "" + column.median; - break; - case ReplaceWith.None: - break; - } - } else { - input.value = option; - } - } - - getSelectedColumnsArrayWithoutNullVals(): string[] { - let colNames: string[] = []; - - for (let i = 0; i < this.selectedColumnsInfoArray.length; i++) { - let oneColInfo = this.selectedColumnsInfoArray[i]; - if (oneColInfo.numNulls == 0) - colNames.push(oneColInfo.columnName); - } - return colNames; - } - - getNullValuesReplacersArray(): NullValReplacer[] { - let array: NullValReplacer[] = []; - - if (this.experiment.nullValues == NullValueOptions.Replace) { - - for (let i = 0; i < this.selectedColumnsInfoArray.length; i++) { - let oneColInfo = this.selectedColumnsInfoArray[i]; - - if (oneColInfo.numNulls > 0) { //ako kolona nema null vrednosti, ne dodajemo je u niz - if ((document.getElementById("delCol_" + oneColInfo.columnName)).checked) { - array.push({ - column: oneColInfo.columnName, - option: NullValueOptions.DeleteColumns, - value: "" - }); - } - else if ((document.getElementById("delRows_" + oneColInfo.columnName)).checked) { - array.push({ - column: oneColInfo.columnName, - option: NullValueOptions.DeleteRows, - value: "" - }); - } - else if (((document.getElementById("fillCol_" + oneColInfo.columnName)).checked)) { - array.push({ - column: oneColInfo.columnName, - option: NullValueOptions.Replace, - value: (document.getElementById("fillText_" + oneColInfo.columnName)).value - }); - } - } - } - } - return array; - } - - saveExperiment() { - if (this.selectedDataset == undefined) { - Shared.openDialog("Greška", "Izvor podataka nije izabran!"); - return; - } - if (this.experiment.outputColumn == '') { - Shared.openDialog("Greška", "Molimo Vas da izaberete izlaznu kolonu."); - return; - } - if (this.selectedColumnsInfoArray.length <= 1) { //jer izlazna je izabrana - Shared.openDialog("Greška", "Molimo Vas da izaberete ulazne kolone."); - return; - } - - this.experiment._id = ''; - this.experiment.uploaderId = ''; - this.experiment.datasetId = this.selectedDataset._id; - - let pom = this.selectedColumnsInfoArray.filter(x => x.columnName != this.experiment.outputColumn); - for (let i = 0; i < pom.length; i++) - this.experiment.inputColumns.push(pom[i].columnName); - - this.selectedColumnsInfoArray = this.selectedColumnsInfoArray.filter(x => x.numNulls > 0); //obavezno - this.experiment.nullValuesReplacers = this.getNullValuesReplacersArray(); - - this.experiment.randomTestSetDistribution = 1 - Math.round(this.tempTestSetDistribution / 100 * 10) / 10; - - console.log("Eksperiment:", this.experiment); - - this.experimentsService.addExperiment(this.experiment).subscribe((response) => { - this.experiment = response; - - this.selectedColumnsInfoArray = []; - this.selectedNotNullColumnsArray = []; - this.experiment.encodings = []; - - Shared.openDialog("Obaveštenje", "Eksperiment je uspešno kreiran."); - }, (error) => { - if (error.error == "Experiment with this name exists") { - Shared.openDialog("Greška", "Eksperiment sa unetim nazivom već postoji u Vašoj kolekciji. Unesite neki drugi naziv."); - } - }); - } - - countSelectedNullCols(): number { - let counter: number = 0; - - for (let i = 0; i < this.selectedColumnsInfoArray.length; i++) { - let oneColInfo = this.selectedColumnsInfoArray[i]; - if (oneColInfo.numNulls > 0) - ++counter; - } - return counter; - } -} diff --git a/frontend/src/app/training/training.component.html b/frontend/src/app/training/training.component.html deleted file mode 100644 index 672e75fb..00000000 --- a/frontend/src/app/training/training.component.html +++ /dev/null @@ -1,46 +0,0 @@ - -
-
-
- -
- -

1. Izaberite eksperiment iz kolekcije

-
- -
-
-
    -
  • - -
  • -
-
- -

2. Izaberite model

- - -

3. Treniranje modela

- -
- -
- -

Rezultati treniranja

-
-

Rezultati treniranja:

-

- {{trainingResult}} -

-
-
- -
-
-
\ No newline at end of file -- cgit v1.2.3