1 2
5 6 7 8 9
Editor, Emulator Coder
Joined: 8/7/2008
Posts: 1156
no, that's not what he's suggesting. he proposed to make a dll that lua can consume. lua would still be involved, as would the bizhawk to lua bindings. bizhaw's lua bindings are fairly tightly coupled. you could make a plugin api so people can write their own scripts using managed dlls. that would be c# dlls. he said c++ dlls. You'll find that theres no good place to actually put c# code right now to control the emulator with. Your best bet would probably be to extend the lua console system to be able to manage a list of c# coroutines activated by name via reflection, in addition to lua scripts, and have the c# coroutines run immediately after the lua coroutines, so that the means by which the main emulator frontend launches the coroutines is uniform.
Site Admin, Skilled player (1250)
Joined: 4/17/2010
Posts: 11473
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
Dwood15 wrote:
If it's not too tightly coupled, we could make a plugin API so people can write their own scripts using managed .dll's.
I remember coming up with this idea (with a bit different intent) 2 years ago. Feels nice to see evolution going (to go) this direction.
Warning: When making decisions, I try to collect as much data as possible before actually deciding. I try to abstract away and see the principles behind real world events and people's opinions. I try to generalize them and turn into something clear and reusable. I hate depending on unpredictable and having to make lottery guesses. Any problem can be solved by systems thinking and acting.
Joined: 6/18/2015
Posts: 54
zeromus wrote:
no, that's not what he's suggesting. he proposed to make a dll that lua can consume. lua would still be involved, as would the bizhawk to lua bindings.
Ah, well I wouldn't want to do that. I'd rather bypass LUA entirely if I go the managed route. As far as that extra Lua stuff, I definitely wouldn't want to mess with any of that co-routine stuff. I'll take a look at the emulator later this week, I've downloaded the source to my PC, so i'm going to take a peek at what you mean in the code. I'm going to be sad if I couldn't call some function to read a byte directly using the c# code. If it was all loosely coupled and I could call the functions exposed to LUA directly as a normal C# function, that would be ideal, instead of any other stuff.
Editor, Emulator Coder
Joined: 8/7/2008
Posts: 1156
You can call some function to read a byte directly using the c# code. But this is a waste of time until you actually crack the source open. Youll see what I mean then.
Joined: 6/18/2015
Posts: 54
zeromus wrote:
You'll find that theres no good place to actually put c# code right now to control the emulator with. Your best bet would probably be to extend the lua console system to be able to manage a list of c# coroutines activated by name via reflection, in addition to lua scripts, and have the c# coroutines run immediately after the lua coroutines, so that the means by which the main emulator frontend launches the coroutines is uniform.
I've finally taken a peek at the code. I've never messed with reflection in C#, so I'm going to have to read up about that, as I'm not sure what it's for/does. You have a good idea there about adding the C# function I want to run to the Lua coroutines. I'll take a look at it. To be honest, I kind of just want to call a function using C#, extensibility be damned. I am going to do what you said, but just hardcode it and not bother with a plugin/dll system. That said, I'm trying to track down the sections is that you're talking about for the LUA coroutines. So far I haven't seen any code that leads from a main loop. directly. Edit: Well I've decided what I'm going to do. I'm going to implement the NEAT library from sharpNEAT in C# so lua doesn't do that heavy lifting, and make a createNetworks(<params>), evaluateNetworks(<netInputs>) which returns the output neuron states. It would also allow us/me to focus on the fitness function and the inputs/outputs in lua.
darkszero
He/Him
Joined: 7/12/2009
Posts: 181
Location: São Paulo, Brazil
Dwood15 wrote:
Edit: Well I've decided what I'm going to do. I'm going to implement the NEAT library from sharpNEAT in C# so lua doesn't do that heavy lifting, and make a createNetworks(<params>), evaluateNetworks(<netInputs>) which returns the output neuron states. It would also allow us/me to focus on the fitness function and the inputs/outputs in lua.
Zeromus understood what I meant by my last post, but considering what you just wrote I'll try to explain it again. In my suggested workflow, you write your whole logic in lua. That's convenient, because BizHawk already supports this, and expanding the exported functions, if you happen to need more, wont be disruptive to the rest of the emulator. Now for the core functions of your project that will do the heavy lifting, those 'createNetworks' and 'evaluateNetworks', we can do the following: * Create a C/C++ file that defines this function:
Language: c

