Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added lossGraph to features.json #506

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions features.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"title": "Learning tool",
"knnModel": true
}
"knnModel": true,
"lossGraph": true
}
5 changes: 3 additions & 2 deletions src/__viteBuildVariants__/ml-machine-simple/features.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"title": "ML-Machine",
"knnModel": false
}
"knnModel": false,
"lossGraph": false
}
5 changes: 3 additions & 2 deletions src/__viteBuildVariants__/ml-machine/features.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"title": "ML-Machine",
"knnModel": true
}
"knnModel": true,
"lossGraph": true
}
5 changes: 3 additions & 2 deletions src/__viteBuildVariants__/unbranded/features.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"title": "Learning tool",
"knnModel": true
}
"knnModel": true,
"lossGraph": true
}
2 changes: 1 addition & 1 deletion src/components/graphs/LossGraph.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import { onMount } from 'svelte';
import { Readable } from 'svelte/store';
import { LossTrainingIteration } from './LossGraphUtil';
import { LossTrainingIteration } from '../../script/mlmodels/LayersModelTrainer';

export let loss: Readable<LossTrainingIteration[]>;
export let maxX: number | undefined = undefined;
Expand Down
13 changes: 0 additions & 13 deletions src/components/graphs/LossGraphUtil.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/pages/training/NeuralNetworkTrainingPageView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import StandardButton from '../../components/buttons/StandardButton.svelte';
import ModelRegistry from '../../script/domain/ModelRegistry';
import Logger from '../../script/utils/Logger';
import { Feature, hasFeature } from '../../script/FeatureToggles';

const classifier = stores.getClassifier();
const model = classifier.getModel();
Expand All @@ -37,7 +38,7 @@
<StandardButton onClick={trainModelClickHandler}
>{$t(trainButtonSimpleLabel)}</StandardButton>
{/if}
{#if $loss.length > 0}
{#if $loss.length > 0 && hasFeature(Feature.LOSS_GRAPH)}
<LossGraph {loss} maxX={StaticConfiguration.layersModelTrainingSettings.noOfEpochs} />
{/if}
</div>
2 changes: 1 addition & 1 deletion src/pages/training/TrainModelButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
import StandardButton from '../../components/buttons/StandardButton.svelte';
import { Writable } from 'svelte/store';

import { LossTrainingIteration } from '../../components/graphs/LossGraphUtil';
import { highlightedAxis } from '../../script/stores/uiStore';
import { stores } from '../../script/stores/Stores';
import { options, trainModel } from './TrainModelButton';
import Axes from '../../script/domain/Axes';
import ModelRegistry, { ModelInfo } from '../../script/domain/ModelRegistry';
import { LossTrainingIteration } from '../../script/mlmodels/LayersModelTrainer';

export let onTrainingIteration: (iteration: LossTrainingIteration) => void;
export let onClick: () => void;
Expand Down
3 changes: 1 addition & 2 deletions src/pages/training/TrainModelButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import { stores } from '../../script/stores/Stores';
import StaticConfiguration from '../../StaticConfiguration';
import KNNNonNormalizedModelTrainer from '../../script/mlmodels/KNNNonNormalizedModelTrainer';
import { extractAxisFromTrainingData } from '../../script/utils/graphUtils';
import LayersModelTrainer from '../../script/mlmodels/LayersModelTrainer';
import { LossTrainingIteration } from '../../components/graphs/LossGraphUtil';
import LayersModelTrainer, { LossTrainingIteration } from '../../script/mlmodels/LayersModelTrainer';
import { FilterType } from '../../script/domain/FilterTypes';
import Filters from '../../script/domain/Filters';
import ModelRegistry, { ModelInfo } from '../../script/domain/ModelRegistry';
Expand Down
3 changes: 1 addition & 2 deletions src/pages/training/TrainingPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* SPDX-License-Identifier: MIT
*/
import { get, writable } from 'svelte/store';
import { LossTrainingIteration } from '../../components/graphs/LossGraphUtil';
import { highlightedAxis, selectedModel } from '../../script/stores/uiStore';
import Axes from '../../script/domain/Axes';
import KNNNonNormalizedModelTrainer from '../../script/mlmodels/KNNNonNormalizedModelTrainer';
Expand All @@ -14,7 +13,7 @@ import { stores } from '../../script/stores/Stores';
import CookieManager from '../../script/CookieManager';
import { appInsights } from '../../appInsights';
import ModelRegistry, { ModelInfo } from '../../script/domain/ModelRegistry';
import LayersModelTrainer from '../../script/mlmodels/LayersModelTrainer';
import LayersModelTrainer, { LossTrainingIteration } from '../../script/mlmodels/LayersModelTrainer';

export const loss = writable<LossTrainingIteration[]>([]);

Expand Down
1 change: 1 addition & 0 deletions src/script/FeatureToggles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Logger from './utils/Logger';
export enum Feature {
KNN_MODEL = 'knnModel',
TITLE = 'title',
LOSS_GRAPH = 'lossGraph',
}

export const hasFeature = (feature: Feature): boolean => {
Expand Down
8 changes: 6 additions & 2 deletions src/script/mlmodels/LayersModelTrainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*
* SPDX-License-Identifier: MIT
*/
import { LossTrainingIteration } from '../../components/graphs/LossGraphUtil';
import ModelTrainer, { TrainingData } from '../domain/ModelTrainer';
import LayersMLModel from './LayersMLModel';
import * as tf from '@tensorflow/tfjs';
Expand All @@ -15,11 +14,16 @@ export type LayersModelTrainingSettings = {
batchSize: number;
};

export type LossTrainingIteration = {
loss: number;
epoch: number;
};

class LayersModelTrainer implements ModelTrainer<LayersMLModel> {
constructor(
private settings: LayersModelTrainingSettings,
private onFitIteration: (h: LossTrainingIteration) => void,
) {}
) { }
public async trainModel(trainingData: TrainingData): Promise<LayersMLModel> {
// Fetch data
const features: Array<number[]> = [];
Expand Down
5 changes: 5 additions & 0 deletions src/script/utils/graphUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,8 @@ export const distanceBetween = (point1: Point3D, point2: Point3D): number => {

return Math.sqrt(squaredDistance);
};

export type LossTrainingIteration = {
loss: number;
epoch: number;
};
Loading