-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_run.php
More file actions
105 lines (88 loc) · 3.59 KB
/
Copy pathtest_run.php
File metadata and controls
105 lines (88 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* Simple test runner to verify all ML components work correctly
* Run this to make sure everything is implemented correctly
*/
// Enable error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);
echo "Machine Learning in PHP - Component Test Runner\n";
echo str_repeat("=", 60) . "\n\n";
// Test 1: Linear Algebra
echo "Testing Linear Algebra Components...\n";
require_once 'src/LinearAlgebra/Vector.php';
require_once 'src/LinearAlgebra/Matrix.php';
try {
$v1 = new MLPyHP\LinearAlgebra\Vector([1, 2, 3]);
$v2 = new MLPyHP\LinearAlgebra\Vector([4, 5, 6]);
$dotProduct = $v1->dotProduct($v2);
echo "✓ Vector operations working (dot product: {$dotProduct})\n";
$m1 = new MLPyHP\LinearAlgebra\Matrix([[1, 2], [3, 4]]);
$m2 = new MLPyHP\LinearAlgebra\Matrix([[5, 6], [7, 8]]);
$result = $m1->multiply($m2);
echo "✓ Matrix operations working\n";
} catch (Exception $e) {
echo "✗ Linear Algebra Error: " . $e->getMessage() . "\n";
}
// Test 2: Algorithms
echo "\nTesting Algorithm Components...\n";
require_once 'src/Algorithms/Sorting.php';
require_once 'src/Algorithms/Searching.php';
try {
$data = [3, 1, 4, 1, 5, 9, 2, 6];
$sorted = MLPyHP\Algorithms\Sorting::bubbleSort($data);
echo "✓ Sorting algorithms working\n";
$index = MLPyHP\Algorithms\Searching::binarySearch($sorted, 5);
echo "✓ Search algorithms working (found 5 at index {$index})\n";
} catch (Exception $e) {
echo "✗ Algorithm Error: " . $e->getMessage() . "\n";
}
// Test 3: Data Processing
echo "\nTesting Data Processing Components...\n";
require_once 'src/DataProcessing/DataCleaner.php';
try {
$messyData = [
['value' => 10],
['value' => null],
['value' => 30]
];
$cleaned = MLPyHP\DataProcessing\DataCleaner::handleMissingValues($messyData, 'mean');
echo "✓ Data cleaning working\n";
$outliers = MLPyHP\DataProcessing\DataCleaner::detectOutliers([1, 2, 3, 100]);
echo "✓ Outlier detection working (found " . count($outliers) . " outliers)\n";
} catch (Exception $e) {
echo "✗ Data Processing Error: " . $e->getMessage() . "\n";
}
// Test 4: Neural Network Components
echo "\nTesting Neural Network Components...\n";
require_once 'src/NeuralNetwork/Perceptron.php';
require_once 'src/NeuralNetwork/NeuralNetwork.php';
require_once 'src/NeuralNetwork/LossFunctions.php';
try {
// Test Perceptron
$perceptron = new MLPyHP\NeuralNetwork\Perceptron(2, 0.1, 'step');
$prediction = $perceptron->predict([1, 0]);
echo "✓ Perceptron working (prediction: {$prediction})\n";
// Test Neural Network
$network = new MLPyHP\NeuralNetwork\NeuralNetwork([2, 3, 1]);
$output = $network->forwardPropagate([0.5, 0.8]);
echo "✓ Neural Network working (output: " . number_format($output[0], 4) . ")\n";
// Test Loss Functions
$mse = MLPyHP\NeuralNetwork\LossFunctions::meanSquaredError([0.8], [0.9]);
echo "✓ Loss Functions working (MSE: " . number_format($mse, 4) . ")\n";
} catch (Exception $e) {
echo "✗ Neural Network Error: " . $e->getMessage() . "\n";
}
// Test 5: Complete Example
echo "\nTesting Complete Example...\n";
try {
require_once 'src/Examples/CompleteExample.php';
echo "✓ Complete example loaded successfully\n";
echo "✓ All components integrated properly\n";
} catch (Exception $e) {
echo "✗ Complete Example Error: " . $e->getMessage() . "\n";
}
echo "\n" . str_repeat("=", 60) . "\n";
echo "Component testing complete!\n";
echo "Run 'php src/Examples/CompleteExample.php' for full demonstration.\n";
echo str_repeat("=", 60) . "\n";