extern "C" __declspec(dllexport) int luaopen_NEAT(lua_State *L);
* Compile such file to a NEAT.dll * Place the DLL next the the BizHawk.exe * Add the following to your lua script:
Language: lua

local NEAT = require("NEAT") local myNetwork = NEAT.createNetworks(params)
All that is left is implementing the createNetworks and evaluateNetworks, and deciding how it will pass variables around. If your params and return values are simple strings/numbers it's perfect. Simple tables are OK as well, as long as you just fetch values immediately. If there's callbacks, things get nasty. Especially if there's multi-threading. For information on how to implement the C wrapper functions: Manual Lua Reference Example of how the luaopen_NEAT could be written: http://pastebin.com/pGeSwZVC
Joined: 6/18/2015
Posts: 54
DarkZero, those are some interesting ideas, but I'm going to stick with C# unless I move to an all-C++ emulator. I think I have located the largest source of the problem we need to solve. As I was working on integrating sharpNEAT into the emulator, I was thinking about what the limitations of our experiments are, performance-wise. You aren't being limited by CPU DarkZero. I think you are being limited by concurrency. How much CPU is bizhawk using per core? What if we could spawn multiple emulators at once and train several Neural Networks at the same time? While I was trying to use sharpNEAT last night I discovered an inherent issue with the library. The evolution algorithms are extremely tightly coupled with the "Domain" library. Suffice it to say, it's (on the surface) going to be simpler for me to have the evolution program create the main emulator form, auto-load the Lua file to manage the fitness, and then kill the instance once fitness of the genome is measured, then load up the next neural ne then fire up another emulator session. This would have the benefit of allowing us to run X number of emulator instances all at once (where X is the number of species or genomes within a generation), and training them all at the same time... In that case we need to kill all other logic that we don't care about, essentially making the emulator a console. Then the only thing we'd need to script for are the fitness functions, which we can do with lua to make sure it works and then port it to c#, where we can strip the emulator to strictly logic. The Following are mostly notes for myself for the future, you guys can critique this if you want: 1) Have a top-level execution layer that packages up a thread with the neural net(s) (given the settings from a config file) and emulator. This way we can run multiple instances at once. a) Cut out all nonessential logic from the emulator. (bye video, bye sound!) 2) Use either C# or Lua to evaluate fitness. Lua for fast prototyping without having to rebuild the emu every time I want to test a fitness function, then once I have a good fitness function, cut out all the Lua and move it to C#. 3) The spawned thread(s) evaluate nets it holds for fitness and returns the fitness to the main thread. I'll look into ways I can integrate bizhawk with another program.
Editor, Emulator Coder
Joined: 8/7/2008
Posts: 1156
if the cpu was infinitely fast, the ideal solution would be found in zero time. you're being limited by cpu. concurrency just lets you multiply your speed several times. the algorithms are tightly coupled with the 'domain' library because that's how they sense the world that's hosted in bizhawk. this isn't a problem, it's a basic principle. there's no solving it, or changing it. it just is. you have two choices. you can create a script which runs several emuhawk.exe instances, or you can edit emuhawk to run several bsnes cores. if you make the first choice, you will eventually regret it when you discover emuhawk is not easy to control from an external process or via the commandline. you will then make the second choice, which is the correct one. we have a multihawk project which is a (imho not great, but definitely successful) example of rewiring the bizhawk innards. I think it would be better still to make a new tool window in emuhawk which just takes control of everything. ditch the whole main form and existing lua scripting control.
Joined: 7/14/2015
Posts: 3
N3rdsWithGame wrote:
Has anyone thought about using this on Kaizo Mario or any of the other ROM hacks. That would surely be interesting to see how it handles Kaizo
I have it running currently. The answer so far is: Not well. It can work out to bounce over one of the bullets pretty easily, but has yet to figure out how to climb them to jump over the launchers. I'm about 9 hours in. Edit: I'm having a little bit of an issue understanding how to speed up the emulation. I seem to cap out at about 80fps, even at 6400% set, there is no throttling set except for clock throttling (I get "Unable to change speed, enabled clock throttling). All GUI elements are disabled and the only thing visible is the blue background and FPS counter. This is a fairly beasty machine, is there a setting I'm missing? Cheers
Editor, Emulator Coder
Joined: 8/7/2008
Posts: 1156
The machine isn't as beast as you think. bsnes is a slow emulator. be sure youve picked the performance core..
Joined: 6/18/2015
Posts: 54
zeromus wrote:
The machine isn't as beast as you think. bsnes is a slow emulator. be sure youve picked the performance core..
That, and he needs to uncheck "clock throttling". That said, even my pc gets a minimum of 120 fps unthrottled, and it's crap.
Joined: 7/14/2015
Posts: 3
zeromus wrote:
The machine isn't as beast as you think. bsnes is a slow emulator. be sure youve picked the performance core..
I suppose, but if other users are hitting the 6400% limit, surely I should get a little bit more than ~160% on a OC Quad i7? Also, the performance core crashes instantly upon trying to start LUA, but prior to that it gets about 140fps. Strangely, when I attempt to change the speed (with clock throttling turned off + performance core), it throws the error below and drops to 70fps.
Dwood15 wrote:
That, and he needs to uncheck "clock throttling". That said, even my pc gets a minimum of 120 fps unthrottled, and it's crap.
When I try and increase the speed above 100% it throws: "Unable to change speed, please switch to clock throttle". I assumed clock throttle had to be enabled.
Editor, Emulator Coder
Joined: 8/7/2008
Posts: 1156
Anything you read about a 6400% limit is idiotic. There is no 6400% limit. Nobody is even achieving 6400%. Stop fiddling with the speed. Unthrottle the emulator. It won't go faster than that. What youre basically doing is saying "I want more speed. I see a speed option" and clubbing it with your first without thinking. The speed controls how fast it runs throttled. If you cant achieve that speed, you dont get that speed. If you want maximum speed, you dont want to control the speed. Run it unthrottled. The performance core doesnt crash for most people. Maybe youre doing something odd, or your OC isnt as stable as you think.
Joined: 7/14/2015
Posts: 3
zeromus wrote:
Anything you read about a 6400% limit is idiotic. There is no 6400% limit. Nobody is even achieving 6400%. Stop fiddling with the speed. Unthrottle the emulator. It won't go faster than that. What youre basically doing is saying "I want more speed. I see a speed option" and clubbing it with your first without thinking. The speed controls how fast it runs throttled. If you cant achieve that speed, you dont get that speed. If you want maximum speed, you dont want to control the speed. Run it unthrottled. The performance core doesnt crash for most people. Maybe youre doing something odd, or your OC isnt as stable as you think.
I was merely reading through this thread and saw posts with people thinking about removing the 6400% limiter, which I assumed meant they'd hit it. I was curious how, considering how ridiculously difficult it is to get BSNES past 300% (I had done research, honest. I know how threading works and the fact it's single threaded and only running on one core so clock speed counts etc.), so I assumed there must have been an option that does some ridiculous stuff somewhere that boosts speed, though it seems that they were just mistake in understanding what more than 200% looks like. But thank you for pointing that I had in fact hit the wall. With some modifications to the core config I've managed to get it to about ~310% (190 fps). I assure you it isn't my clock - It's starting the LUA script while the emulator is in performance that causes the application to crash in this case. It may be something to do with Win10, or new AMD drivers or something savestates(Yes, I have a different savestate for compatibility and performance) . It works fine in compatibility with a slightly lower FPS, so I'll stay on that.
Editor, Emulator Coder
Joined: 8/7/2008
Posts: 1156
OK, well, crashing with performance + lua isn't expected, and it isn't normal. Savestate mismatch between compatibility/performance profile shouldnt create crashes, jsut fails loading the savestates.
Joined: 8/18/2015
Posts: 4
So, I made some modifications to the neatevolve.lua and created some more outputs in the Banner. Also I made the Fitness form bigger and the Save and Load buttons bigger. Script http://pastebin.com/drKN5t2F Must restart to work with new values which get stored. Will not work with your *.state.pool ~zoom if you like~, ctrl+ Generation 7, 47% done
G:7-47% 
Avarage fitness current generation / Avarage fitness last generation / Max Avarage Fitness
AF: 15/-6/-6
TotalTries that this *state.pool has done
TT:4340
Avarage fitness stales, counts the generations with no new Max Avarage Fitness, here 0 means last Generation hat a new MaxAF
AFS:0
UniqueSpeciecsId, each new Species gets a new id and the UniqueSpeciesId goes +1, 1115 means that this is the 1115th species created in this *.state.pool (it is tied to a specific species)
Id:1115
Age of that species, the amount of Generations they have survived in this *.state.pool
a:6
Fitness of the current run / Maximum Fitness (means best run)
F:13/538
CurrentSpecies - genome (changes each generation, is not tied to a specific species)
s:112-4
The 96th run in this Generation, -- must ranme to run
try:96
1 generation has passed since this species has beaten its own best fitness in this .*state.pool (species.staleness)
ss:1
Must restart to work with new values which get stored. Will not work with your .*state.pool The code is a mess, feel free to critisize and improve or ask questions. Also: (solved) Can I somehow remove the biasCell
local biasCell = {}
	biasCell.x = 80
	biasCell.y = 110
	biasCell.value = network.neurons[Inputs].value
	cells[Inputs] = biasCell
