Switched To point for datasets
This commit is contained in:
@@ -50,7 +50,14 @@ class PerceptronController extends Controller
|
|||||||
$dataset = [];
|
$dataset = [];
|
||||||
$dataset['label'] = str_replace('.csv', '', $file);
|
$dataset['label'] = str_replace('.csv', '', $file);
|
||||||
$dataSetReader = new DataSetReader($dataSetsDirectory . '/' . $file);
|
$dataSetReader = new DataSetReader($dataSetsDirectory . '/' . $file);
|
||||||
$dataset['data'] = $dataSetReader->lines;
|
$dataset['data'] = [];
|
||||||
|
foreach ($dataSetReader->lines as $line) {
|
||||||
|
$dataset['data'][] = [
|
||||||
|
'x' => $line[0],
|
||||||
|
'y' => $line[1],
|
||||||
|
'label' => $line[2],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
switch ($dataset['label']) {
|
switch ($dataset['label']) {
|
||||||
case '2.9':
|
case '2.9':
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import type {
|
|||||||
BubbleDataPoint,
|
BubbleDataPoint,
|
||||||
Point,
|
Point,
|
||||||
} from 'chart.js';
|
} from 'chart.js';
|
||||||
import { Chart } from 'vue-chartjs';
|
|
||||||
import type { Iteration } from '@/types/perceptron';
|
|
||||||
import { colors } from '@/types/graphs';
|
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
|
import { Chart } from 'vue-chartjs';
|
||||||
|
import { colors } from '@/types/graphs';
|
||||||
|
import type { Iteration } from '@/types/perceptron';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
cleanedDataset: { label: number; data: { x: number; y: number }[] }[];
|
cleanedDataset: { label: number; data: { x: number; y: number }[] }[];
|
||||||
@@ -45,13 +45,13 @@ function getPerceptronDecisionBoundaryDataset(
|
|||||||
networkWeights.length == 1 &&
|
networkWeights.length == 1 &&
|
||||||
networkWeights[0].length == 1 &&
|
networkWeights[0].length == 1 &&
|
||||||
networkWeights[0][0].length == 3
|
networkWeights[0][0].length == 3
|
||||||
) {
|
) { // Unique, 3 weights perceptron
|
||||||
// Unique, 3 weights perceptron
|
|
||||||
const perceptronWeights = networkWeights[0][0]; // We take the unique
|
const perceptronWeights = networkWeights[0][0]; // We take the unique
|
||||||
|
|
||||||
function perceptronLine(x: number): number {
|
function perceptronLine(x: number): number {
|
||||||
// w0 + w1*x + w2*y = 0 => y = -(w1/w2)*x - w0/w2
|
// w0 + w1*x + w2*y = 0 => y = -(w1/w2)*x - w0/w2
|
||||||
return -(perceptronWeights[1] / perceptronWeights[2]) * x - perceptronWeights[0] / perceptronWeights[2];
|
const w2 = perceptronWeights[2] == 0 ? 1e-6 : perceptronWeights[2]; // Avoid division by zero
|
||||||
|
return -(perceptronWeights[1] / w2) * x - perceptronWeights[0] / w2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simple line
|
// Simple line
|
||||||
|
|||||||
@@ -12,10 +12,11 @@ import {
|
|||||||
PointElement,
|
PointElement,
|
||||||
LineElement,
|
LineElement,
|
||||||
} from 'chart.js';
|
} from 'chart.js';
|
||||||
import { computed, onMounted, ref, watch } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
import LinkHeader from '@/components/LinkHeader.vue';
|
import LinkHeader from '@/components/LinkHeader.vue';
|
||||||
import type {
|
import type {
|
||||||
Dataset,
|
Dataset,
|
||||||
|
DatasetPoint,
|
||||||
InitializationMethod,
|
InitializationMethod,
|
||||||
Iteration,
|
Iteration,
|
||||||
PerceptronType,
|
PerceptronType,
|
||||||
@@ -49,7 +50,7 @@ const props = defineProps<{
|
|||||||
}>();
|
}>();
|
||||||
|
|
||||||
const selectedDatasetName = ref<string>('');
|
const selectedDatasetName = ref<string>('');
|
||||||
const dataset = computed<number[][]>(() => {
|
const dataset = computed<DatasetPoint[]>(() => {
|
||||||
const selected = props.datasets.find(
|
const selected = props.datasets.find(
|
||||||
(d) => d.label === selectedDatasetName.value,
|
(d) => d.label === selectedDatasetName.value,
|
||||||
);
|
);
|
||||||
@@ -72,15 +73,12 @@ const cleanedDataset = computed<
|
|||||||
}[] = [];
|
}[] = [];
|
||||||
// Separate data into each dataset based on value of the last column (label)
|
// Separate data into each dataset based on value of the last column (label)
|
||||||
dataset.value.forEach((row) => {
|
dataset.value.forEach((row) => {
|
||||||
const label = row[row.length - 1];
|
let dataset = cleanedDataset.find((d) => d.label === row.label);
|
||||||
const dataPoint = { x: row[0], y: row[1] };
|
|
||||||
|
|
||||||
let dataset = cleanedDataset.find((d) => d.label === label);
|
|
||||||
if (!dataset) {
|
if (!dataset) {
|
||||||
dataset = { label, data: [] };
|
dataset = { label: row.label, data: [] };
|
||||||
cleanedDataset.push(dataset);
|
cleanedDataset.push(dataset);
|
||||||
}
|
}
|
||||||
dataset.data.push(dataPoint);
|
dataset.data.push({ x: row.x, y: row.y });
|
||||||
});
|
});
|
||||||
return cleanedDataset;
|
return cleanedDataset;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import type { Point } from "chart.js";
|
||||||
|
|
||||||
export type Iteration = {
|
export type Iteration = {
|
||||||
iteration: number;
|
iteration: number;
|
||||||
exampleIndex: number;
|
exampleIndex: number;
|
||||||
@@ -7,10 +9,16 @@ export type Iteration = {
|
|||||||
|
|
||||||
export type Dataset = {
|
export type Dataset = {
|
||||||
label: string;
|
label: string;
|
||||||
data: { x: number; y: number }[];
|
data: DatasetPoint[];
|
||||||
defaultLearningRate: number | undefined;
|
defaultLearningRate: number | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type DatasetPoint = {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
label: number;
|
||||||
|
};
|
||||||
|
|
||||||
export type InitializationMethod = 'zeros' | 'random';
|
export type InitializationMethod = 'zeros' | 'random';
|
||||||
|
|
||||||
export type PerceptronType = 'simple';
|
export type PerceptronType = 'simple';
|
||||||
|
|||||||
Reference in New Issue
Block a user