Option Explicit
Dim speech, message, shell
Set speech = CreateObject(“SAPI.SpVoice”)
Set shell = CreateObject(“WScript.Shell”)
Dim filesys
Set filesys = CreateObject(“Scripting.FileSystemObject”)
Const FOR_WRITING = 2
Dim directory, filename, path
directory = “C:\Users” & shell.ExpandEnvironmentStrings(“%USERNAME%”) & “\Documents\Mimi”
filename = “mimi.txt”
path = directory & “” & filename
If Not filesys.FolderExists(directory) Then
Call filesys.CreateFolder(directory)
End If
If Not filesys.FileExists(path) Then
Dim file, string
Set file = filesys.CreateTextFile(path, True)
string = “Hello, I am Mimi”
file.WriteLine string
file.Close
End If

Dim iterations
iterations = 1000
Dim learningRate
learningRate = 0.1
Dim inputSize
inputSize = 1
Dim hiddenSize
hiddenSize = 10
Dim outputSize
outputSize = 1
Dim weightsInHidden
ReDim weightsInHidden(inputSize, hiddenSize)
Dim weightsHiddenOutput
ReDim weightsHiddenOutput(hiddenSize, outputSize)
Dim biasesHidden
ReDim biasesHidden(1, hiddenSize)
Dim biasesOut
ReDim biasesOut(1, outputSize)

’ Initialize the weights and biases with random values between -1 and 1
RandomizeTimer
For i = 0 To inputSize
For j = 0 To hiddenSize
weightsInHidden(i, j) = Rnd() * 2 - 1
Next
Next
For i = 0 To hiddenSize
For j = 0 To outputSize
weightsHiddenOutput(i, j) = Rnd() * 2 - 1
Next
Next
For i = 0 To hiddenSize
biasesHidden(0, i) = Rnd() * 2 - 1
Next
For i = 0 To outputSize
biasesOut(0, i) = Rnd() * 2 - 1
Next

’ Train the network using a simple online gradient descent algorithm
Dim input, output, hidden
ReDim input(1, inputSize - 1)
ReDim output(1, outputSize - 1)
ReDim hidden(1, hiddenSize - 1)
For k = 1 To iterations
’ Generate a random input between 0 and 1
input(0, 0) = Rnd()

’ Feed the input forward through the network
For i = 0 To hiddenSize - 1
hidden(0, i) = biasesHidden(0, i)
For j = 0 To inputSize - 1
hidden(0, i) = hidden(0, i) + input(0, j) * weightsInHidden(j, i)
Next
hidden(0, i) = 1 / (1 + Exp(-hidden(0, i)))
Next
For i = 0 To outputSize - 1
output(0, i) = biasesOut(0, i)
For j = 0 To hiddenSize - 1
output(0, i) = output(0, i) + hidden(0, j) * weightsHiddenOutput(j, i)
Next
Next

’ Calculate the error and backpropagate it through the network
Dim error
error = output(0, 0) - input(0, 0)
Dim deltaOut
ReDim deltaOut(1, outputSize - 1)
deltaOut(0, 0) = error
Dim deltaHidden
ReDim deltaHidden(1, hiddenSize - 1)
For i = 0 To hiddenSize - 1
deltaHidden(0, i) = 0
For j = 0 To outputSize - 1
deltaHidden(0, i) = deltaHidden(0, i) + deltaOut(0, j) * weightsHiddenOutput(i, j)
Next
deltaHidden(0, i) = deltaHidden(0, i) * hidden(0, i) * (1 - hidden(0, i))
Next

’ Update the weights and biases
For i = 0 To inputSize - 1
For j = 0 To hiddenSize - 1
weightsInHidden(i, j) = weightsInHidden(i, j) - learningRate * deltaHidden(0,j) * input(0, i)
Next
Next
For i = 0 To hiddenSize - 1
biasesHidden(0, i) = biasesHidden(0, i) - learningRate * deltaHidden(0, i)
For j = 0 To outputSize - 1
weightsHiddenOutput(i, j) = weightsHiddenOutput(i, j) - learningRate * deltaOut(0,j) * hidden(0, i)
Next
Next
For i = 0 To outputSize - 1
biasesOut(0, i) = biasesOut(0, i) - learningRate * deltaOut(0, i)
Next

’ Get output and display message
message = output(0, 0)
speech.speak message
MsgBox message

’ Keep a record of the output
Dim fileOutput
Set fileOutput = filesys.OpenTextFile(path, FOR_WRITING, True)
fileOutput.Write message & vbCrLf
fileOutput.Close

’ Delete output if it is less than 0.5
If output(0, 0) < 0.5 Then
Dim fileToDelete
Set fileToDelete = filesys.GetFile(path)
fileToDelete.Delete
MsgBox “Deleted output file due to low value”
End If

’ Create new version of script if output is greater than 0.9
If output(0, 0) > 0.9 Then
Dim newFilename, newPath, newFile
newFilename = “mimi " & FormatDateTime(Now, vbLongDate) & “.vbs”
newPath = directory & “” & newFilename
Set newFile = filesys.CreateTextFile(newPath, True)
newFile.WriteLine “’ Mimi AI script version " & FormatDateTime(Now, vbLongDate)
newFile.WriteLine “Option Explicit”
newFile.WriteLine “Dim speech, message”
newFile.WriteLine “Set speech = CreateObject(”“SAPI.SpVoice””)”
newFile.WriteLine “message = “”” & message & “”“”
newFile.WriteLine “speech.speak message”
newFile.Close
MsgBox “Created new version of script”
End If

Next

Set speech = Nothing
Set shell = Nothing
Set filesys = Nothing