r/PowerShell • u/Nearby-Ambition-1319 • Jun 01 '23
STUPID AI IN POWERSHELL?
Hi, hello.
Some of you guys might recognize me from my previous posts, gloating on about my 3d ascii graphics I've done in PowerShell.
Me taking a break from PowerShell programming, because I was caught doing some "helpful" acts within school, I have come back!
I was bored a week ago, procrastinating my English essay, I fell into the deep rabbit hole of
Artificial intelligence!
With this sudden interest, it was evident what I wanted to make next.
Not sure if this is the first regardless considering I'm 15 and its in PowerShell 💀, idc.
Single-Nueral-PowerShell
Trained with linear regression training, and with one neuron,
It calculates the multiples of numbers,
$train = @(
@(0, 0),
@(1, 2),
@(2, 4),
@(3, 6),
@(4, 8)
)
$train_count = $train.Length
function rand_float {
return [float](Get-Random) / [float]::MaxValue
}
function cost($w) {
$result = 0.0
$n = $train_count
for ($i = 0; $i -lt $n; $i++) {
$x = $train[$i][0]
$y = $x * $w
$d = $y - $train[$i][1]
$result += $d * $d
}
$result /= $n
return $result
}
function dcost($w) {
$result = 0.0
$n = $train_count
for ($i = 0; $i -lt $n; $i++) {
$x = $train[$i][0]
$y = $train[$i][1]
$result += 2 * ($x * $w - $y) * $x
}
$result /= $n
return $result
}
$w = rand_float * 10.0
$rate = 1e-1
Write-Host "cost = $(cost($w)), w = $w"
for ($i = 0; $i -lt 50; $i++) {
$dw = dcost($w)
$w -= $rate * $dw
Write-Host "cost = $(cost($w)), w = $w"
}
Write-Host "------------------------------"
Write-Host "Made By JH1SC"
Write-Host "w = $w"Therefore, its prediction ($w) would be 2! And not to mention works with even decimals, Even PI!!!
PSMultiNeural
It has multi-layered neural networks to calculate XOR logic gate, and or any other logic gate!
It uses backpropagation to train the neural network!!
surprisingly takes like 10 seconds to train with the defaults!
$num_inputs = 3
$num_hidden_neurons = 4
$num_outputs = 2
$learning_rate = 1
$num_iterations = 10000Its too chunky to paste all the code but for an example:
$train = @(
@(0, 0, 0),
@(0, 1, 1),
@(1, 0, 1),
@(1, 1, 0)
r1 r2 r3
)Effectively, r1 and r2 being the two inputs, and then r3 being the outputs its trained on!
Here is a picture PSMultiNeuralXOR/Brains.png at main · jh1sc/PSMultiNeuralXOR · GitHub
Anyways thanks for reading lol
Staring my repo, would be kindly appreciated😀!
cause hard work and stuf