Fixed Regression datasets
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled

This commit is contained in:
2026-03-23 16:01:22 +01:00
parent bcaf334380
commit a92a47288c
3 changed files with 30 additions and 11 deletions

View File

@@ -29,11 +29,6 @@ class LinearOrderDataSetReader implements IDataSetReader
$newLine[] = (float) $value;
}
// if the dataset is for regression, we add a fake label of 0
if (count($newLine) === 2) {
$newLine[] = 0.0;
}
$this->lines[] = $newLine;
}
}

View File

@@ -29,11 +29,6 @@ class RandomOrderDataSetReader implements IDataSetReader
$newLine[] = (float) $value;
}
// if the dataset is for regression, we add a fake label of 0
if (count($newLine) === 2) {
$newLine[] = 0.0;
}
$this->lines[] = $newLine;
}
}

View File

@@ -35,6 +35,30 @@ const farRightDataPointX = computed(() => {
return maxX;
});
function getPerceptronOutput(weightsNetwork: number[][], inputs: number[]): number[] {
for (const layer of weightsNetwork) {
const nextInputs: number[] = [];
for (const neuron of layer) {
const bias = neuron[0];
const weights = neuron.slice(1);
let sum = bias;
for (let i = 0; i < weights.length; i++) {
sum += weights[i] * inputs[i];
}
const activated = props.activationFunction(sum);
nextInputs.push(activated);
}
inputs = nextInputs;
}
return inputs;
}
function getPerceptronDecisionBoundaryDataset(
networkWeights: number[][][],
activationFunction: (x: number) => number = (x) => x,
@@ -48,12 +72,17 @@ function getPerceptronDecisionBoundaryDataset(
if (
networkWeights.length == 1 &&
networkWeights[0].length == 1 &&
networkWeights[0][0].length == 3
networkWeights[0][0].length <= 3
) {
// Unique, 3 weights perceptron
const perceptronWeights = networkWeights[0][0]; // We take the unique perceptron
function perceptronLine(x: number): number {
if (perceptronWeights.length < 3) {
// If we have less than 3 weights, we assume missing weights are zero
perceptronWeights.push(getPerceptronOutput(networkWeights, [x])[0]);
}
// w0 + w1*x + w2*y = 0 => y = -(w1/w2)*x - w0/w2
const w2 = perceptronWeights[2] == 0 ? 1e-6 : perceptronWeights[2]; // Avoid division by zero
return -(perceptronWeights[1] / w2) * x - perceptronWeights[0] / w2;