You there you haven’t responded at all?
You there? Its been awhile. I never gotten the solution.
His school probably started and he cant do anything 3thy character limit
oh okay. probably thats the reason.
Yes sorry, college started and I don’t got much time to be active here. We will see about your issues tomorrow and try to fix them!
Thank you for considering to use my plugin by the way, it means a lot
Well OpenML is of course a great idea and is really well made. My product tends to be easier to use than OpenML and easy to apply to any characters in any games. Its main goal is to be accessible for everyone so you don’t need any technical knowledges to use it. I’ll include an AI Barista NPC I’ve made with this plugin that can think by itself and create new recipes that have never been created before, so you can see it’s true potential and capabilities.
I’ve noticed you didn’t gave any training datas to the Neural Network when training it in the first place. That’s why it wasn’t working, it had no training data, therefore no possibilities to predict.
So here I changed variable names and the params to make it easier to read and maintain in the future:
-- Example training data for the neural network
local nn_data = {
{0, 0}, -- Forward obstacle detected
{0, 1}, -- Backward obstacle detected
{1, 0}, -- Right obstacle detected
{1, 1}, -- Left obstacle detected
}
local nn_targets = {
{1}, -- Move forward
{2}, -- Move backward
{3}, -- Turn left
{4}, -- Turn right
}
-- Define constants
local nn_params = {
numInputs = 4,
numHidden = 48,
numOutputs = 4,
epochs = 1000,
learningRate = 0.1,
debugMode = false -- adds additional prints in the console for each epochs
}
-- Initialize Neural Network model
nn_model:train(nn_data, nn_targets, nn_params)
I also modified this part to make it easier and less complex:
local function chooseAction(obstacles)
-- Predict action based on obstacles
local output = nn_model:predict(obstacles)
local action = output[1] -- Assuming the output returns a list and we pick the first prediction
-- Execute action based on prediction
if action == 1 then
moveForward()
elseif action == 2 then
moveBackward()
elseif action == 3 then
turnLeft()
elseif action == 4 then
turnRight()
end
end
So here’s the final script:
local RS = game:GetService("ReplicatedStorage")
local Modules = require(RS:WaitForChild("Modules").Modules)
local machineLearning = Modules.MachineLearningModule
local nn_model = machineLearning.new(machineLearning.ModelType.NeuralNetwork)
local dt_model = machineLearning.new(machineLearning.ModelType.DecisionTree)
local NPC = workspace:WaitForChild("NPCFolder"):WaitForChild("tracedrounds")
local humanoid = NPC:FindFirstChildWhichIsA("Humanoid")
local humanoidRootPart = humanoid.RootPart
-- Example training data for the neural network
local nn_data = {
{0, 0}, -- Forward obstacle detected
{0, 1}, -- Backward obstacle detected
{1, 0}, -- Right obstacle detected
{1, 1}, -- Left obstacle detected
}
local nn_targets = {
{1}, -- Move forward
{2}, -- Move backward
{3}, -- Turn left
{4}, -- Turn right
}
-- Define constants
local nn_params = {
numInputs = 4, -- Number of inputs, corresponding to directions/obstacles
numHidden = 48, -- Hidden layer size
numOutputs = 4, -- Actions: forward, backward, left, right
epochs = 1000, -- Training iterations
learningRate = 0.1, -- Learning rate for the neural network
debugMode = false -- Disable debug printing
}
-- Initialize Neural Network model
nn_model:train(nn_data, nn_targets, nn_params)
-- Define obstacle detection function
local function detectObstacles()
local obstacles = {}
local directions = {
{ direction = humanoidRootPart.CFrame.LookVector, name = "forward" },
{ direction = -humanoidRootPart.CFrame.LookVector, name = "backward" },
{ direction = humanoidRootPart.CFrame.RightVector, name = "right" },
{ direction = -humanoidRootPart.CFrame.RightVector, name = "left" }
}
for _, dir in ipairs(directions) do
local ray = Ray.new(humanoidRootPart.Position, dir.direction * 10)
local params = RaycastParams.new()
params.RespectCanCollide = true
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {NPC}
local result = workspace:Raycast(humanoidRootPart.Position, dir.direction * 10, params)
if result then
table.insert(obstacles, _)
else
table.insert(obstacles, 0)
end
end
return obstacles
end
-- Define action functions
local function moveForward()
humanoid:MoveTo(humanoidRootPart.Position + humanoidRootPart.CFrame.LookVector * 5)
end
local function moveBackward()
humanoid:MoveTo(humanoidRootPart.Position - humanoidRootPart.CFrame.LookVector * 5)
end
local function turnLeft()
humanoidRootPart.CFrame = humanoidRootPart.CFrame * CFrame.Angles(0, math.rad(-90), 0)
end
local function turnRight()
humanoidRootPart.CFrame = humanoidRootPart.CFrame * CFrame.Angles(0, math.rad(90), 0)
end
local function chooseAction(obstacles)
-- Predict action based on obstacles
local output = nn_model:predict(obstacles)
local action = output[1] -- Assuming the output returns a list and we pick the first prediction
-- Execute action based on prediction
if action == 1 then
moveForward()
elseif action == 2 then
moveBackward()
elseif action == 3 then
turnLeft()
elseif action == 4 then
turnRight()
end
end
-- Main loop
while true do
local obstacles = detectObstacles()
chooseAction(obstacles)
wait(1) -- Adjust as needed for your game
end
Hope it works! Let me know if there are any more issues.
Can I implement this for my upcoming cooking game recipe? Basically you make recipe with ingredients.
ServerStorage.Modules.MachineLearningModule.NeuralNetwork:52: attempt to perform arithmetic (mul) on nil and number
new error recieved.
I see, mind turning on debug mode so I could see what does it print in the output?
Sure, feel free to use this system for your game!
Could you send me the link to it so I can test it out?
Sure I’m currently in school. So later.
I am only trying to see if it works but it will only take me long to make this. I will update you if I make one.