without making the program crush? I think MarI/O gets wrong level input and that makes him ultimately less intelligent. Allthough he will probably start running right sooner with the biasCell, it is impacting on his decisionmaking later by giving faulty level information, doesn't it?. Ideas appreciated. Also: When suddenly my FPS dropped (from ~150 to ~50 over night) in Windows 7 playing around with Visual Properties of Windows 7 + disabling Windows Fullscreen Hack in Display options in Bizhawk did the trick for me. Something with how Windows displays its windows. The first screenshot shows the options i mean, not sure which did the trick: http://www.sevenforums.com/tutorials/1908-visual-effects-settings-change.html
Amaraticando
It/Its
Editor, Player (159)
Joined: 1/10/2012
Posts: 673
Location: Brazil
Has MarI/O beaten any hard level so far? Will he ever do it?
Joined: 8/18/2015
Posts: 4
I found a way to remove the biasCell. Testing is ongoing, but he learns slower, still learns though. Hopefully staleness is lower and he will not reach a dead point in his evolution so often. Pastebin: http://pastebin.com/i4jY7PpZ The screenshot show the difference in neural nets, they are not a good base to compare, since it is a different level and different pool conditions, but it show what i hope to achieve by removing the biasCell. I want Mario to be smarter in the long run by giving him correct information. ~zoom if you like~ ctrl+
Amaraticando wrote:
Has MarI/O beaten any hard level so far? Will he ever do it?
I'm testing and changing the code. Provide me with a savestate of a 'hard level' and I'm willing to give it a try and see how far he can get. The unchanged original script would already fail at the second level when you have to jump up a few platforms before you can go right to finish the level. This is propably not dooable without changes to the Fitness calculation, or setting a high TimeoutConstant, and then it is still unlikely i think.
Joined: 8/18/2015
Posts: 4
I think this is a bug, i haven't seen that before in the original, has maybe someone else? It looks like the neurol connection are connecting the buttons itself with each other. Which is not meant to happen in theory. There seem to be 2 connections between 'B' and 'Left', a red and a green one. Someone has an idea?
Joined: 6/18/2015
Posts: 54
Gotta be honest, I thought this thread died. Anyway, I've been in limbo lately, and haven't had access to a good development computer setup for a while. I still don't but I'm in a situation where I can get working on my multihawk setup. Zeromus: I know it's not supported, but it looks like there's an issue with Multihawk's implementation of bsnes. Forcing snes9x in multihawk allows me to run multiple snes instances. I haven't decided whether I want to use bizhawk or multihawk as my emulator mnger or roll my own, as each one seems to have their own setups I'm going to want to configure, though as things have progressed I'm leaning towards my own control form which launches the emulator instances in a threaded state. toolchild: I'm not sure what you expect to get by removing bias cell, but I wish you the best in getting a smarter AI out of it. As far as the connections in your latest post child, don't worry about the layout of the neurons in the networks too much. The goal is to get the ai to work, not to audit the neurons. Survival of the fittest doesn't care how something gets done, just that it does. Lastly, the SethBling MarI/O ai has a major bug, in that it should allow for recurrent neural networks, but doesn't. It needs to allow full clocks to form. Amaraticando: It looks like there hasn't been much progress on the AI front for a while. I'm at the start of a pretty big change in mario nn's though. The focus after this is going to be on creating a more effective training environment, so mario won't just be memorizing.
Editor, Emulator Coder
Joined: 8/7/2008
Posts: 1156
if you can use snes9x in multihawk to mari/o, then you should.
Joined: 8/18/2015
Posts: 4
Dwood15 wrote:
toolchild: I'm not sure what you expect to get by removing bias cell, but I wish you the best in getting a smarter AI out of it. As far as the connections in your latest post child, don't worry about the layout of the neurons in the networks too much. The goal is to get the ai to work, not to audit the neurons. Survival of the fittest doesn't care how something gets done, just that it does. Lastly, the SethBling MarI/O ai has a major bug, in that it should allow for recurrent neural networks, but doesn't. It needs to allow full clocks to form.
Hi, DWood15: By removing the biasCell I hope to give MarI/O a more precise information about the level/situation he is in. The biasCell isn't actually part of his environment, it is not part of the level. So it is false information. As I understand it, that should make him dumber on the long run. About the button neuros connecting to each other: I'm breaking my brain over it, and i cannot come to a conclusion whether it could make sense to connect button neures to button neuros or whether it should not happen. On the one side it can be a pretty good idea to connect button neurons because it might make sense in Mario World aswell to press buttons because of the combination of buttons already pressed + the situation, on the other side it looks just wrong. But you are right, evolution should sort that out for us, if that works correctly. I did some minor changes, this is what it looks like now: I am still new to programming, so feel free to give advice.
Joined: 6/18/2015
Posts: 54
Hey Toolchild, so I took a look at biasCell in context of the whole script, and from what I can tell, biasCell doesn't actually cover any of the inputs into the neural network. Instead of that, biasCell is actually just something used for rendering. I didn't look up too much of it, however, because for me the network visualization is basically useless. In fact, it's on my list of things to rewrite, as I hate the way SethBling coded the display and the sprite readings. My own code is progressing smoothly, albeit slowly, hoping to have a proper c# implementation by the end of the week. If not, it should be next week. Secondly, i've realized something about fitness - that there's a flaw in the fitness function in that it considers time as a portion of the fitness. While it's a nice thought in theory, it takes too much hand tuning to get right, so i've removed time from the fitness function. Thirdly, one (small) way to speed lua up is to use multiplication of decimal values instead of division where you can. Over the course of thousands of iterations, m-plying can cost a noticeably less number of iterations than dividing touse. Fourthly, the real issues holding the ai back the most, toolchild, is definitely the fitness function. If you want to figure out how to help the ai succeed, you'll want to revisit fitness and add your own variables from ram from places like smw-central or the smw bizhawk lua script linked earlier in the thread.
tom_mai78101
He/Him
Player (126)
Joined: 3/16/2015
Posts: 160
I have hit a hard limit when it comes to MarI/O trying to beat this level (where Mario is currently standing.) http://i.imgur.com/ux3d9pW.png It's been running for a long time. I'm sure this level can never be beat. Download pool file: http://www.mediafire.com/download/brfa7t6awpm6vwk/mario-limit.zip
Joined: 6/18/2015
Posts: 54
1. Make your image smaller tom 2. Have you modified the script at all? My Ai has been able to beat that level consistently.
1 2
5 6 7 8 9