Trainable elements?

  • peeps
    14th Sep 2018 Member 2 Permalink

    Hello guys

    I am currently developing an experimental neural network based trainable element system.

    What i want to do:

    an API for dynamic lua element generation and training:

    you create a special particle, or specify the particular data, then you specify the state of simulation around that particle, and what the particle itself and the stuff arount that particle would be look like after a tick.

    you create as many examples of the desired interactions that you want to create for this element, using a "before" and an "after" format.

    Then the neural network should be able to "learn" what it should do next, and after a few hundred training samples, should behave like what you want it to be. the particle basically learn it's proper update function through machine learning.

     

    these are the samples of my code that i am currently working on.

    Will this work? do you have any suggestions? for example, to improve this code or to submit some functions, so i can bring this into existence? thanks.

     

    function LinRec_AC(level,offset,sensitivity)
     x=(level-offset)*sensitivity
     if x>0 then
      return x
     else
      return x*0.1
     end
    end
    function LinRec_BP(output,offset,sensitivity)
     if output>0 then
      return (output/sensitivity)+offset
     else
      return (output*10/sensitivity)+offset
     end
    end
    function FullyConnected.initialize_neurons(number,inter_mediate_depth,i_o_range)
     mapping={}
     Cv=1
     mapping[Cv]=FullyConnected.initialize_input(i_o_range)
     Cv=Cv+1
     for i=1,inter_mediate_depth,1 do
      mapping[Cv]=FullyConnected.initialize_layer(number)
      Cv=Cv+1
     end
     mapping[Cv]=FullyConnected.initialize_output(i_o_range)
     for j=1,Cv-1,1 do
      FullyConnected.initialize_connection(mapping[j],mapping[j+1])
     end
     return mapping
    end
     
    function FullyConnected.LoadFromElement(mapping,x,y,Mem)
     bits=bit.tobit(tpt.get_property("tmp",x,y))
     for index,Neui in pairs(mapping[1]) do
      if Neui.typ==input then
       part_type=tpt.get_property("type",x+Neui.x,y+Neui.y)
       if Neui.typ=="typeU2b" then
        Neui.level=math.floor(part_type/64)*Neui.multiplier
       elseif Neui.typ=="typeM3b" then
        Neui.level=math.floor(part_type%64/8)*Neui.multiplier
       elseif Neui.typ=="typeL3b" then
        Neui.level=part_type%8*Neui.multiplier
       else
        Neui.level=tpt.get_property(Neui.property,x+Neui.x,y+Neui.y)*Neui.multiplier
       end
      elseif Neui.typ=mem_input then
       bmask=bit.lshift(bit.tobit(1),Neui.place-1)
       bres=bit.rshift(bit.band(bits,bmask),Neui.place-1)
       Neui.level=bres*Neui.multiplier
      end
     end
    end
     
    also, is this neuron design adequate?
     
    default_Neuron={typ=default,level=0,offset=0.5,sensitivity=1,Weights_from={amount=0},Weights_to={amount=0}}
    input_neuron={typ=input,multiplier=0.1,offset=0.5,sensitivity=1,Weights_to={amount=0},level=0,x=0,y=0,property="life"}
    input_memory_neuron={typ=mem_input,multiplier=1,offset=0.5,sensitivity=1,Weights_to={amount=0},level=0,place=1}
    output_neuron={typ=output,multiplier=10,offset=0.5,sensitivity=1,Weights_from={amount=0},level=0,x=0,y=0,property="life"}
    output_memory_neuron={typ=mem_output,threshold=0.5,offset=0.5,sensitivity=1,Weights_from={amount=0},level=0,place=1}
     
    are there any improvement for this?
     
    This is just pretty much a WIP. I am welcome for any one that could help.
     
    Update: the full WIP code is behind this link:
    Edited 2 times by peeps. Last: 14th Sep 2018
  • NF
    14th Sep 2018 Member 0 Permalink

    Looks nice, I wish I could code but unfortunately lack the patience. Wish you luck.

  • Holly866_668
    2nd Jul 2019 Member 0 Permalink

    This is nice code, but you forgot to use == instead ofon lines 346 and 381.

     

    Edit: Sorry for necroposting, but I had to comment to alert OP of the mistake.

    Edited once by JohnSmith777779. Last: 2nd Jul 2019
  • regk
    9th Sep 2022 Member 0 Permalink

    can you make a regular pastebin link and not a ubuntu pastebin link please?