Fixed Regression datasets
This commit is contained in:
@@ -29,11 +29,6 @@ class LinearOrderDataSetReader implements IDataSetReader
|
|||||||
$newLine[] = (float) $value;
|
$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;
|
$this->lines[] = $newLine;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,11 +29,6 @@ class RandomOrderDataSetReader implements IDataSetReader
|
|||||||
$newLine[] = (float) $value;
|
$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;
|
$this->lines[] = $newLine;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,30 @@ const farRightDataPointX = computed(() => {
|
|||||||
return maxX;
|
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(
|
function getPerceptronDecisionBoundaryDataset(
|
||||||
networkWeights: number[][][],
|
networkWeights: number[][][],
|
||||||
activationFunction: (x: number) => number = (x) => x,
|
activationFunction: (x: number) => number = (x) => x,
|
||||||
@@ -48,12 +72,17 @@ function getPerceptronDecisionBoundaryDataset(
|
|||||||
if (
|
if (
|
||||||
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 perceptron
|
const perceptronWeights = networkWeights[0][0]; // We take the unique perceptron
|
||||||
|
|
||||||
function perceptronLine(x: number): number {
|
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
|
// 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
|
const w2 = perceptronWeights[2] == 0 ? 1e-6 : perceptronWeights[2]; // Avoid division by zero
|
||||||
return -(perceptronWeights[1] / w2) * x - perceptronWeights[0] / w2;
|
return -(perceptronWeights[1] / w2) * x - perceptronWeights[0] / w2;
|
||||||
|
|||||||
Reference in New Issue
Block a user